summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-12-18 16:14:47 +0100
committerJeija <norrepli@gmail.com>2012-12-18 16:14:47 +0100
commite9e1006656e8dd57ec0ddc3c4bb59215c2ab199f (patch)
treeb2f2503638a2c2ec635bfb9f3f5525d744bad808
parent313b9adcd5fcfd400af7ed730a2829db3fe21015 (diff)
parent313a137675f3b01b242a3759c3e959992d2935a0 (diff)
downloadmesecons-e9e1006656e8dd57ec0ddc3c4bb59215c2ab199f.tar
mesecons-e9e1006656e8dd57ec0ddc3c4bb59215c2ab199f.tar.gz
mesecons-e9e1006656e8dd57ec0ddc3c4bb59215c2ab199f.tar.bz2
mesecons-e9e1006656e8dd57ec0ddc3c4bb59215c2ab199f.tar.xz
mesecons-e9e1006656e8dd57ec0ddc3c4bb59215c2ab199f.zip
Merge branch 'master' of https://github.com/Jeija/minetest-mod-mesecons
-rw-r--r--mesecons_pistons/init.lua56
1 files changed, 16 insertions, 40 deletions
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