From 0a2fd6eabeedc7552aeb800b73c8d046c7e484b0 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sat, 13 Feb 2016 20:00:37 -0800 Subject: [PATCH 1/2] Allow building doors on buildable_to nodes. This code never allowed placing a door on e.g. a grass plant. The code to handle this isn't that complex. With this code, doors can be placed on flowers and on normal node surfaces without issues. --- mods/doors/init.lua | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index e96a7f53..28ec91cb 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -183,8 +183,15 @@ function doors.register(name, def) inventory_image = def.inventory_image, on_place = function(itemstack, placer, pointed_thing) - local pos = pointed_thing.above - local node = minetest.get_node(pos) + local pos = nil + + local node = minetest.get_node(pointed_thing.under) + if minetest.registered_nodes[node.name].buildable_to then + pos = pointed_thing.under + else + pos = pointed_thing.above + node = minetest.get_node(pos) + end if not minetest.registered_nodes[node.name].buildable_to then return itemstack From 5a8d16278c21201b0cfdc28295ab501909eb6185 Mon Sep 17 00:00:00 2001 From: Auke Kok Date: Sat, 13 Feb 2016 20:27:03 -0800 Subject: [PATCH 2/2] Open doors when right-clicking a door with a door. And similarly, if we wield a door and right click any node that has an on_rightclick() handler, call the handler instead. Just to be on the safe side, assure that none of this code runs when right-clicking an entity or player, which would likely crash the server. Fold in PR #831 as well - prevent server crash on door place on unknown blocks, by @tenplus1. --- mods/doors/init.lua | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/mods/doors/init.lua b/mods/doors/init.lua index 28ec91cb..caba680a 100644 --- a/mods/doors/init.lua +++ b/mods/doors/init.lua @@ -185,16 +185,26 @@ function doors.register(name, def) on_place = function(itemstack, placer, pointed_thing) local pos = nil + if not pointed_thing.type == "node" then + return itemstack + end + local node = minetest.get_node(pointed_thing.under) - if minetest.registered_nodes[node.name].buildable_to then + local def = minetest.registered_nodes[node.name] + if def and def.on_rightclick then + return def.on_rightclick(pointed_thing.under, + node, placer, itemstack) + end + + if def and def.buildable_to then pos = pointed_thing.under else pos = pointed_thing.above node = minetest.get_node(pos) - end - - if not minetest.registered_nodes[node.name].buildable_to then - return itemstack + def = minetest.registered_nodes[node.name] + if not def or not def.buildable_to then + return itemstack + end end local above = { x = pos.x, y = pos.y + 1, z = pos.z }