summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-08-17 16:28:59 +0200
committerJeija <norrepli@gmail.com>2012-08-17 16:28:59 +0200
commit3c2d0ba325d4bcf6d56433cc33539eaea7dae86a (patch)
tree95f89aba068c4c695b5743fc69df89d23e86c260
parent863ef26b633470fc25c0dc365387fefc620e876c (diff)
downloadmesecons-3c2d0ba325d4bcf6d56433cc33539eaea7dae86a.tar
mesecons-3c2d0ba325d4bcf6d56433cc33539eaea7dae86a.tar.gz
mesecons-3c2d0ba325d4bcf6d56433cc33539eaea7dae86a.tar.bz2
mesecons-3c2d0ba325d4bcf6d56433cc33539eaea7dae86a.tar.xz
mesecons-3c2d0ba325d4bcf6d56433cc33539eaea7dae86a.zip
Re-enable button + Wall lever, bugfix that adds a 'receiver' node (not yet designed)
-rw-r--r--mesecons_button/depends.txt1
-rw-r--r--mesecons_button/init.lua4
-rw-r--r--mesecons_receiver/depends.txt1
-rw-r--r--mesecons_receiver/init.lua117
-rw-r--r--mesecons_walllever/depends.txt2
-rw-r--r--mesecons_walllever/init.lua7
6 files changed, 127 insertions, 5 deletions
diff --git a/mesecons_button/depends.txt b/mesecons_button/depends.txt
index acaa924..19c798c 100644
--- a/mesecons_button/depends.txt
+++ b/mesecons_button/depends.txt
@@ -1 +1,2 @@
mesecons
+mesecons_receiver
diff --git a/mesecons_button/init.lua b/mesecons_button/init.lua
index 67011e4..017f26c 100644
--- a/mesecons_button/init.lua
+++ b/mesecons_button/init.lua
@@ -24,7 +24,7 @@ minetest.register_node("mesecons_button:button_off", {
{ -4/16, -2/16, 4/16, 4/16, 2/16, 6/16 } -- the button itself
}
},
- groups = {dig_immediate=2, mesecon = 3},
+ groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1},
description = "Button",
})
minetest.register_node("mesecons_button:button_on", {
@@ -53,7 +53,7 @@ minetest.register_node("mesecons_button:button_on", {
{ -4/16, -2/16, 11/32, 4/16, 2/16, 6/16 }
}
},
- groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3},
+ groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1},
drop = 'mesecons_button:button_off',
description = "Button",
})
diff --git a/mesecons_receiver/depends.txt b/mesecons_receiver/depends.txt
new file mode 100644
index 0000000..acaa924
--- /dev/null
+++ b/mesecons_receiver/depends.txt
@@ -0,0 +1 @@
+mesecons
diff --git a/mesecons_receiver/init.lua b/mesecons_receiver/init.lua
new file mode 100644
index 0000000..c203102
--- /dev/null
+++ b/mesecons_receiver/init.lua
@@ -0,0 +1,117 @@
+minetest.register_node("mesecons_receiver:receiver_on", {
+ tiles = {"default_wood.png"},
+ groups = {dig_immediate = 3, mesecon = 3, not_in_creative_inventory = 1},
+ drop = "mesecons:wire_00000000_off",
+})
+
+minetest.register_node("mesecons_receiver:receiver_off", {
+ description = "You hacker you",
+ tiles = {"default_stone.png"},
+ groups = {dig_immediate = 3, mesecon = 3},
+ drop = "mesecons:wire_00000000_off",
+})
+
+mesecon:add_rules("receiver_pos", {{x = 2, y = 0, z = 0}})
+
+mesecon:add_rules("receiver_pos_all", {
+{x = 2, y = 0, z = 0},
+{x =-2, y = 0, z = 0},
+{x = 0, y = 0, z = 2},
+{x = 0, y = 0, z =-2}})
+
+mesecon:add_rules("mesecon_receiver", {
+{x = 1, y = 0, z = 0},
+{x = -2, y = 0, z = 0},})
+
+mesecon:add_rules("mesecon_receiver_all", {
+{x = 1, y = 0, z = 0},
+{x =-2, y = 0, z = 0},
+{x =-1, y = 0, z = 0},
+{x = 2, y = 0, z = 0},
+{x = 0, y = 0, z = 1},
+{x = 0, y = 0, z =-2},
+{x = 1, y = 0, z =-1},
+{x =-2, y = 0, z = 2},})
+
+function receiver_get_rules(param2)
+ local rules = mesecon:get_rules("mesecon_receiver")
+ if param2 == 2 then
+ rules = mesecon:rotate_rules_left(rules)
+ elseif param2 == 3 then
+ rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
+ elseif param2 == 0 then
+ rules = mesecon:rotate_rules_right(rules)
+ end
+ return rules
+end
+
+mesecon:register_conductor("mesecons_receiver:receiver_on", "mesecons_receiver:receiver_off", mesecon:get_rules("mesecon_receiver_all"), receiver_get_rules)
+
+function mesecon:receiver_get_pos_from_rcpt(pos)
+ node = minetest.env:get_node(pos)
+ local rules = mesecon:get_rules("receiver_pos")
+ if node.param2 == 2 then
+ rules = mesecon:rotate_rules_left(rules)
+ elseif node.param2 == 3 then
+ rules = mesecon:rotate_rules_right(mesecon:rotate_rules_right(rules))
+ elseif node.param2 == 0 then
+ rules = mesecon:rotate_rules_right(rules)
+ end
+ np = {
+ x = pos.x + rules[1].x,
+ y = pos.y + rules[1].y,
+ z = pos.z + rules[1].z}
+ return np
+end
+
+function mesecon:receiver_place(rcpt_pos)
+ local node = minetest.env:get_node(rcpt_pos)
+ pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos, node.param2)
+ nn = minetest.env:get_node(pos)
+
+ if string.find(nn.name, "mesecons:wire_") ~= nil then
+ minetest.env:dig_node(pos)
+ minetest.env:add_node(pos, {name = "mesecons_receiver:receiver_off", param2 = node.param2})
+ mesecon:update_autoconnect(pos)
+ end
+end
+
+function mesecon:receiver_remove(rcpt_pos)
+ pos = mesecon:receiver_get_pos_from_rcpt(rcpt_pos)
+ node = minetest.env:get_node(pos)
+
+ if string.find(node.name, "mesecons_receiver:receiver_") ~=nil then
+ minetest.env:dig_node(pos)
+ minetest.env:place_node(pos, {name = "mesecons:wire_00000000_off"})
+ mesecon:update_autoconnect(pos)
+ end
+end
+
+minetest.register_on_placenode(function (pos, node)
+ if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
+ mesecon:receiver_place(pos)
+ end
+end)
+
+minetest.register_on_dignode(function(pos, node)
+ if minetest.get_item_group(node.name, "mesecon_needs_receiver") == 1 then
+ mesecon:receiver_remove(pos)
+ end
+end)
+
+minetest.register_on_placenode(function (pos, node)
+ if string.find(node.name, "mesecons:wire_") ~=nil then
+ rules = mesecon:get_rules("receiver_pos_all")
+ local i = 1
+ while rules[i] ~= nil do
+ np = {
+ x = pos.x + rules[i].x,
+ y = pos.y + rules[i].y,
+ z = pos.z + rules[i].z}
+ if minetest.get_item_group(minetest.env:get_node(np).name, "mesecon_needs_receiver") == 1 then
+ mesecon:receiver_place(np)
+ end
+ i = i + 1
+ end
+ end
+end)
diff --git a/mesecons_walllever/depends.txt b/mesecons_walllever/depends.txt
index 52a18df..19c798c 100644
--- a/mesecons_walllever/depends.txt
+++ b/mesecons_walllever/depends.txt
@@ -1,2 +1,2 @@
mesecons
-mesecons_button
+mesecons_receiver
diff --git a/mesecons_walllever/init.lua b/mesecons_walllever/init.lua
index b41e87a..eadd6a4 100644
--- a/mesecons_walllever/init.lua
+++ b/mesecons_walllever/init.lua
@@ -26,8 +26,11 @@ minetest.register_node("mesecons_walllever:wall_lever_off", {
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge"
{ -1/16, -8/16, 4/16, 1/16, 0, 6/16 }} -- the lever itself.
},
- groups = {dig_immediate=2, mesecon = 3},
+ groups = {dig_immediate=2, mesecon = 3, mesecon_needs_receiver = 1},
description="Lever",
+ after_place_node = function(pos, placer)
+
+ end,
})
minetest.register_node("mesecons_walllever:wall_lever_on", {
drawtype = "nodebox",
@@ -56,7 +59,7 @@ minetest.register_node("mesecons_walllever:wall_lever_on", {
{ -2/16, -1/16, 3/16, 2/16, 1/16, 4/16 }, -- the lever "hinge"
{ -1/16, 0, 4/16, 1/16, 8/16, 6/16 }} -- the lever itself.
},
- groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 3},
+ groups = {dig_immediate=2,not_in_creative_inventory=1, mesecon = 3, mesecon_needs_receiver = 1},
drop = '"mesecons_walllever:wall_lever_off" 1',
description="Lever",
})