forked from minetest-mods/mesecons
Bugfix foes for pistons, delayyrs, gates and microcontrollers. Rework delayers.
This commit is contained in:
parent
5a88a9715f
commit
7fe4947056
@ -70,6 +70,7 @@ dofile(minetest.get_modpath("mesecons").."/internal.lua");
|
||||
|
||||
-- Deprecated stuff
|
||||
-- To be removed in future releases
|
||||
-- Currently there is nothing here
|
||||
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||
|
||||
-- API
|
||||
@ -100,7 +101,7 @@ function mesecon:receptor_off(pos, rules)
|
||||
end
|
||||
|
||||
|
||||
print("[OK] mesecons")
|
||||
print("[OK] Mesecons")
|
||||
|
||||
--The actual wires
|
||||
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
||||
|
@ -331,9 +331,26 @@ function mesecon:turnoff(pos, rulename)
|
||||
end
|
||||
|
||||
|
||||
function mesecon:connected_to_receptor(pos, checked)
|
||||
checked = checked or {}
|
||||
function mesecon:connected_to_receptor(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
-- Check if conductors around are connected
|
||||
local rules = mesecon:get_any_inputrules(node)
|
||||
if not rules then return false end
|
||||
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
if mesecon:rules_link(np, pos) then
|
||||
if mesecon:find_receptor_on(np, {}) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:find_receptor_on(pos, checked)
|
||||
-- find out if node has already been checked (to prevent from endless loop)
|
||||
for _, cp in ipairs(checked) do
|
||||
if mesecon:cmpPos(cp, pos) then
|
||||
@ -343,27 +360,25 @@ function mesecon:connected_to_receptor(pos, checked)
|
||||
|
||||
-- add current position to checked
|
||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
||||
|
||||
local node = minetest.env:get_node(pos)
|
||||
|
||||
if mesecon:is_conductor(node.name) then
|
||||
-- Check if conductors around are connected
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
if mesecon:is_receptor_on(node.name) then
|
||||
return true
|
||||
end
|
||||
|
||||
if mesecon:is_conductor(node.name) then
|
||||
local rules = mesecon:conductor_get_rules(node)
|
||||
for _, rule in ipairs(rules) do
|
||||
local np = mesecon:addPosRule(pos, rule)
|
||||
if mesecon:rules_link(np, pos) then
|
||||
connected, checked = mesecon:connected_to_receptor(np, checked)
|
||||
if connected then
|
||||
if mesecon:find_receptor_on(np, checked) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif mesecon:is_receptor_on(node.name) then
|
||||
return true
|
||||
end
|
||||
|
||||
return false, checked
|
||||
return false
|
||||
end
|
||||
|
||||
function mesecon:rules_link(output, input, dug_outputrules) --output/input are positions (outputrules optional, used if node has been dug), second return value: the name of the affected input rule
|
||||
|
@ -1,28 +1,16 @@
|
||||
-- Function that get the input/output rules of the delayer
|
||||
local delayer_get_output_rules = function(node)
|
||||
local rules = {}
|
||||
if node.param2 == 0 then
|
||||
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||
elseif node.param2 == 2 then
|
||||
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||
elseif node.param2 == 1 then
|
||||
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||
elseif node.param2 == 3 then
|
||||
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||
local rules = {{x = 0, y = 0, z = 1}}
|
||||
for i = 0, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
|
||||
local delayer_get_input_rules = function(node)
|
||||
local rules = {}
|
||||
if node.param2 == 0 then
|
||||
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||
elseif node.param2 == 2 then
|
||||
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||
elseif node.param2 == 1 then
|
||||
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||
elseif node.param2 == 3 then
|
||||
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||
local rules = {{x = 0, y = 0, z = -1}}
|
||||
for i = 0, node.param2 do
|
||||
rules = mesecon:rotate_rules_left(rules)
|
||||
end
|
||||
return rules
|
||||
end
|
||||
@ -30,54 +18,30 @@ end
|
||||
-- Functions that are called after the delay time
|
||||
|
||||
local delayer_turnon = function(params)
|
||||
local rules = delayer_get_output_rules(params)
|
||||
local rules = delayer_get_output_rules(params.node)
|
||||
mesecon:receptor_on(params.pos, rules)
|
||||
end
|
||||
|
||||
local delayer_turnoff = function(params)
|
||||
local rules = delayer_get_output_rules(params)
|
||||
local rules = delayer_get_output_rules(params.node)
|
||||
mesecon:receptor_off(params.pos, rules)
|
||||
end
|
||||
|
||||
local delayer_update = function(pos, node)
|
||||
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
|
||||
local time = 0
|
||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_1")
|
||||
time=0.1
|
||||
elseif node.name=="mesecons_delayer:delayer_off_2" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_2")
|
||||
time=0.3
|
||||
elseif node.name=="mesecons_delayer:delayer_off_3" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_3")
|
||||
time=0.5
|
||||
elseif node.name=="mesecons_delayer:delayer_off_4" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_4")
|
||||
time=1
|
||||
end
|
||||
minetest.after(time, delayer_turnon, {pos=pos, param2=node.param2})
|
||||
end
|
||||
|
||||
if string.find(node.name, "mesecons_delayer:delayer_on")~=nil then
|
||||
local time = 0
|
||||
if node.name=="mesecons_delayer:delayer_on_1" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_1")
|
||||
time=0.1
|
||||
elseif node.name=="mesecons_delayer:delayer_on_2" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_2")
|
||||
time=0.3
|
||||
elseif node.name=="mesecons_delayer:delayer_on_3" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_3")
|
||||
time=0.5
|
||||
elseif node.name=="mesecons_delayer:delayer_on_4" then
|
||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_off_4")
|
||||
time=1
|
||||
end
|
||||
minetest.after(time, delayer_turnoff, {pos=pos, param2=node.param2})
|
||||
end
|
||||
local delayer_activate = function(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local time = def.delayer_time
|
||||
mesecon:swap_node(pos, def.delayer_onstate)
|
||||
minetest.after(time, delayer_turnon , {pos = pos, node = node})
|
||||
end
|
||||
|
||||
--Actually register the 2 (states) x 4 (delay times) delayers
|
||||
local delayer_deactivate = function(pos, node)
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
local time = def.delayer_time
|
||||
mesecon:swap_node(pos, def.delayer_offstate)
|
||||
minetest.after(time, delayer_turnoff, {pos = pos, node = node})
|
||||
end
|
||||
|
||||
-- Register the 2 (states) x 4 (delay times) delayers
|
||||
|
||||
for i = 1, 4 do
|
||||
local groups = {}
|
||||
@ -87,6 +51,12 @@ else
|
||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
||||
end
|
||||
|
||||
local delaytime
|
||||
if i == 1 then delaytime = 0.1
|
||||
elseif i == 2 then delaytime = 0.3
|
||||
elseif i == 3 then delaytime = 0.5
|
||||
elseif i == 4 then delaytime = 1.0 end
|
||||
|
||||
boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
||||
|
||||
{ -2/16, -7/16, -4/16, 2/16, -26/64, -3/16 }, -- the jeweled "on" indicator
|
||||
@ -138,6 +108,8 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
|
||||
end
|
||||
end,
|
||||
delayer_time = delaytime,
|
||||
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
|
||||
mesecons = {
|
||||
receptor =
|
||||
{
|
||||
@ -147,7 +119,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
|
||||
effector =
|
||||
{
|
||||
rules = delayer_get_input_rules,
|
||||
action_change = delayer_update
|
||||
action_on = delayer_activate
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -190,6 +162,8 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
||||
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
|
||||
end
|
||||
end,
|
||||
delayer_time = delaytime,
|
||||
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
|
||||
mesecons = {
|
||||
receptor =
|
||||
{
|
||||
@ -199,7 +173,7 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
||||
effector =
|
||||
{
|
||||
rules = delayer_get_input_rules,
|
||||
action_change = delayer_update
|
||||
action_off = delayer_deactivate
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -20,7 +20,7 @@ end
|
||||
function mesecon:mvps_process_stack(stack)
|
||||
-- update mesecons for placed nodes ( has to be done after all nodes have been added )
|
||||
for _, n in ipairs(stack) do
|
||||
mesecon.on_placenode(n.pos, n.node)
|
||||
mesecon.on_placenode(n.pos, minetest.env:get_node(n.pos))
|
||||
mesecon:update_autoconnect(n.pos)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user