From 07d36c9ded0e308e68a0259884faa45fda4fee3d Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 5 Jun 2017 21:26:11 +0200 Subject: [PATCH] Place trapdoors upside-down when placed at top --- mods/ITEMS/mcl_doors/init.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/mods/ITEMS/mcl_doors/init.lua b/mods/ITEMS/mcl_doors/init.lua index 1fef227178..7c5c306679 100644 --- a/mods/ITEMS/mcl_doors/init.lua +++ b/mods/ITEMS/mcl_doors/init.lua @@ -664,6 +664,32 @@ function mcl_doors:register_trapdoor(name, def) punch(pos) end), }}, + on_place = function(itemstack, placer, pointed_thing) + local p0 = pointed_thing.under + local p1 = pointed_thing.above + local param2 = 0 + + local placer_pos = placer:getpos() + if placer_pos then + param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos)) + end + + local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing) + local fpos = finepos.y % 1 + + + local origname = itemstack:get_name() + if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5) + or (fpos < -0.5 and fpos > -0.999999999) then + param2 = param2 + 20 + if param2 == 21 then + param2 = 23 + elseif param2 == 23 then + param2 = 21 + end + end + return minetest.item_place(itemstack, placer, pointed_thing, param2) + end, on_rightclick = on_rightclick, })