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)

This commit is contained in:
Jeija 2012-08-13 20:17:45 +02:00
parent 24c50571f7
commit 00ce2540c2
14 changed files with 206 additions and 163 deletions

View File

@ -154,7 +154,7 @@ function mesecon:receptor_on(pos, rules)
np.x = pos.x + rules[i].x np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z np.z = pos.z + rules[i].z
mesecon:turnon(np) mesecon:turnon(np, pos)
i=i+1 i=i+1
end end
end end
@ -164,7 +164,6 @@ function mesecon:receptor_off(pos, rules)
rules = mesecon:get_rules("default") rules = mesecon:get_rules("default")
end end
local checked = {}
local connected = false local connected = false
local i = 1 local i = 1
while rules[i]~=nil do while rules[i]~=nil do
@ -172,9 +171,9 @@ function mesecon:receptor_off(pos, rules)
np.x = pos.x + rules[i].x np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z np.z = pos.z + rules[i].z
connected, checked = mesecon:connected_to_pw_src(np, checked) connected = mesecon:connected_to_pw_src(np)
if not connected then if connected == false then
mesecon:turnoff(np) mesecon:turnoff(np, pos)
end end
i=i+1 i=i+1
end end

View File

@ -1,5 +1,6 @@
-- INTERNAL API -- INTERNAL
--Receptors
function mesecon:is_receptor_node(nodename) function mesecon:is_receptor_node(nodename)
local i = 1 local i = 1
while mesecon.receptors[i] ~= nil do while mesecon.receptors[i] ~= nil do
@ -53,6 +54,33 @@ function mesecon:receptor_get_rules(node)
return nil return nil
end 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) function mesecon:effector_get_input_rules(node)
local i = 1 local i = 1
while(mesecon.effectors[i] ~= nil) do 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 or mesecon.effectors[i].offstate == node.name then
if mesecon.effectors[i].get_input_rules ~= nil then if mesecon.effectors[i].get_input_rules ~= nil then
return mesecon.effectors[i].get_input_rules(node.param2) 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 return mesecon.effectors[i].input_rules
else else
return mesecon:get_rules("default") return mesecon:get_rules("default")
@ -89,16 +117,16 @@ function mesecon:receptor_outputs (cpos, rpos) --cpos = conductor pos, rpos = re
return false return false
end end
function mesecon:effector_inputs (cpos, rpos) --cpos = conductor pos, rpos = receptor pos function mesecon:effector_inputs (srcpos, destpos)
local rnode = minetest.env:get_node (rpos) local destnode = minetest.env:get_node (destpos)
local rules = mesecon:effector_get_input_rules (rnode) local rules = mesecon:effector_get_input_rules (destnode)
if rules == nil then return false end if rules == nil then return false end
local i = 1 local i = 1
while rules[i] ~= nil do while rules[i] ~= nil do
if rpos.x + rules[i].x == cpos.x if destpos.x + rules[i].x == srcpos.x
and rpos.y + rules[i].y == cpos.y and destpos.y + rules[i].y == srcpos.y
and rpos.z + rules[i].z == cpos.z then and destpos.z + rules[i].z == srcpos.z then
return true return true
end end
i = i + 1 i = i + 1
@ -214,59 +242,6 @@ function mesecon:is_conductor_off(name)
return false return false
end 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) function mesecon:is_power_on(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_on(node.name) or mesecon:is_receptor_node(node.name) then 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) function mesecon:is_power_off(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_node_off(node.name) then if mesecon:is_conductor_off(node.name) or mesecon:is_receptor_node_off(node.name) then
return 1 return true
end end
return 0 return false
end end
function mesecon:turnon(pos) function mesecon:turnon(pos, sourcepos)
local node = minetest.env:get_node(pos) 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 if mesecon:is_conductor_off(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_on(node.name)}) 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 while rules[i]~=nil do
local np = {} local np = {}
np.x = pos.x + rules[i].x np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z np.z = pos.z + rules[i].z
mesecon:turnon(np)
mesecon:turnon(np, pos)
i=i+1 i=i+1
end end
end end
if mesecon:is_effector(node.name) then
if mesecon:effector_inputs(sourcepos, pos) then
mesecon:changesignal(pos) mesecon:changesignal(pos)
if minetest.get_item_group(node.name, "mesecon_effector_off") == 1 then if mesecon:is_effector_off(node.name) then mesecon:activate(pos) end
mesecon:activate(pos) end
end end
end end
function mesecon:turnoff(pos) function mesecon:turnoff(pos, sourcepos)
local node = minetest.env:get_node(pos) 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 if mesecon:is_conductor_on(node.name) then
minetest.env:add_node(pos, {name=mesecon:get_conductor_off(node.name)}) 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 while rules[i]~=nil do
local np = {} local np = {}
np.x = pos.x + rules[i].x np.x = pos.x + rules[i].x
np.y = pos.y + rules[i].y np.y = pos.y + rules[i].y
np.z = pos.z + rules[i].z np.z = pos.z + rules[i].z
mesecon:turnoff(np)
i=i+1 mesecon:turnoff(np, pos)
i = i + 1
end end
end end
mesecon:changesignal(pos) --Changesignal is always thrown because nodes can be both receptors and effectors if mesecon:is_effector(node.name) then
if minetest.get_item_group(node.name, "mesecon_effector_on") == 1 and if mesecon:effector_inputs(sourcepos, pos) then
not mesecon:is_powered(pos) then --Check if the signal comes from another source mesecon:changesignal(pos)
--Send Signals to effectors: if mesecon:is_effector_on(node.name) then mesecon:deactivate(pos) end
mesecon:deactivate(pos) end
end end
end end
@ -456,3 +433,56 @@ end
function compare_pos(pos1, pos2) function compare_pos(pos1, pos2)
return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z return pos1.x == pos2.x and pos1.y == pos2.y and pos1.z == pos2.z
end 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

