summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeija <norrepli@gmail.com>2012-08-13 20:17:45 +0200
committerJeija <norrepli@gmail.com>2012-08-13 20:17:45 +0200
commit00ce2540c22340ed02135d74c6d70a35757e8deb (patch)
tree24f5ee80cf20e3eb2a9a303a52ead63ff685fecd
parent24c50571f788a2d946ee905dd295124affc88d8b (diff)
downloadmesecons-00ce2540c22340ed02135d74c6d70a35757e8deb.tar
mesecons-00ce2540c22340ed02135d74c6d70a35757e8deb.tar.gz
mesecons-00ce2540c22340ed02135d74c6d70a35757e8deb.tar.bz2
mesecons-00ce2540c22340ed02135d74c6d70a35757e8deb.tar.xz
mesecons-00ce2540c22340ed02135d74c6d70a35757e8deb.zip
New effector system, effectors have to be registered with mesecon:register_effector(onstate, offstate, rules, function get_rules) rules and function get_rules are optional. You don't have to specify both onstate and offstate (required for e.g. removestone)
-rw-r--r--mesecons/init.lua9
-rw-r--r--mesecons/internal.lua194
-rw-r--r--mesecons/services.lua4
-rw-r--r--mesecons_battery/init.lua6
-rw-r--r--mesecons_delayer/init.lua78
-rw-r--r--mesecons_door/init.lua2
-rw-r--r--mesecons_lamp/init.lua2
-rw-r--r--mesecons_lightstone/init.lua3
-rw-r--r--mesecons_microcontroller/init.lua16
-rw-r--r--mesecons_movestones/init.lua6
-rw-r--r--mesecons_noteblock/init.lua3
-rw-r--r--mesecons_pistons/init.lua6
-rw-r--r--mesecons_random/init.lua4
-rw-r--r--mesecons_torch/init.lua36
14 files changed, 206 insertions, 163 deletions
diff --git a/mesecons/init.lua b/mesecons/init.lua
index 34cb624..7e7456f 100644
--- a/mesecons/init.lua
+++ b/mesecons/init.lua
@@ -154,7 +154,7 @@ function mesecon:receptor_on(pos, rules)
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- mesecon:turnon(np)
+ mesecon:turnon(np, pos)
i=i+1
end
end
@@ -164,7 +164,6 @@ function mesecon:receptor_off(pos, rules)
rules = mesecon:get_rules("default")
end
- local checked = {}
local connected = false
local i = 1
while rules[i]~=nil do
@@ -172,9 +171,9 @@ function mesecon:receptor_off(pos, rules)
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- connected, checked = mesecon:connected_to_pw_src(np, checked)
- if not connected then
- mesecon:turnoff(np)
+ connected = mesecon:connected_to_pw_src(np)
+ if connected == false then
+ mesecon:turnoff(np, pos)
end
i=i+1
end
diff --git a/mesecons/internal.lua b/mesecons/internal.lua
index cdd747f..bba29b8 100644
--- a/mesecons/internal.lua
+++ b/mesecons/internal.lua
@@ -1,5 +1,6 @@
--- INTERNAL API
+-- INTERNAL
+--Receptors
function mesecon:is_receptor_node(nodename)
local i = 1
while mesecon.receptors[i] ~= nil do
@@ -53,6 +54,33 @@ function mesecon:receptor_get_rules(node)
return nil
end
+-- Effectors
+function mesecon:is_effector_on(nodename)
+ local i = 1
+ while mesecon.effectors[i] ~= nil do
+ if mesecon.effectors[i].onstate == nodename then
+ return true
+ end
+ i = i + 1
+ end
+ return false
+end
+
+function mesecon:is_effector_off(nodename)
+ local i = 1
+ while mesecon.effectors[i] ~= nil do
+ if mesecon.effectors[i].offstate == nodename then
+ return true
+ end
+ i = i + 1
+ end
+ return false
+end
+
+function mesecon:is_effector(nodename)
+ return mesecon:is_effector_on(nodename) or mesecon:is_effector_off(nodename)
+end
+
function mesecon:effector_get_input_rules(node)
local i = 1
while(mesecon.effectors[i] ~= nil) do
@@ -60,7 +88,7 @@ function mesecon:effector_get_input_rules(node)
or mesecon.effectors[i].offstate == node.name then
if mesecon.effectors[i].get_input_rules ~= nil then
return mesecon.effectors[i].get_input_rules(node.param2)
- elseif mesecon.receptors[i].input_rules ~=nil then
+ elseif mesecon.effectors[i].input_rules ~=nil then
return mesecon.effectors[i].input_rules
else
return mesecon:get_rules("default")
@@ -89,16 +117,16 @@ function mesecon:receptor_outputs (cpos, rpos) --cpos = conductor pos, rpos = re
return false
end
-function mesecon:effector_inputs (cpos, rpos) --cpos = conductor pos, rpos = receptor pos
- local rnode = minetest.env:get_node (rpos)
- local rules = mesecon:effector_get_input_rules (rnode)
+function mesecon:effector_inputs (srcpos, destpos)
+ local destnode = minetest.env:get_node (destpos)
+ local rules = mesecon:effector_get_input_rules (destnode)
if rules == nil then return false end
local i = 1
while rules[i] ~= nil do
- if rpos.x + rules[i].x == cpos.x
- and rpos.y + rules[i].y == cpos.y
- and rpos.z + rules[i].z == cpos.z then
+ if destpos.x + rules[i].x == srcpos.x
+ and destpos.y + rules[i].y == srcpos.y
+ and destpos.z + rules[i].z == srcpos.z then
return true
end
i = i + 1
@@ -214,59 +242,6 @@ function mesecon:is_conductor_off(name)
return false
end
---Rules rotation Functions:
-function mesecon:rotate_rules_right(rules)
- local i=1
- local nr={};
- while rules[i]~=nil do
- nr[i]={}
- nr[i].z=rules[i].x
- nr[i].x=-rules[i].z
- nr[i].y=rules[i].y
- i=i+1
- end
- return nr
-end
-
-function mesecon:rotate_rules_left(rules)
- local i=1
- local nr={};
- while rules[i]~=nil do
- nr[i]={}
- nr[i].z=-rules[i].x
- nr[i].x=rules[i].z
- nr[i].y=rules[i].y
- i=i+1
- end
- return nr
-end
-
-function mesecon:rotate_rules_down(rules)
- local i=1
- local nr={};
- while rules[i]~=nil do
- nr[i]={}
- nr[i].y=rules[i].x
- nr[i].x=-rules[i].y
- nr[i].z=rules[i].z
- i=i+1
- end
- return nr
-end
-
-function mesecon:rotate_rules_up(rules)
- local i=1
- local nr={};
- while rules[i]~=nil do
- nr[i]={}
- nr[i].y=-rules[i].x
- nr[i].x=rules[i].y
- nr[i].z=rules[i].z
- i=i+1
- end
- return nr
-end
-
function mesecon:is_power_on(pos)
local node = minetest.env:get_node(pos)
if mesecon:is_conductor_on(node.name) or mesecon:is_receptor_node(node.name) then
@@ -278,60 +253,62 @@ end
function mesecon:is_power_off(pos)
local node = minetest.env:get_node(pos)
if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_node_off(node.name) then
- return 1
+ return true
end
- return 0
+ return false
end
-function mesecon:turnon(pos)
+function mesecon:turnon(pos, sourcepos)
local node = minetest.env:get_node(pos)
+ local rules = mesecon:get_rules("default") --TODO: Use rules of conductor
+ local i = 1
if mesecon:is_conductor_off(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_on(node.name)})
- nodeupdate(pos)
- rules = mesecon:get_rules("default") --TODO: Use rules of conductor
- local i=1
while rules[i]~=nil do
local np = {}
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- mesecon:turnon(np)
+
+ mesecon:turnon(np, pos)
i=i+1
end
end
- mesecon:changesignal(pos)
- if minetest.get_item_group(node.name, "mesecon_effector_off") == 1 then
- mesecon:activate(pos)
+ if mesecon:is_effector(node.name) then
+ if mesecon:effector_inputs(sourcepos, pos) then
+ mesecon:changesignal(pos)
+ if mesecon:is_effector_off(node.name) then mesecon:activate(pos) end
+ end
end
end
-function mesecon:turnoff(pos)
+function mesecon:turnoff(pos, sourcepos)
local node = minetest.env:get_node(pos)
+ rules = mesecon:get_rules("default") --TODO: Use rules of conductor
+ local i = 1
if mesecon:is_conductor_on(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name)})
- nodeupdate(pos)
- rules = mesecon:get_rules("default") --TODO: Use ruels of conductor
- local i = 1
while rules[i]~=nil do
local np = {}
np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z
- mesecon:turnoff(np)
- i=i+1
+
+ mesecon:turnoff(np, pos)
+ i = i + 1
end
end
- mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors
- if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 and
- not mesecon:is_powered(pos) then --Check if the signal comes from another source
- --Send Signals to effectors:
- mesecon:deactivate(pos)
+ if mesecon:is_effector(node.name) then
+ if mesecon:effector_inputs(sourcepos, pos) then
+ mesecon:changesignal(pos)
+ if mesecon:is_effector_on(node.name) then mesecon:deactivate(pos) end
+ end
end
end
@@ -456,3 +433,56 @@ end
function compare_pos(pos1, pos2)
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
end
+
+--Rules rotation Functions:
+function mesecon:rotate_rules_right(rules)
+ local i=1
+ local nr={};
+ while rules[i]~=nil do
+ nr[i]={}
+ nr[i].z=rules[i].x
+ nr[i].x=-rules[i].z
+ nr[i].y=rules[i].y
+ i=i+1
+ end
+ return nr
+end
+
+function mesecon:rotate_rules_left(rules)
+ local i=1
+ local nr={};
+ while rules[i]~=nil do
+ nr[i]={}
+ nr[i].z=-rules[i].x
+ nr[i].x=rules[i].z
+ nr[i].y=rules[i].y
+ i=i+1
+ end
+ return nr
+end
+
+function mesecon:rotate_rules_down(rules)
+ local i=1
+ local nr={};
+ while rules[i]~=nil do
+ nr[i]={}
+ nr[i].y=rules[i].x
+ nr[i].x=-rules[i].y
+ nr[i].z=rules[i].z
+ i=i+1
+ end
+ return nr
+end
+
+function mesecon:rotate_rules_up(rules)
+ local i=1
+ local nr={};
+ while rules[i]~=nil do
+ nr[i]={}
+ nr[i].y=-rules[i].x
+ nr[i].x=rules[i].y
+ nr[i].z=rules[i].z
+ i=i+1
+ end
+ return nr
+end
diff --git a/mesecons/services.lua b/mesecons/services.lua
index 4cf615e..c5b9308 100644
--- a/mesecons/services.lua
+++ b/mesecons/services.lua
@@ -1,7 +1,7 @@
minetest.register_on_dignode(
function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then
- local i = 1
+ print("receptor_off")
mesecon:receptor_off(pos)
end
@@ -19,7 +19,7 @@ minetest.register_on_placenode(
if mesecon:is_powered(pos) then
if mesecon:is_conductor_off(node.name) then
- mesecon:turnon(pos)
+ mesecon:turnon(pos) -- in this case we don't need a source as the destination certainly is a conductor and not a receptor
else
mesecon:changesignal(pos)
mesecon:activate(pos)
diff --git a/mesecons_battery/init.lua b/mesecons_battery/init.lua
index b5e50a9..1218778 100644
--- a/mesecons_battery/init.lua
+++ b/mesecons_battery/init.lua
@@ -19,10 +19,9 @@ for i = 1, 5 do
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
- groups = {dig_immediate=2, mesecon = 2, mesecon_effector_on = 1},
+ groups = {dig_immediate=2, mesecon = 2},
description="Battery",
})
- mesecon:add_receptor_node_off("mesecons_battery:battery_charging_"..i)
end
for i = 1, 5 do
@@ -46,10 +45,11 @@ for i = 1, 5 do
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
- groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2, mesecon_effector_off = 1},
+ groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 2},
description="Battery",
})
mesecon:add_receptor_node("mesecons_battery:battery_discharging_"..i)
+ mesecon:register_effector("mesecons_battery:battery_discharging_"..i, "mesecons_battery:battery_charging_"..i)
end
minetest.register_on_placenode(function (pos, newnode, placer)
diff --git a/mesecons_delayer/init.lua b/mesecons_delayer/init.lua
index 469704f..c732a17 100644
--- a/mesecons_delayer/init.lua
+++ b/mesecons_delayer/init.lua
@@ -115,55 +115,45 @@ end)
mesecon.delayer_update = function(pos, node)
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
- local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
- np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
-
- if mesecon:is_power_on(np) then
- local time = 0
- if node.name=="mesecons_delayer:delayer_off_1" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
- time=0.1
- end
- if node.name=="mesecons_delayer:delayer_off_2" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
- time=0.3
- end
- if node.name=="mesecons_delayer:delayer_off_3" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
- time=0.5
- end
- if node.name=="mesecons_delayer:delayer_off_4" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
- time=1
- end
- minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
+ local time = 0
+ if node.name=="mesecons_delayer:delayer_off_1" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
+ time=0.1
end
+ if node.name=="mesecons_delayer:delayer_off_2" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
+ time=0.3
+ end
+ if node.name=="mesecons_delayer:delayer_off_3" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
+ time=0.5
+ end
+ if node.name=="mesecons_delayer:delayer_off_4" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
+ time=1
+ end
+ minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
end
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
- local input_rules = mesecon.delayer_get_input_rules(node.param2)[1]
- np = {x = pos.x + input_rules.x, y = pos.y + input_rules.y, z = pos.z + input_rules.z}
-
- if not mesecon:is_power_on(np) then
- local time = 0
- if node.name=="mesecons_delayer:delayer_on_1" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
- time=0.1
- end
- if node.name=="mesecons_delayer:delayer_on_2" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
- time=0.3
- end
- if node.name=="mesecons_delayer:delayer_on_3" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
- time=0.5
- end
- if node.name=="mesecons_delayer:delayer_on_4" then
- minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
- time=1
- end
- minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
+ local time = 0
+ if node.name=="mesecons_delayer:delayer_on_1" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
+ time=0.1
+ end
+ if node.name=="mesecons_delayer:delayer_on_2" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
+ time=0.3
+ end
+ if node.name=="mesecons_delayer:delayer_on_3" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
+ time=0.5
+ end
+ if node.name=="mesecons_delayer:delayer_on_4" then
+ minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
+ time=1
end
+ minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
end
end
diff --git a/mesecons_door/init.lua b/mesecons_door/init.lua
index ae7ec48..a53852b 100644
--- a/mesecons_door/init.lua
+++ b/mesecons_door/init.lua
@@ -100,6 +100,7 @@ for i = 1, 4 do
},
on_punch = mesecons_door_transform
})
+ mesecon:register_effector("mesecons_door:door_"..i.."_"..j, "mesecons_door:door_"..i.."_"..j)
end
end
@@ -125,6 +126,7 @@ minetest.register_node("mesecons_door:door", {
minetest.env:add_node(node_pos, {name = "mesecons_door:door_"..best_number.."_1"})
end
})
+mesecon:register_effector("mesecons_door:door")
minetest.register_on_placenode(function(pos, newnode, placer)
local b_pos = {x = pos.x, y = pos.y - 1, z = pos.z}
diff --git a/mesecons_lamp/init.lua b/mesecons_lamp/init.lua
index 4d7e92b..8c1b613 100644
--- a/mesecons_lamp/init.lua
+++ b/mesecons_lamp/init.lua
@@ -71,3 +71,5 @@ mesecon:register_on_signal_off(function(pos, node)
nodeupdate(pos)
end
end)
+
+mesecon:register_effector("mesecons_lamp:lamp_on", "mesecons_lamp:lamp_off")
diff --git a/mesecons_lightstone/init.lua b/mesecons_lightstone/init.lua
index 55c3394..33e308e 100644
--- a/mesecons_lightstone/init.lua
+++ b/mesecons_lightstone/init.lua
@@ -8,7 +8,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
tile_images = {texture_on},
inventory_image = minetest.inventorycube(texture_on),
- groups = {cracky=2,not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon = 2},
+ groups = {cracky=2,not_in_creative_inventory=1, mesecon = 2},
drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
light_source = LIGHT_MAX-2,
description=name.." Lightstone",
@@ -33,6 +33,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
{'','group:mesecon_conductor_craftable',''},
}
})
+ mesecon:register_effector("mesecons_lightstone:lightstone_" .. name .. "_on", "mesecons_lightstone:lightstone_" .. name .. "_off")
end
diff --git a/mesecons_microcontroller/init.lua b/mesecons_microcontroller/init.lua
index 1d47710..faa9ffd 100644
--- a/mesecons_microcontroller/init.lua
+++ b/mesecons_microcontroller/init.lua
@@ -1,3 +1,9 @@
+mesecon:add_rules("microcontroller_all", { --flat rules (looks better with nodebox wires connection)
+{x = 1, y = 0, z = 0 },
+{x = 0, y = 0, z = 1 },
+{x = -1, y = 0, z = 0},
+{x = 0, y = 0, z = -1}})
+
EEPROM_SIZE = 255
for a = 0, 1 do
@@ -6,9 +12,9 @@ for c = 0, 1 do
for d = 0, 1 do
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then
- groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon_effector_on = 1, mesecon_effector_off = 0, mesecon = 2}
+ groups = {dig_immediate=2, not_in_creative_inventory=1, mesecon = 3}
else
- groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 0, mesecon = 2}
+ groups = {dig_immediate=2, mesecon = 3}
end
minetest.register_node(nodename, {
description = "Microcontroller",
@@ -17,7 +23,6 @@ minetest.register_node(nodename, {
"jeija_microcontroller_top_"..tostring(d)..tostring(c)..tostring(b)..tostring(a)..".png",
"jeija_microcontroller_sides.png",
},
- --inventory_image = "jeija_microcontroller_top_0000.png",
sunlight_propagates = true,
paramtype = "light",
@@ -88,16 +93,17 @@ minetest.register_node(nodename, {
update_yc(pos)
end,
})
+
local rules={}
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end
if (b == 1) then table.insert(rules, {x = 0, y = 0, z = 1}) end
if (c == 1) then table.insert(rules, {x = 1, y = 0, z = 0}) end
if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end
mesecon:add_rules(nodename, rules)
+
+mesecon:register_effector(nodename, nodename, mesecon:get_rules("microcontroller_all"))
if nodename ~= "mesecons_microcontroller:microcontroller0000" then
mesecon:add_receptor_node(nodename, rules)
-else
- mesecon:add_receptor_node_off(nodename)
end
end
end
diff --git a/mesecons_movestones/init.lua b/mesecons_movestones/init.lua
index 9e40be1..6441e61 100644
--- a/mesecons_movestones/init.lua
+++ b/mesecons_movestones/init.lua
@@ -39,9 +39,10 @@ minetest.register_node("mesecons_movestones:movestone", {
tile_images = {"jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_side.png", "jeija_movestone_arrows.png", "jeija_movestone_arrows.png"},
paramtype2 = "facedir",
legacy_facedir_simple = true,
- groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1},
+ groups = {cracky=3},
description="Movestone",
})
+mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone")
minetest.register_entity("mesecons_movestones:movestone_entity", {
physical = false,
@@ -116,9 +117,10 @@ minetest.register_node("mesecons_movestones:sticky_movestone", {
inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
paramtype2 = "facedir",
legacy_facedir_simple = true,
- groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1},
+ groups = {cracky=3},
description="Sticky Movestone",
})
+mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone")
minetest.register_craft({
output = '"mesecons_movestones:sticky_movestone" 2',
diff --git a/mesecons_noteblock/init.lua b/mesecons_noteblock/init.lua
index 09e3b8c..c976d52 100644
--- a/mesecons_noteblock/init.lua
+++ b/mesecons_noteblock/init.lua
@@ -1,7 +1,7 @@
minetest.register_node("mesecons_noteblock:noteblock", {
description = "Noteblock",
tile_images = {"mesecons_noteblock.png"},
- groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_effector_off = 1, mesecon = 2},
+ groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
drawtype = "allfaces_optional",
visual_scale = 1.3,
paramtype="light",
@@ -9,6 +9,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
end
})
+mesecon:register_effector("mesecons_noteblock:noteblock", "mesecons_noteblock:noteblock")
minetest.register_craft({
output = '"mesecons_noteblock:noteblock" 1',
diff --git a/mesecons_pistons/init.lua b/mesecons_pistons/init.lua
index 1c0a8a8..1bf7034 100644
--- a/mesecons_pistons/init.lua
+++ b/mesecons_pistons/init.lua
@@ -3,7 +3,7 @@
minetest.register_node("mesecons_pistons:piston_normal", {
description = "Piston",
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_side.png"},
- groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
+ groups = {cracky=3, mesecon = 2},
paramtype2 = "facedir",
after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)
@@ -18,12 +18,13 @@ minetest.register_node("mesecons_pistons:piston_normal", {
end
end,
})
+mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
--registration sticky one:
minetest.register_node("mesecons_pistons:piston_sticky", {
description = "Sticky Piston",
tiles = {"jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_tb.png", "jeija_piston_sticky_side.png"},
- groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1, mesecon = 2},
+ groups = {cracky=3, mesecon = 2},
paramtype2 = "facedir",
after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode)
@@ -38,6 +39,7 @@ minetest.register_node("mesecons_pistons:piston_sticky", {
end
end,
})
+mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
minetest.register_craft({
output = '"mesecons_pistons:piston_normal" 2',
diff --git a/mesecons_random/init.lua b/mesecons_random/init.lua
index d60b871..fe29bea 100644
--- a/mesecons_random/init.lua
+++ b/mesecons_random/init.lua
@@ -4,10 +4,12 @@ minetest.register_node("mesecons_random:removestone", {
tile_images = {"jeija_removestone.png"},
inventory_image = minetest.inventorycube("jeija_removestone_inv.png"),
material = minetest.digprop_stonelike(1.0),
- groups = {cracky=3, mesecon_effector_off = 1, mesecon = 2},
+ groups = {cracky=3, mesecon = 2},
description="Removestone",
})
+mesecon:register_effector(nil, "mesecons_random:removestone")
+
minetest.register_craft({
output = '"mesecons_random:removestone" 4',
recipe = {
diff --git a/mesecons_torch/init.lua b/mesecons_torch/init.lua
index c97fec8..5e12875 100644
--- a/mesecons_torch/init.lua
+++ b/mesecons_torch/init.lua
@@ -53,22 +53,8 @@ minetest.register_abm({
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
- local pa = {x=0, y=0, z=0}
local rules=mesecon.torch_get_rules(minetest.env:get_node(pos).param2)
-
- if node.param2 == 4 then
- pa.z = -2
- elseif node.param2 == 2 then
- pa.x = -2
- elseif node.param2 == 5 then
- pa.z = 2
- elseif node.param2 == 3 then
- pa.x = 2
- elseif node.param2 == 1 then
- pa.y = 2
- elseif node.param2 == 0 then
- pa.y = -2
- end
+ local pa = mesecon.torch_get_input_rules(node.param2)
local postc = {x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z}
if mesecon:is_power_on(postc) then
@@ -101,6 +87,25 @@ mesecon.torch_get_rules = function(param2)
return rules
end
+mesecon.torch_get_input_rules = function(param2)
+ local rules = {x=0, y=0, z=0}
+
+ if param2 == 4 then
+ rules.z = -2
+ elseif param2 == 2 then
+ rules.x = -2
+ elseif param2 == 5 then
+ rules.z = 2
+ elseif param2 == 3 then
+ rules.x = 2
+ elseif param2 == 1 then
+ rules.y = 2
+ elseif param2 == 0 then
+ rules.y = -2
+ end
+ return rules
+end
+
mesecon:add_rules("mesecontorch",
{{x=1, y=0, z=0},
{x=0, y=0, z=1},
@@ -110,6 +115,7 @@ mesecon:add_rules("mesecontorch",
mesecon:add_receptor_node("mesecons_torch:mesecon_torch_on", nil, mesecon.torch_get_rules)
mesecon:add_receptor_node_off("mesecons_torch:mesecon_torch_off", nil, mesecon.torch_get_rules)
+mesecon:register_effector("mesecons_torch:mesecon_torch_on","mesecons_torch:mesecon_torch_off", nil,mesecon.torch_get_input_rules)
-- Param2 Table (Block Attached To)
-- 5 = z-1