From 73a04914a0dfba36d1f4759e2f2442afe6179fdd Mon Sep 17 00:00:00 2001 From: sfan5 Date: Sat, 28 Jan 2012 19:01:50 +0100 Subject: [PATCH] Torches are working --- jeija/init.lua | 54 +++++++++++++-------------------- jeija/torches.lua | 77 ++++++++++++++++++++++++----------------------- 2 files changed, 60 insertions(+), 71 deletions(-) diff --git a/jeija/init.lua b/jeija/init.lua index f766e1d..afc13b6 100644 --- a/jeija/init.lua +++ b/jeija/init.lua @@ -455,49 +455,37 @@ function mesecon:get_rules(name) table.insert(rules, {x=0, y=-1, z=0}) table.insert(rules, {x=0, y=1, z=0}) end - if name=="mesecontorch_x+" then - table.insert(rules, {x=1, y=1, z=0}) - table.insert(rules, {x=1, y=0, z=0}) - table.insert(rules, {x=1, y=-1, z=0}) - end if name=="mesecontorch_x-" then - table.insert(rules, {x=-1, y=1, z=0}) - table.insert(rules, {x=-1, y=0, z=0}) - table.insert(rules, {x=-1, y=-1, z=0}) - end - if name=="mesecontorch_z+" then - table.insert(rules, {x=0, y=1, z=1}) + table.insert(rules, {x=1, y=0, z=0}) table.insert(rules, {x=0, y=0, z=1}) - table.insert(rules, {x=0, y=-1, z=1}) + table.insert(rules, {x=0, y=0, z=-1}) + end + if name=="mesecontorch_x+" then + table.insert(rules, {x=-1, y=0, z=0}) + table.insert(rules, {x=0, y=0, z=1}) + table.insert(rules, {x=0, y=0, z=-1}) end if name=="mesecontorch_z-" then - table.insert(rules, {x=0, y=1, z=-1}) - table.insert(rules, {x=0, y=0, z=-1}) - table.insert(rules, {x=0, y=-1, z=-1}) + table.insert(rules, {x=0, y=0, z=1}) + table.insert(rules, {x=1, y=0, z=0}) + table.insert(rules, {x=-1, y=0, z=0}) end - if name=="mesecontorch_y+" then - table.insert(rules, {x=-1, y=1, z=0}) - table.insert(rules, {x=-1, y=1, z=1}) - table.insert(rules, {x=-1, y=1, z=-1}) - + if name=="mesecontorch_z+" then + table.insert(rules, {x=0, y=0, z=-1}) + table.insert(rules, {x=1, y=0, z=0}) + table.insert(rules, {x=-1, y=0, z=0}) + end + if name=="mesecontorch_y-" then + table.insert(rules, {x=0, y=1, z=0}) table.insert(rules, {x=1, y=1, z=0}) - table.insert(rules, {x=1, y=1, z=1}) - table.insert(rules, {x=1, y=1, z=-1}) - - table.insert(rules, {x=0, y=1, z=0}) + table.insert(rules, {x=-1, y=1, z=0}) table.insert(rules, {x=0, y=1, z=1}) table.insert(rules, {x=0, y=1, z=-1}) end - if name=="mesecontorch_y-" then - table.insert(rules, {x=-1, y=-1, z=0}) - table.insert(rules, {x=-1, y=-1, z=1}) - table.insert(rules, {x=-1, y=-1, z=-1}) - + if name=="mesecontorch_y+" then + table.insert(rules, {x=0, y=-1, z=0}) table.insert(rules, {x=1, y=-1, z=0}) - table.insert(rules, {x=1, y=-1, z=1}) - table.insert(rules, {x=1, y=-1, z=-1}) - - table.insert(rules, {x=0, y=-1, z=0}) + table.insert(rules, {x=-1, y=-1, z=0}) table.insert(rules, {x=0, y=-1, z=1}) table.insert(rules, {x=0, y=-1, z=-1}) end diff --git a/jeija/torches.lua b/jeija/torches.lua index 32c0cf2..fca051c 100644 --- a/jeija/torches.lua +++ b/jeija/torches.lua @@ -43,42 +43,43 @@ end)]] minetest.register_abm({ nodenames = {"jeija:mesecon_torch_off","jeija:mesecon_torch_on"}, - interval = 0.2, + interval = 0.1, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) local pa = {x=0, y=0, z=0} - pa.y = 1 - local rules_string="" + --pa.y = 1 + local rules_string="" - if node.param2 == 5 then - pa.z = -1 - rules_string="mesecontorch_z+" - elseif node.param2 == 3 then - pa.x = -1 - rules_string="mesecontorch_x+" - elseif node.param2 == 4 then - pa.z = 1 - rules_string="mesecontorch_z-" - elseif node.param2 == 2 then - pa.x = 1 - rules_string="mesecontorch_x-" - elseif node.param2 == 0 then - pa.y = 1 - rules_string="mesecontorch_y-" - elseif node.param2 == 1 then - pa.y = -1 - rules_string="mesecontorch_y+" + if node.param2 == 4 then + pa.z = -2 + rules_string="mesecontorch_z+" + elseif node.param2 == 2 then + pa.x = -2 + rules_string="mesecontorch_x+" + elseif node.param2 == 5 then + pa.z = 2 + rules_string="mesecontorch_z-" + elseif node.param2 == 3 then + pa.x = 2 + rules_string="mesecontorch_x-" + elseif node.param2 == 1 then + pa.y = 2 + rules_string="mesecontorch_y-" + elseif node.param2 == 0 then + pa.y = -2 + rules_string="mesecontorch_y+" end - - if mesecon:is_power_on({x=pos.x, y=pos.y, z=pos.z}, pa.x, pa.y, pa.z)==1 then + local postc = {x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z} + --print("Checking at "..dump(postc).." with "..rules_string) + if mesecon:is_power_on(postc,0,0,0)==1 then if node.name ~= "jeija:mesecon_torch_off" then minetest.env:add_node(pos, {name="jeija:mesecon_torch_off",param2=node.param2}) - mesecon:receptor_off({x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z}, rules_string) + mesecon:receptor_off(pos, rules_string) end else if node.name ~= "jeija:mesecon_torch_on" then minetest.env:add_node(pos, {name="jeija:mesecon_torch_on",param2=node.param2}) - mesecon:receptor_on({x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z}, rules_string) + mesecon:receptor_on(pos, rules_string) end end end @@ -96,19 +97,19 @@ minetest.register_on_placenode(function(pos, node, placer) if node.name == "jeija:mesecon_torch_on" then local rules_string="" - if node.param2 == 5 then - rules_string="mesecontorch_z+" - elseif node.param2 == 3 then - rules_string="mesecontorch_x+" - elseif node.param2 == 4 then - rules_string="mesecontorch_z-" - elseif node.param2 == 2 then - rules_string="mesecontorch_x-" - elseif node.param2 == 0 then - rules_string="mesecontorch_y-" - elseif node.param2 == 1 then - rules_string="mesecontorch_y+" - end + if node.param2 == 4 then + rules_string="mesecontorch_z+" + elseif node.param2 == 2 then + rules_string="mesecontorch_x+" + elseif node.param2 == 5 then + rules_string="mesecontorch_z-" + elseif node.param2 == 3 then + rules_string="mesecontorch_x-" + elseif node.param2 == 1 then + rules_string="mesecontorch_y-" + elseif node.param2 == 0 then + rules_string="mesecontorch_y+" + end mesecon:receptor_on(pos, rules_string) end