summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Zhang <azhang9@gmail.com>2012-02-09 23:01:23 -0500
committerAnthony Zhang <azhang9@gmail.com>2012-02-09 23:01:23 -0500
commit1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917 (patch)
treec8d30b0bd0c16601d0fdf7cfad7db87b68ff0bd3
parente94941931d37d8be5d4fcc982ab5dcc21ad978f9 (diff)
downloadmesecons-1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917.tar
mesecons-1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917.tar.gz
mesecons-1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917.tar.bz2
mesecons-1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917.tar.xz
mesecons-1ac2bc910f11f8ae610bf32f8fc6bc73a5bf5917.zip
Refactor plugs and sockets to be smaller and faster, make inverters default to the On state.
-rw-r--r--jeija/alias.lua2
-rw-r--r--jeija/temperest.lua125
2 files changed, 51 insertions, 76 deletions
diff --git a/jeija/alias.lua b/jeija/alias.lua
index 079bb8d..8d091cc 100644
--- a/jeija/alias.lua
+++ b/jeija/alias.lua
@@ -17,5 +17,5 @@ minetest.register_alias("jeija:pressure_plate_wood", "jeija:pressure_plate_wood_
if ENABLE_TEMPEREST==1 then
minetest.register_alias("jeija:mesecon_socket", "jeija:mesecon_socket_off")
- minetest.register_alias("jeija:mesecon_inverter", "jeija:mesecon_inverter_off")
+ minetest.register_alias("jeija:mesecon_inverter", "jeija:mesecon_inverter_on")
end \ No newline at end of file
diff --git a/jeija/temperest.lua b/jeija/temperest.lua
index 0f84624..6a3214f 100644
--- a/jeija/temperest.lua
+++ b/jeija/temperest.lua
@@ -15,93 +15,68 @@ minetest.register_node("jeija:mesecon_plug", {
description = "Plug",
})
-mesecon:register_on_signal_on(function(pos, node)
- if node.name=="jeija:mesecon_plug" then
- local set_node_on = function(pos)
- local node = minetest.env:get_node(pos)
- if node.name=="jeija:mesecon_socket_off" then
- minetest.env:add_node(pos, {name="jeija:mesecon_socket_on"})
- nodeupdate(pos)
- mesecon:receptor_on(pos)
- elseif node.name=="jeija:mesecon_inverter_on" then
- minetest.env:add_node(pos, {name="jeija:mesecon_inverter_off"})
- nodeupdate(pos)
- mesecon:receptor_off(pos)
- end
- end
-
- local lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_on({x=pos.x-2, y=pos.y, z=pos.z}) end
-
- local lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_on({x=pos.x+2, y=pos.y, z=pos.z}) end
-
- local lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_on({x=pos.x, y=pos.y, z=pos.z-2}) end
-
- local lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_on({x=pos.x, y=pos.y, z=pos.z+2}) end
- end
-end)
-
-mesecon:register_on_signal_off(function(pos, node)
- if node.name=="jeija:mesecon_plug" then
- local set_node_off = function(pos)
- node = minetest.env:get_node(pos)
- if node.name=="jeija:mesecon_socket_on" then
- minetest.env:add_node(pos, {name="jeija:mesecon_socket_off"})
- nodeupdate(pos)
- mesecon:receptor_off(pos)
- elseif node.name=="jeija:mesecon_inverter_off" then
- minetest.env:add_node(pos, {name="jeija:mesecon_inverter_on"})
- nodeupdate(pos)
- mesecon:receptor_on(pos)
- end
- end
-
- lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_off({x=pos.x-2, y=pos.y, z=pos.z}) end
-
- lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_off({x=pos.x+2, y=pos.y, z=pos.z}) end
-
- lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_off({x=pos.x, y=pos.y, z=pos.z-2}) end
-
- lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_off({x=pos.x, y=pos.y, z=pos.z+2}) end
+local set_node_on = function(pos)
+ local node = minetest.env:get_node(pos)
+ if node.name=="jeija:mesecon_socket_off" then
+ minetest.env:add_node(pos, {name="jeija:mesecon_socket_on"})
+ nodeupdate(pos)
+ mesecon:receptor_on(pos)
+ elseif node.name=="jeija:mesecon_inverter_on" then
+ minetest.env:add_node(pos, {name="jeija:mesecon_inverter_off"})
+ nodeupdate(pos)
+ mesecon:receptor_off(pos)
end
-end)
+end
-minetest.register_on_dignode(function(pos, oldnode, digger)
- if oldnode.name == "jeija:mesecon_plug" then
- local set_node_deactivated = function(pos)
+local set_node_off = function(pos)
node = minetest.env:get_node(pos)
if node.name=="jeija:mesecon_socket_on" then
minetest.env:add_node(pos, {name="jeija:mesecon_socket_off"})
nodeupdate(pos)
mesecon:receptor_off(pos)
- elseif node.name=="jeija:mesecon_inverter_on" then
- minetest.env:add_node(pos, {name="jeija:mesecon_inverter_off"})
+ elseif node.name=="jeija:mesecon_inverter_off" then
+ minetest.env:add_node(pos, {name="jeija:mesecon_inverter_on"})
nodeupdate(pos)
- mesecon:receptor_off(pos)
+ mesecon:receptor_on(pos)
end
+end
+
+local plug_on = function(pos, node)
+ if node.name=="jeija:mesecon_plug" then
+ local lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_on({x=pos.x-2, y=pos.y, z=pos.z}) end
+
+ local lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_on({x=pos.x+2, y=pos.y, z=pos.z}) end
+
+ local lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_on({x=pos.x, y=pos.y, z=pos.z-2}) end
+
+ local lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_on({x=pos.x, y=pos.y, z=pos.z+2}) end
end
-
- lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_deactivated({x=pos.x-2, y=pos.y, z=pos.z}) end
-
- lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_deactivated({x=pos.x+2, y=pos.y, z=pos.z}) end
-
- lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_deactivated({x=pos.x, y=pos.y, z=pos.z-2}) end
-
- lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
- if lnode.name=="air" then set_node_deactivated({x=pos.x, y=pos.y, z=pos.z+2}) end
+end
+
+local plug_off = function(pos, node)
+ if node.name=="jeija:mesecon_plug" then
+ lnode = minetest.env:get_node({x=pos.x-1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_off({x=pos.x-2, y=pos.y, z=pos.z}) end
+
+ lnode = minetest.env:get_node({x=pos.x+1, y=pos.y, z=pos.z}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_off({x=pos.x+2, y=pos.y, z=pos.z}) end
+
+ lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z-1}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_off({x=pos.x, y=pos.y, z=pos.z-2}) end
+
+ lnode = minetest.env:get_node({x=pos.x, y=pos.y, z=pos.z+1}) --a node between this node and the one two nodes away
+ if lnode.name=="air" then set_node_off({x=pos.x, y=pos.y, z=pos.z+2}) end
end
-end)
+end
+
+mesecon:register_on_signal_on(plug_on)
+mesecon:register_on_signal_off(plug_off)
+minetest.register_on_dignode(plug_off)
minetest.register_craft({
output = 'node "jeija:mesecon_plug" 2',