From 54bb6b707a40e422352c941ff587a11afaa6a153 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 10 Jan 2018 03:06:15 +0100 Subject: [PATCH] Force-call on_place callbacks when placing door --- mods/ITEMS/mcl_doors/api_doors.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mods/ITEMS/mcl_doors/api_doors.lua b/mods/ITEMS/mcl_doors/api_doors.lua index 566a98c3de..c93ea846ee 100644 --- a/mods/ITEMS/mcl_doors/api_doors.lua +++ b/mods/ITEMS/mcl_doors/api_doors.lua @@ -1,3 +1,25 @@ +-- This helper function calls on_place_node callbacks. +local function on_place_node(place_to, newnode, + placer, oldnode, itemstack, pointed_thing) + -- Run script hook + for _, callback in ipairs(minetest.registered_on_placenodes) do + -- Deep-copy pos, node and pointed_thing because callback can modify them + local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} + local newnode_copy = + {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2} + local oldnode_copy = + {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2} + local pointed_thing_copy = { + type = pointed_thing.type, + above = vector.new(pointed_thing.above), + under = vector.new(pointed_thing.under), + ref = pointed_thing.ref, + } + callback(place_to_copy, newnode_copy, placer, + oldnode_copy, itemstack, pointed_thing_copy) + end +end + -- Registers a door -- name: The name of the door -- def: a table with the folowing fields: @@ -138,6 +160,10 @@ function mcl_doors:register_door(name, def) if not minetest.settings:get_bool("creative_mode") then itemstack:take_item() end + + on_place_node(pt, minetest.get_node(pt), placer, nu, itemstack, pointed_thing) + on_place_node(pt2, minetest.get_node(pt2), placer, minetest.get_node({x=ptu.x,y=ptu.y+1,z=ptu.z}), itemstack, pointed_thing) + return itemstack end, })