mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-12-28 16:27:28 +01:00
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
|
-- Deprecated stuff
|
||||||
-- To be removed in future releases
|
-- To be removed in future releases
|
||||||
|
-- Currently there is nothing here
|
||||||
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
dofile(minetest.get_modpath("mesecons").."/legacy.lua");
|
||||||
|
|
||||||
-- API
|
-- API
|
||||||
@ -100,7 +101,7 @@ function mesecon:receptor_off(pos, rules)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
print("[OK] mesecons")
|
print("[OK] Mesecons")
|
||||||
|
|
||||||
--The actual wires
|
--The actual wires
|
||||||
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
dofile(minetest.get_modpath("mesecons").."/wires.lua");
|
||||||
|
@ -331,9 +331,26 @@ function mesecon:turnoff(pos, rulename)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function mesecon:connected_to_receptor(pos, checked)
|
function mesecon:connected_to_receptor(pos)
|
||||||
checked = checked or {}
|
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)
|
-- find out if node has already been checked (to prevent from endless loop)
|
||||||
for _, cp in ipairs(checked) do
|
for _, cp in ipairs(checked) do
|
||||||
if mesecon:cmpPos(cp, pos) then
|
if mesecon:cmpPos(cp, pos) then
|
||||||
@ -343,27 +360,25 @@ function mesecon:connected_to_receptor(pos, checked)
|
|||||||
|
|
||||||
-- add current position to checked
|
-- add current position to checked
|
||||||
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
table.insert(checked, {x=pos.x, y=pos.y, z=pos.z})
|
||||||
|
|
||||||
local node = minetest.env:get_node(pos)
|
local node = minetest.env:get_node(pos)
|
||||||
|
|
||||||
if mesecon:is_conductor(node.name) then
|
if mesecon:is_receptor_on(node.name) then
|
||||||
-- Check if conductors around are connected
|
return true
|
||||||
local rules = mesecon:conductor_get_rules(node)
|
end
|
||||||
|
|
||||||
|
if mesecon:is_conductor(node.name) then
|
||||||
|
local rules = mesecon:conductor_get_rules(node)
|
||||||
for _, rule in ipairs(rules) do
|
for _, rule in ipairs(rules) do
|
||||||
local np = mesecon:addPosRule(pos, rule)
|
local np = mesecon:addPosRule(pos, rule)
|
||||||
if mesecon:rules_link(np, pos) then
|
if mesecon:rules_link(np, pos) then
|
||||||
connected, checked = mesecon:connected_to_receptor(np, checked)
|
if mesecon:find_receptor_on(np, checked) then
|
||||||
if connected then
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif mesecon:is_receptor_on(node.name) then
|
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false, checked
|
return false
|
||||||
end
|
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
|
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
|
-- Function that get the input/output rules of the delayer
|
||||||
local delayer_get_output_rules = function(node)
|
local delayer_get_output_rules = function(node)
|
||||||
local rules = {}
|
local rules = {{x = 0, y = 0, z = 1}}
|
||||||
if node.param2 == 0 then
|
for i = 0, node.param2 do
|
||||||
table.insert(rules, {x = 1, y = 0, z = 0})
|
rules = mesecon:rotate_rules_left(rules)
|
||||||
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})
|
|
||||||
end
|
end
|
||||||
return rules
|
return rules
|
||||||
end
|
end
|
||||||
|
|
||||||
local delayer_get_input_rules = function(node)
|
local delayer_get_input_rules = function(node)
|
||||||
local rules = {}
|
local rules = {{x = 0, y = 0, z = -1}}
|
||||||
if node.param2 == 0 then
|
for i = 0, node.param2 do
|
||||||
table.insert(rules, {x =-1, y = 0, z = 0})
|
rules = mesecon:rotate_rules_left(rules)
|
||||||
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})
|
|
||||||
end
|
end
|
||||||
return rules
|
return rules
|
||||||
end
|
end
|
||||||
@ -30,54 +18,30 @@ end
|
|||||||
-- Functions that are called after the delay time
|
-- Functions that are called after the delay time
|
||||||
|
|
||||||
local delayer_turnon = function(params)
|
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)
|
mesecon:receptor_on(params.pos, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
local delayer_turnoff = function(params)
|
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)
|
mesecon:receptor_off(params.pos, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
local delayer_update = function(pos, node)
|
local delayer_activate = function(pos, node)
|
||||||
if string.find(node.name, "mesecons_delayer:delayer_off")~=nil then
|
local def = minetest.registered_nodes[node.name]
|
||||||
local time = 0
|
local time = def.delayer_time
|
||||||
if node.name=="mesecons_delayer:delayer_off_1" then
|
mesecon:swap_node(pos, def.delayer_onstate)
|
||||||
mesecon:swap_node(pos, "mesecons_delayer:delayer_on_1")
|
minetest.after(time, delayer_turnon , {pos = pos, node = node})
|
||||||
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
|
|
||||||
end
|
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
|
for i = 1, 4 do
|
||||||
local groups = {}
|
local groups = {}
|
||||||
@ -87,6 +51,12 @@ else
|
|||||||
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
||||||
end
|
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
|
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
|
{ -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")
|
mesecon:swap_node(pos,"mesecons_delayer:delayer_off_1")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
delayer_time = delaytime,
|
||||||
|
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
|
||||||
mesecons = {
|
mesecons = {
|
||||||
receptor =
|
receptor =
|
||||||
{
|
{
|
||||||
@ -147,7 +119,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
|
|||||||
effector =
|
effector =
|
||||||
{
|
{
|
||||||
rules = delayer_get_input_rules,
|
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")
|
mesecon:swap_node(pos,"mesecons_delayer:delayer_on_1")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
delayer_time = delaytime,
|
||||||
|
delayer_offstate = "mesecons_delayer:delayer_off_"..tostring(i),
|
||||||
mesecons = {
|
mesecons = {
|
||||||
receptor =
|
receptor =
|
||||||
{
|
{
|
||||||
@ -199,7 +173,7 @@ minetest.register_node("mesecons_delayer:delayer_on_"..tostring(i), {
|
|||||||
effector =
|
effector =
|
||||||
{
|
{
|
||||||
rules = delayer_get_input_rules,
|
rules = delayer_get_input_rules,
|
||||||
action_change = delayer_update
|
action_off = delayer_deactivate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -20,7 +20,7 @@ end
|
|||||||
function mesecon:mvps_process_stack(stack)
|
function mesecon:mvps_process_stack(stack)
|
||||||
-- update mesecons for placed nodes ( has to be done after all nodes have been added )
|
-- update mesecons for placed nodes ( has to be done after all nodes have been added )
|
||||||
for _, n in ipairs(stack) do
|
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)
|
mesecon:update_autoconnect(n.pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user