View File

@ -1,7 +1,7 @@
minetest.register_on_dignode( minetest.register_on_dignode(
function(pos, oldnode, digger) function(pos, oldnode, digger)
if mesecon:is_conductor_on(oldnode.name) then if mesecon:is_conductor_on(oldnode.name) then
local i = 1 print("receptor_off")
mesecon:receptor_off(pos) mesecon:receptor_off(pos)
end end
@ -19,7 +19,7 @@ minetest.register_on_placenode(
if mesecon:is_powered(pos) then if mesecon:is_powered(pos) then
if mesecon:is_conductor_off(node.name) 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 else
mesecon:changesignal(pos) mesecon:changesignal(pos)
mesecon:activate(pos) mesecon:activate(pos)

View File

@ -19,10 +19,9 @@ for i = 1, 5 do
type = "fixed", type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 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", description="Battery",
}) })
mesecon:add_receptor_node_off("mesecons_battery:battery_charging_"..i)
end end
for i = 1, 5 do for i = 1, 5 do
@ -46,10 +45,11 @@ for i = 1, 5 do
type = "fixed", type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, 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", description="Battery",
}) })
mesecon:add_receptor_node("mesecons_battery:battery_discharging_"..i) mesecon:add_receptor_node("mesecons_battery:battery_discharging_"..i)
mesecon:register_effector("mesecons_battery:battery_discharging_"..i, "mesecons_battery:battery_charging_"..i)
end end
minetest.register_on_placenode(function (pos, newnode, placer) minetest.register_on_placenode(function (pos, newnode, placer)

View File

@ -115,10 +115,6 @@ end)
mesecon.delayer_update = function(pos, node) mesecon.delayer_update = function(pos, node)
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then 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 local time = 0
if node.name=="mesecons_delayer:delayer_off_1" then if node.name=="mesecons_delayer:delayer_off_1" then
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2}) minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
@ -138,13 +134,8 @@ mesecon.delayer_update = function(pos, node)
end end
minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2}) minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
end end
end
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then 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 local time = 0
if node.name=="mesecons_delayer:delayer_on_1" then if node.name=="mesecons_delayer:delayer_on_1" then
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2}) minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
@ -164,7 +155,6 @@ mesecon.delayer_update = function(pos, node)
end end
minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2}) minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
end end
end
end end
mesecon:register_on_signal_change(mesecon.delayer_update) mesecon:register_on_signal_change(mesecon.delayer_update)

View File

