mirror of
https://github.com/minetest-mods/mesecons.git
synced 2024-08-21 05:24:11 +02:00
Make Delayer use facedir
This commit is contained in:
parent
6772bc0112
commit
b0a0387722
@ -62,83 +62,87 @@ end
|
|||||||
|
|
||||||
|
|
||||||
minetest.register_on_punchnode(function (pos, node)
|
minetest.register_on_punchnode(function (pos, node)
|
||||||
|
mesecon.delayer_get_output_rules(node.param2)
|
||||||
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_off_2"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
minetest.register_on_punchnode(function (pos, node)
|
minetest.register_on_punchnode(function (pos, node)
|
||||||
|
mesecon.delayer_get_output_rules(node.param2)
|
||||||
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_on_2"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mesecon.delayer_signal_change = function(pos, node)
|
mesecon.delayer_signal_change = 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
|
||||||
np={x=pos.x-1, y=pos.y, z=pos.z}
|
rules = mesecon.delayer_get_input_rules(node.param2)[1]
|
||||||
nn=minetest.env:get_node(np)
|
np = {x = pos.x + rules.x, y = pos.y + rules.y, z = pos.z + rules.z}
|
||||||
if nn.name=="mesecons:mesecon_on" or mesecon:is_receptor_node(nn.name, np, pos) then
|
|
||||||
|
if mesecon:is_power_on(np) then
|
||||||
local time
|
local time
|
||||||
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"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_1", param2=node.param2})
|
||||||
time=0.1
|
time=0.1
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_2" then
|
if node.name=="mesecons_delayer:delayer_off_2" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_2", param2=node.param2})
|
||||||
time=0.3
|
time=0.3
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_3" then
|
if node.name=="mesecons_delayer:delayer_off_3" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_3", param2=node.param2})
|
||||||
time=0.5
|
time=0.5
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_off_4" then
|
if node.name=="mesecons_delayer:delayer_off_4" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_on_4", param2=node.param2})
|
||||||
time=1
|
time=1
|
||||||
end
|
end
|
||||||
minetest.after(time, mesecon.delayer_turnon, {pos=pos})
|
minetest.after(time, mesecon.delayer_turnon, {pos=pos, param2=node.param2})
|
||||||
|
|
||||||
end
|
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
|
||||||
np={x=pos.x-1, y=pos.y, z=pos.z}
|
rules = mesecon.delayer_get_input_rules(node.param2)[1]
|
||||||
nn=minetest.env:get_node(np)
|
np = {x = pos.x + rules.x, y = pos.y + rules.y, z = pos.z + rules.z}
|
||||||
if nn.name=="mesecons:mesecon_off" or mesecon:is_receptor_node_off(nn.name, np, pos) or nn.name=="air" then
|
|
||||||
|
if not mesecon:is_power_on(np) then
|
||||||
local time
|
local time
|
||||||
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"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
|
||||||
time=0.1
|
time=0.1
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_2" then
|
if node.name=="mesecons_delayer:delayer_on_2" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_2", param2=node.param2})
|
||||||
time=0.3
|
time=0.3
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_3" then
|
if node.name=="mesecons_delayer:delayer_on_3" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_3", param2=node.param2})
|
||||||
time=0.5
|
time=0.5
|
||||||
end
|
end
|
||||||
if node.name=="mesecons_delayer:delayer_on_4" then
|
if node.name=="mesecons_delayer:delayer_on_4" then
|
||||||
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4"})
|
minetest.env:add_node(pos, {name="mesecons_delayer:delayer_off_4", param2=node.param2})
|
||||||
time=1
|
time=1
|
||||||
end
|
end
|
||||||
minetest.after(time, mesecon.delayer_turnoff, {pos=pos})
|
minetest.after(time, mesecon.delayer_turnoff, {pos=pos, param2=node.param2})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -146,21 +150,49 @@ end
|
|||||||
mesecon:register_on_signal_change(mesecon.delayer_signal_change)
|
mesecon:register_on_signal_change(mesecon.delayer_signal_change)
|
||||||
|
|
||||||
mesecon.delayer_turnon=function(params)
|
mesecon.delayer_turnon=function(params)
|
||||||
mesecon:receptor_on(params.pos, mesecon:get_rules("delayer"))
|
local rules = mesecon.delayer_get_output_rules(params.param2)
|
||||||
|
mesecon:receptor_on(params.pos, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
mesecon.delayer_turnoff=function(params)
|
mesecon.delayer_turnoff=function(params)
|
||||||
mesecon:receptor_off(params.pos, mesecon:get_rules("delayer"))
|
local rules = mesecon.delayer_get_output_rules(params.param2)
|
||||||
|
mesecon:receptor_off(params.pos, rules)
|
||||||
end
|
end
|
||||||
|
|
||||||
mesecon:add_rules("delayer", {{x=1, y=0, z=0}})
|
mesecon.delayer_get_output_rules = function(param2)
|
||||||
|
rules = {}
|
||||||
|
if param2 == 0 then
|
||||||
|
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||||
|
elseif param2 == 2 then
|
||||||
|
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||||
|
elseif param2 == 1 then
|
||||||
|
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||||
|
elseif param2 == 3 then
|
||||||
|
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||||
|
end
|
||||||
|
return rules
|
||||||
|
end
|
||||||
|
|
||||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", mesecon:get_rules("delayer"))
|
mesecon.delayer_get_input_rules = function(param2)
|
||||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", mesecon:get_rules("delayer"))
|
rules = {}
|
||||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", mesecon:get_rules("delayer"))
|
if param2 == 0 then
|
||||||
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", mesecon:get_rules("delayer"))
|
table.insert(rules, {x =-1, y = 0, z = 0})
|
||||||
|
elseif param2 == 2 then
|
||||||
|
table.insert(rules, {x = 1, y = 0, z = 0})
|
||||||
|
elseif param2 == 1 then
|
||||||
|
table.insert(rules, {x = 0, y = 0, z = 1})
|
||||||
|
elseif param2 == 3 then
|
||||||
|
table.insert(rules, {x = 0, y = 0, z =-1})
|
||||||
|
end
|
||||||
|
return rules
|
||||||
|
end
|
||||||
|
|
||||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", mesecon:get_rules("delayer"))
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_1", nil, mesecon.delayer_get_output_rules)
|
||||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", mesecon:get_rules("delayer"))
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_2", nil, mesecon.delayer_get_output_rules)
|
||||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", mesecon:get_rules("delayer"))
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_3", nil, mesecon.delayer_get_output_rules)
|
||||||
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", mesecon:get_rules("delayer"))
|
mesecon:add_receptor_node("mesecons_delayer:delayer_on_4", nil, mesecon.delayer_get_output_rules)
|
||||||
|
|
||||||
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_1", nil, mesecon.delayer_get_output_rules)
|
||||||
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_2", nil, mesecon.delayer_get_output_rules)
|
||||||
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_3", nil, mesecon.delayer_get_output_rules)
|
||||||
|
mesecon:add_receptor_node_off("mesecons_delayer:delayer_off_4", nil, mesecon.delayer_get_output_rules)
|
||||||
|
Loading…
Reference in New Issue
Block a user