summaryrefslogtreecommitdiff
path: root/mesecons_torch
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-03-29 11:35:23 +0200
committerJeija <norrepli@gmail.com>2012-03-29 11:35:23 +0200
commit8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66 (patch)
tree9d40fcbb714b33e021b37333e6d1d1b7bce845f0 /mesecons_torch
parentd6c54cf76ba04f2d63135fde0aac1289aa4b2182 (diff)
downloadmesecons-8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66.tar
mesecons-8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66.tar.gz
mesecons-8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66.tar.bz2
mesecons-8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66.tar.xz
mesecons-8e0b2a2b119e41c8ebd187fa33cd35b9abd57e66.zip
Simplify rules System
Diffstat (limited to 'mesecons_torch')
-rw-r--r--mesecons_torch/init.lua64
1 files changed, 33 insertions, 31 deletions
diff --git a/mesecons_torch/init.lua b/mesecons_torch/init.lua
index dfed5c6..ba3ac65 100644
--- a/mesecons_torch/init.lua
+++ b/mesecons_torch/init.lua
@@ -46,34 +46,33 @@ end)]]
minetest.register_abm({
nodenames = {"mesecons_torch:mesecon_torch_off","mesecons_torch:mesecon_torch_on"},
- interval = 0.1,
+ interval = 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=""
+ local rules=mesecon:get_rules("mesecontorch")
if node.param2 == 4 then
- pa.z = -2
- rules_string="mesecontorch_z+"
+ pa.z = -2
+ rules=mesecon:rotate_rules_right(rules)
elseif node.param2 == 2 then
- pa.x = -2
- rules_string="mesecontorch_x+"
+ pa.x = -2
+ rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees
elseif node.param2 == 5 then
- pa.z = 2
- rules_string="mesecontorch_z-"
+ pa.z = 2
+ rules=mesecon:rotate_rules_left(rules)
elseif node.param2 == 3 then
- pa.x = 2
- rules_string="mesecontorch_x-"
+ pa.x = 2
elseif node.param2 == 1 then
- pa.y = 2
- rules_string="mesecontorch_y-"
+ pa.y = 2
+ rules=mesecon:rotate_rules_down(rules)
elseif node.param2 == 0 then
- pa.y = -2
- rules_string="mesecontorch_y+"
+ pa.y = -2
+ rules=mesecon:rotate_rules_up(rules)
end
+
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 ~= "mesecons_torch:mesecon_torch_off" then
minetest.env:add_node(pos, {name="mesecons_torch:mesecon_torch_off",param2=node.param2})
@@ -98,26 +97,29 @@ minetest.register_on_dignode(
minetest.register_on_placenode(function(pos, node, placer)
if node.name == "mesecons_torch:mesecon_torch_on" then
- local rules_string=""
-
+ local rules=mesecon:get_rules("mesecontorch")
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)
+ rules=mesecon:rotate_rules_right(rules)
+ elseif node.param2 == 2 then
+ rules=mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules)) --180 degrees
+ elseif node.param2 == 5 then
+ rules=mesecon:rotate_rules_left(rules)
+ elseif node.param2 == 1 then
+ rules=mesecon:rotate_rules_down(rules)
+ elseif node.param2 == 0 then
+ rules=mesecon:rotate_rules_up(rules)
+ end
+ mesecon:receptor_on(pos, rules)
end
end)
+mesecon:add_rules("mesecontorch",
+{{x=1, y=0, z=0},
+{x=0, y=0, z=1},
+{x=0, y=0, z=-1},
+{x=0, y=1, z=0},
+{x=0, y=-1, z=0}})
+
mesecon:add_receptor_node("mesecons_torch:mesecon_torch_on")
mesecon:add_receptor_node_off("mesecons_torch:mesecon_torch_off")