@ -100,6 +100,7 @@ for i = 1, 4 do
}, },
on_punch = mesecons_door_transform on_punch = mesecons_door_transform
}) })
mesecon:register_effector("mesecons_door:door_"..i.."_"..j, "mesecons_door:door_"..i.."_"..j)
end end
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"}) minetest.env:add_node(node_pos, {name = "mesecons_door:door_"..best_number.."_1"})
end end
}) })
mesecon:register_effector("mesecons_door:door")
minetest.register_on_placenode(function(pos, newnode, placer) minetest.register_on_placenode(function(pos, newnode, placer)
local b_pos = {x = pos.x, y = pos.y - 1, z = pos.z} local b_pos = {x = pos.x, y = pos.y - 1, z = pos.z}

View File

@ -71,3 +71,5 @@ mesecon:register_on_signal_off(function(pos, node)
nodeupdate(pos) nodeupdate(pos)
end end
end) end)
mesecon:register_effector("mesecons_lamp:lamp_on", "mesecons_lamp:lamp_off")

View File

@ -8,7 +8,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", { minetest.register_node("mesecons_lightstone:lightstone_" .. name .. "_on", {
tile_images = {texture_on}, tile_images = {texture_on},
inventory_image = minetest.inventorycube(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", drop = "node mesecons_lightstone:lightstone_" .. name .. "_off 1",
light_source = LIGHT_MAX-2, light_source = LIGHT_MAX-2,
description=name.." Lightstone", description=name.." Lightstone",
@ -33,6 +33,7 @@ function mesecon:lightstone_add(name, base_item, texture_off, texture_on)
{'','group:mesecon_conductor_craftable',''}, {'','group:mesecon_conductor_craftable',''},
} }
}) })
mesecon:register_effector("mesecons_lightstone:lightstone_" .. name .. "_on", "mesecons_lightstone:lightstone_" .. name .. "_off")
end end

View File

