From b37bdbf55cf6d3205d5dd7a2491a8bd855cbbd76 Mon Sep 17 00:00:00 2001 From: Jeija Date: Sun, 9 Dec 2012 00:42:30 +0100 Subject: Port a lot more (basically everything apart from gates, pistons and extrawire crossing) to the new nodedef system. There are some problems with wall button and wall lever (in the way they visually connect to wires) --- mesecons_movestones/init.lua | 165 +++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 85 deletions(-) (limited to 'mesecons_movestones/init.lua') diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua index 5198a29..b17874f 100644 --- a/mesecons_movestones/init.lua +++ b/mesecons_movestones/init.lua @@ -1,33 +1,53 @@ -- MOVESTONE +-- Non-sticky: +-- Moves along mesecon lines +-- Pushes all blocks in front of it +-- +-- Sticky one +-- Moves along mesecon lines +-- Pushes all block in front of it +-- Pull all blocks in its back function mesecon:get_movestone_direction(pos) - getactivated=0 + getactivated = 0 local lpos - local getactivated=0 - local rules=mesecon:get_rules("movestone") - - lpos={x=pos.x+1, y=pos.y, z=pos.z} - for n=1, 3 do + local getactivated = 0 + local rules = { + {x=0, y=1, z=-1}, + {x=0, y=0, z=-1}, + {x=0, y=-1, z=-1}, + {x=0, y=1, z=1}, + {x=0, y=-1, z=1}, + {x=0, y=0, z=1}, + {x=1, y=0, z=0}, + {x=1, y=1, z=0}, + {x=1, y=-1, z=0}, + {x=-1, y=1, z=0}, + {x=-1, y=-1, z=0}, + {x=-1, y=0, z=0}} + + lpos = {x=pos.x+1, y=pos.y, z=pos.z} + for n = 1, 3 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=0, y=0, z=-1} end end - lpos={x=pos.x-1, y=pos.y, z=pos.z} + lpos = {x = pos.x-1, y = pos.y, z = pos.z} for n=4, 6 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=0, y=0, z=1} end end - lpos={x=pos.x, y=pos.y, z=pos.z+1} + lpos = {x = pos.x, y = pos.y, z = pos.z+1} for n=7, 9 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=-1, y=0, z=0} end end - lpos={x=pos.x, y=pos.y, z=pos.z-1} + lpos = {x = pos.x, y = pos.y, z = pos.z-1} for n=10, 12 do if mesecon:is_power_on(lpos, rules[n].x, rules[n].y, rules[n].z) then return {x=1, y=0, z=0} @@ -41,8 +61,27 @@ minetest.register_node("mesecons_movestones:movestone", { legacy_facedir_simple = true, groups = {cracky=3}, description="Movestone", + mesecons = {effector = { + action_on = function (pos, node) + local direction=mesecon:get_movestone_direction(pos) + if not direction then return end + local checknode={} + local collpos={x=pos.x, y=pos.y, z=pos.z} + repeat -- Check if it collides with a stopper + collpos = addPosRule(collpos, direction) + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + minetest.env:remove_node(pos) + mesecon:update_autoconnect(pos) + minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") + end + }} }) -mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone") minetest.register_entity("mesecons_movestones:movestone_entity", { physical = false, @@ -50,10 +89,6 @@ minetest.register_entity("mesecons_movestones:movestone_entity", { textures = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"}, collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5}, visual = "cube", - --on_activate = function(self, staticdata) - --self.object:setsprite({x=0,y=0}, 1, 0, true) - --self.object:setvelocity({x=-3, y=0, z=0}) - --end, on_punch = function(self, hitter) self.object:remove() @@ -73,7 +108,7 @@ minetest.register_entity("mesecons_movestones:movestone_entity", { self.object:setvelocity({x=direction.x*3, y=direction.y*3, z=direction.z*3}) mesecon:mvps_push(pos, direction) - end + end, }) minetest.register_craft({ @@ -85,28 +120,6 @@ minetest.register_craft({ } }) -mesecon:register_on_signal_on(function (pos, node) - if node.name=="mesecons_movestones:movestone" then - local direction=mesecon:get_movestone_direction(pos) - if not direction then return end - local checknode={} - local collpos={x=pos.x, y=pos.y, z=pos.z} - repeat -- Check if it collides with a stopper - collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - minetest.env:remove_node(pos) - nodeupdate(pos) - minetest.env:add_entity(pos, "mesecons_movestones:movestone_entity") - end -end) - - -- STICKY_MOVESTONE @@ -118,8 +131,36 @@ minetest.register_node("mesecons_movestones:sticky_movestone", { legacy_facedir_simple = true, groups = {cracky=3}, description="Sticky Movestone", + mesecons = {effector = { + action_on = function (pos, node) + local direction=mesecon:get_movestone_direction(pos) + if not direction then return end + local checknode={} + local collpos={x=pos.x, y=pos.y, z=pos.z} + repeat -- Check if it collides with a stopper + collpos = addPosRule(collpos, direction) + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + repeat -- Check if it collides with a stopper (pull direction) + collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z} + checknode=minetest.env:get_node(collpos) + if mesecon:is_mvps_stopper(checknode.name) then + return + end + until checknode.name=="air" + or checknode.name=="ignore" + or not(minetest.registered_nodes[checknode.name].liquidtype == "none") + minetest.env:remove_node(pos) + mesecon:update_autoconnect(pos) + minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") + end + }} }) -mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone") minetest.register_craft({ output = '"mesecons_movestones:sticky_movestone" 2', @@ -146,8 +187,6 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", { local direction=mesecon:get_movestone_direction(colp) if not direction then - --or (minetest.env:get_node_or_nil(pos).name ~="air" - --and minetest.env:get_node_or_nil(pos).name ~= nil) then minetest.env:add_node(pos, {name="mesecons_movestones:sticky_movestone"}) self.object:remove() return @@ -159,49 +198,5 @@ minetest.register_entity("mesecons_movestones:sticky_movestone_entity", { --STICKY mesecon:mvps_pull_all(pos, direction) - end + end, }) - -mesecon:register_on_signal_on(function (pos, node) - if node.name=="mesecons_movestones:sticky_movestone" then - local direction=mesecon:get_movestone_direction(pos) - if not direction then return end - local checknode={} - local collpos={x=pos.x, y=pos.y, z=pos.z} - repeat -- Check if it collides with a stopper - collpos={x=collpos.x+direction.x, y=collpos.y+direction.y, z=collpos.z+direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - repeat -- Check if it collides with a stopper (pull direction) - collpos={x=collpos.x-direction.x, y=collpos.y-direction.y, z=collpos.z-direction.z} - checknode=minetest.env:get_node(collpos) - if mesecon:is_mvps_stopper(checknode.name) then - return - end - until checknode.name=="air" - or checknode.name=="ignore" - or not(minetest.registered_nodes[checknode.name].liquidtype == "none") - minetest.env:remove_node(pos) - nodeupdate(pos) - minetest.env:add_entity(pos, "mesecons_movestones:sticky_movestone_entity") - end -end) - -mesecon:add_rules("movestone", { -{x=0, y=1, z=-1}, -{x=0, y=0, z=-1}, -{x=0, y=-1, z=-1}, -{x=0, y=1, z=1}, -{x=0, y=-1, z=1}, -{x=0, y=0, z=1}, -{x=1, y=0, z=0}, -{x=1, y=1, z=0}, -{x=1, y=-1, z=0}, -{x=-1, y=1, z=0}, -{x=-1, y=-1, z=0}, -{x=-1, y=0, z=0}}) -- cgit v1.2.3