From c50b68cf8327b5c79eb1723f45b8fb46d4f6d3c9 Mon Sep 17 00:00:00 2001 From: Anthony Zhang Date: Sun, 16 Dec 2012 15:12:24 -0500 Subject: Use a simpler way of detecting up/down piston placement (thanks Jeija). --- mesecons_pistons/init.lua | 56 ++++++++++++++--------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) (limited to 'mesecons_pistons/init.lua') diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 840cce2..11389b3 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -184,28 +184,16 @@ minetest.register_node("mesecons_pistons:piston_normal", { paramtype2 = "facedir", after_destruct = destruct, on_timer = timer, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then --can be placed only on nodes - return itemstack - end - if not placer then - return minetest.item_place(itemstack, placer, pointed_thing) + after_place_node = function(pos, placer) + if not placer then --not placed by player + return end - local dir = placer:get_look_dir() - if math.abs(dir.y) > math.sqrt(dir.x ^ 2 + dir.z ^ 2) then --vertical look direction is most significant - local fakestack - if dir.y > 0 then - fakestack = ItemStack("mesecons_pistons:piston_down_normal") - else - fakestack = ItemStack("mesecons_pistons:piston_up_normal") - end - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack - end + local pitch = placer:get_look_pitch() * (180 / math.pi) --placer pitch in degrees + if pitch > 45 then --looking upwards + minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_normal"}) + elseif pitch < 45 then --looking downwards + minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_normal"}) end - return minetest.item_place(itemstack, placer, pointed_thing) --place piston normally end, mesecons = {effector={ action_change = update @@ -219,28 +207,16 @@ minetest.register_node("mesecons_pistons:piston_sticky", { paramtype2 = "facedir", after_destruct = destruct, on_timer = timer, - on_place = function(itemstack, placer, pointed_thing) - if pointed_thing.type ~= "node" then --can be placed only on nodes - return itemstack - end - if not placer then - return minetest.item_place(itemstack, placer, pointed_thing) + after_place_node = function(pos, placer) + if not placer then --not placed by player + return end - local dir = placer:get_look_dir() - if math.abs(dir.y) > math.sqrt(dir.x ^ 2 + dir.z ^ 2) then --vertical look direction is most significant - local fakestack - if dir.y > 0 then - fakestack = ItemStack("mesecons_pistons:piston_down_sticky") - else - fakestack = ItemStack("mesecons_pistons:piston_up_sticky") - end - local ret = minetest.item_place(fakestack, placer, pointed_thing) - if ret:is_empty() then - itemstack:take_item() - return itemstack - end + local pitch = placer:get_look_pitch() * (180 / math.pi) --placer pitch in degrees + if pitch > 45 then --looking upwards + minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_sticky"}) + elseif pitch < 45 then --looking downwards + minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_sticky"}) end - return minetest.item_place(itemstack, placer, pointed_thing) --place piston normally end, mesecons = {effector={ action_change = update -- cgit v1.2.3 From 5cdf23fb00ae257cd1d77b186cd40e889530d4f0 Mon Sep 17 00:00:00 2001 From: Jeija Date: Tue, 18 Dec 2012 16:20:24 +0100 Subject: Fix bug reported here: http://bit.ly/VOF35X --- mesecons_pistons/init.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesecons_pistons/init.lua') diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 11389b3..57e944b 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -191,7 +191,7 @@ minetest.register_node("mesecons_pistons:piston_normal", { local pitch = placer:get_look_pitch() * (180 / math.pi) --placer pitch in degrees if pitch > 45 then --looking upwards minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_normal"}) - elseif pitch < 45 then --looking downwards + elseif pitch < -45 then --looking downwards minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_normal"}) end end, @@ -443,4 +443,4 @@ minetest.register_craft({ {"mesecons_materials:glue"}, {"mesecons_pistons:piston_normal"}, } -}) \ No newline at end of file +}) -- cgit v1.2.3 From f6ef7b005d4ca6d9b26aa5e60909713178184a73 Mon Sep 17 00:00:00 2001 From: Jeija Date: Tue, 18 Dec 2012 16:21:41 +0100 Subject: Same for sticky piston --- mesecons_pistons/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mesecons_pistons/init.lua') diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua index 57e944b..44b9095 100644 --- a/mesecons_pistons/init.lua +++ b/mesecons_pistons/init.lua @@ -214,7 +214,7 @@ minetest.register_node("mesecons_pistons:piston_sticky", { local pitch = placer:get_look_pitch() * (180 / math.pi) --placer pitch in degrees if pitch > 45 then --looking upwards minetest.env:add_node(pos, {name="mesecons_pistons:piston_down_sticky"}) - elseif pitch < 45 then --looking downwards + elseif pitch < -45 then --looking downwards minetest.env:add_node(pos, {name="mesecons_pistons:piston_up_sticky"}) end end, -- cgit v1.2.3