@ -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 EEPROM_SIZE = 255
for a = 0, 1 do for a = 0, 1 do
@ -6,9 +12,9 @@ for c = 0, 1 do
for d = 0, 1 do for d = 0, 1 do
local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a) local nodename = "mesecons_microcontroller:microcontroller"..tostring(d)..tostring(c)..tostring(b)..tostring(a)
if tostring(d)..tostring(c)..tostring(b)..tostring(a) ~= "0000" then 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 else
groups = {dig_immediate=2, mesecon_effector_on = 1, mesecon_effector_off = 0, mesecon = 2} groups = {dig_immediate=2, mesecon = 3}
end end
minetest.register_node(nodename, { minetest.register_node(nodename, {
description = "Microcontroller", description = "Microcontroller",
@ -17,7 +23,6 @@ minetest.register_node(nodename, {
"jeija_microcontroller_top_"..tostring(d)..tostring(c)..tostring(b)..tostring(a)..".png", "jeija_microcontroller_top_"..tostring(d)..tostring(c)..tostring(b)..tostring(a)..".png",
"jeija_microcontroller_sides.png", "jeija_microcontroller_sides.png",
}, },
--inventory_image = "jeija_microcontroller_top_0000.png",
sunlight_propagates = true, sunlight_propagates = true,
paramtype = "light", paramtype = "light",
@ -88,16 +93,17 @@ minetest.register_node(nodename, {
update_yc(pos) update_yc(pos)
end, end,
}) })
local rules={} local rules={}
if (a == 1) then table.insert(rules, {x = -1, y = 0, z = 0}) end 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 (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 (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 if (d == 1) then table.insert(rules, {x = 0, y = 0, z = -1}) end
mesecon:add_rules(nodename, rules) mesecon:add_rules(nodename, rules)
mesecon:register_effector(nodename, nodename, mesecon:get_rules("microcontroller_all"))
if nodename ~= "mesecons_microcontroller:microcontroller0000" then if nodename ~= "mesecons_microcontroller:microcontroller0000" then
mesecon:add_receptor_node(nodename, rules) mesecon:add_receptor_node(nodename, rules)
else
mesecon:add_receptor_node_off(nodename)
end end
end end
end end

View File

@ -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"}, 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", paramtype2 = "facedir",
legacy_facedir_simple = true, legacy_facedir_simple = true,
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1}, groups = {cracky=3},
description="Movestone", description="Movestone",
}) })
mesecon:register_effector("mesecons_movestones:movestone", "mesecons_movestones:movestone")
minetest.register_entity("mesecons_movestones:movestone_entity", { minetest.register_entity("mesecons_movestones:movestone_entity", {
physical = false, 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"), inventory_image = minetest.inventorycube("jeija_sticky_movestone.png", "jeija_movestone_side.png", "jeija_movestone_side.png"),
paramtype2 = "facedir", paramtype2 = "facedir",
legacy_facedir_simple = true, legacy_facedir_simple = true,
groups = {cracky=3, mesecon_effector_on = 1, mesecon_effector_off = 1}, groups = {cracky=3},
description="Sticky Movestone", description="Sticky Movestone",
}) })
mesecon:register_effector("mesecons_movestones:sticky_movestone", "mesecons_movestones:sticky_movestone")
minetest.register_craft({ minetest.register_craft({
output = '"mesecons_movestones:sticky_movestone" 2', output = '"mesecons_movestones:sticky_movestone" 2',

View File

@ -1,7 +1,7 @@
minetest.register_node("mesecons_noteblock:noteblock", { minetest.register_node("mesecons_noteblock:noteblock", {
description = "Noteblock", description = "Noteblock",
tile_images = {"mesecons_noteblock.png"}, 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", drawtype = "allfaces_optional",
visual_scale = 1.3, visual_scale = 1.3,
paramtype="light", paramtype="light",
@ -9,6 +9,7 @@ minetest.register_node("mesecons_noteblock:noteblock", {
minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0}) minetest.env:add_node(pos, {name="mesecons_noteblock:noteblock", param2=0})
end end
}) })
mesecon:register_effector("mesecons_noteblock:noteblock", "mesecons_noteblock:noteblock")
minetest.register_craft({ minetest.register_craft({
output = '"mesecons_noteblock:noteblock" 1', output = '"mesecons_noteblock:noteblock" 1',

View File

@ -3,7 +3,7 @@
minetest.register_node("mesecons_pistons:piston_normal", { minetest.register_node("mesecons_pistons:piston_normal", {
description = "Piston", 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"}, 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", paramtype2 = "facedir",
after_dig_node = function(pos, oldnode) after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode) local dir = mesecon:piston_get_direction(oldnode)
@ -18,12 +18,13 @@ minetest.register_node("mesecons_pistons:piston_normal", {
end end
end, end,
}) })
mesecon:register_effector("mesecons_pistons:piston_normal", "mesecons_pistons:piston_normal")
--registration sticky one: --registration sticky one:
minetest.register_node("mesecons_pistons:piston_sticky", { minetest.register_node("mesecons_pistons:piston_sticky", {
description = "Sticky Piston", 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"}, 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", paramtype2 = "facedir",
after_dig_node = function(pos, oldnode) after_dig_node = function(pos, oldnode)
local dir = mesecon:piston_get_direction(oldnode) local dir = mesecon:piston_get_direction(oldnode)
@ -38,6 +39,7 @@ minetest.register_node("mesecons_pistons:piston_sticky", {
end end
end, end,
}) })
mesecon:register_effector("mesecons_pistons:piston_sticky", "mesecons_pistons:piston_sticky")
minetest.register_craft({ minetest.register_craft({
output = '"mesecons_pistons:piston_normal" 2', output = '"mesecons_pistons:piston_normal" 2',

View File

@ -4,10 +4,12 @@ minetest.register_node("mesecons_random:removestone", {
tile_images = {"jeija_removestone.png"}, tile_images = {"jeija_removestone.png"},
inventory_image = minetest.inventorycube("jeija_removestone_inv.png"), inventory_image = minetest.inventorycube("jeija_removestone_inv.png"),
material = minetest.digprop_stonelike(1.0), material = minetest.digprop_stonelike(1.0),
groups = {cracky=3, mesecon_effector_off = 1, mesecon = 2}, groups = {cracky=3, mesecon = 2},
description="Removestone", description="Removestone",
}) })
mesecon:register_effector(nil, "mesecons_random:removestone")
minetest.register_craft({ minetest.register_craft({
output = '"mesecons_random:removestone" 4', output = '"mesecons_random:removestone" 4',
recipe = { recipe = {

View File

@ -53,22 +53,8 @@ minetest.register_abm({
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) 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) local rules=mesecon.torch_get_rules(minetest.env:get_node(pos).param2)
local pa = mesecon.torch_get_input_rules(node.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 postc = {x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z} local postc = {x=pos.x-pa.x, y=pos.y-pa.y, z=pos.z-pa.z}
if mesecon:is_power_on(postc) then if mesecon:is_power_on(postc) then
@ -101,6 +87,25 @@ mesecon.torch_get_rules = function(param2)
return rules return rules
end 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", mesecon:add_rules("mesecontorch",
{{x=1, y=0, z=0}, {{x=1, y=0, z=0},
{x=0, y=0, z=1}, {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("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: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) -- Param2 Table (Block Attached To)
-- 5 = z-1 -- 5 = z-1