Repeaters: Set correct lock state on placement

This commit is contained in:
Wuzzy 2018-01-27 14:32:21 +01:00
parent b3d069b53a
commit 878743cee5
1 changed files with 32 additions and 5 deletions

View File

@ -15,10 +15,17 @@ local delayer_get_input_rules = function(node)
return rules return rules
end end
local delayer_get_all_rules = function(node) -- Return the sides of a delayer.
local orules = delayer_get_output_rules(node) -- Those are used to toggle the lock state.
local irules = delayer_get_input_rules(node) local delayer_get_sides = function(node)
return mesecon.mergetables(orules, irules) local rules = {
{x = 0, y = 0, z = -1},
{x = 0, y = 0, z = 1},
}
for i = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end end
local check_lock_repeater = function(pos, node) local check_lock_repeater = function(pos, node)
@ -140,12 +147,30 @@ boxes = {
} }
end end
local help, longdesc, usagehelp, icon local help, longdesc, usagehelp, icon, on_construct
if i == 1 then if i == 1 then
help = true help = true
longdesc = "Redstone repeaters are versatile redstone components which delay redstone signals and only allow redstone signals to travel through one direction. The delay of the signal is indicated by the redstone torches and is between 0.1 and 0.4 seconds long." longdesc = "Redstone repeaters are versatile redstone components which delay redstone signals and only allow redstone signals to travel through one direction. The delay of the signal is indicated by the redstone torches and is between 0.1 and 0.4 seconds long."
usagehelp = "To power a redstone repeater, send a signal in “arrow” direction. To change the delay, rightclick the redstone repeater. The delay is changed in steps of 0.1 seconds." usagehelp = "To power a redstone repeater, send a signal in “arrow” direction. To change the delay, rightclick the redstone repeater. The delay is changed in steps of 0.1 seconds."
icon = "mesecons_delayer_item.png" icon = "mesecons_delayer_item.png"
on_construct = function(pos)
local node = minetest.get_node(pos)
local sides = delayer_get_sides(node)
for s=1, #sides do
local spos = vector.add(pos, sides[s])
local snode = minetest.get_node(spos)
local g = minetest.get_item_group(snode.name, "redstone_repeater")
local sdef = minetest.registered_nodes[snode.name]
if g ~= 0 and sdef.mesecons.receptor.state == mesecon.state.on then
if mesecon.is_powered(pos, delayer_get_input_rules(node)[1]) ~= false then
minetest.swap_node(pos, {name="mesecons_delayer:delayer_on_locked", param2 = node.param2})
else
minetest.swap_node(pos, {name="mesecons_delayer:delayer_off_locked", param2 = node.param2})
end
break
end
end
end
else else
help = false help = false
end end
@ -155,6 +180,7 @@ if minetest.get_modpath("screwdriver") then
on_rotate = screwdriver.disallow on_rotate = screwdriver.disallow
end end
minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), { minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
description = "Redstone Repeater", description = "Redstone Repeater",
inventory_image = icon, inventory_image = icon,
@ -202,6 +228,7 @@ minetest.register_node("mesecons_delayer:delayer_off_"..tostring(i), {
minetest.swap_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2}) minetest.swap_node(pos, {name="mesecons_delayer:delayer_off_1", param2=node.param2})
end end
end, end,
on_construct = on_construct,
delayer_time = delaytime, delayer_time = delaytime,
delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i), delayer_onstate = "mesecons_delayer:delayer_on_"..tostring(i),
delayer_lockstate = "mesecons_delayer:delayer_off_locked", delayer_lockstate = "mesecons_delayer:delayer_off_locked",