forked from minetest-mods/MoreMesecons
185 lines
6.0 KiB
Lua
185 lines
6.0 KiB
Lua
--MOREMESECONS TEMPORARYGATE
|
|
--file copy on mesecons delayer
|
|
|
|
-- Function that get the input/output rules of the temporarygate
|
|
local temporarygate_get_output_rules = function(node)
|
|
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 temporarygate_get_input_rules = function(node)
|
|
local rules = {{x = 0, y = 0, z = -1}}
|
|
for i = 0, node.param2 do
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
end
|
|
return rules
|
|
end
|
|
|
|
-- Functions that are called after the delay time
|
|
|
|
local temporarygate_activate = function(pos, node)
|
|
local timer = minetest.get_node_timer(pos)
|
|
print(node)
|
|
local def = minetest.registered_nodes[node.name]
|
|
local time = def.temporarygate_time
|
|
local meta = minetest.get_meta(pos)
|
|
if timer:is_started() then
|
|
timer:stop()
|
|
--On...
|
|
minetest.swap_node(pos, {name = def.temporarygate_onstate, param2=node.param2})
|
|
mesecon.receptor_on(pos, temporarygate_get_output_rules(node))
|
|
--...And off.
|
|
mesecon.receptor_off(pos, temporarygate_get_output_rules(node))
|
|
minetest.swap_node(pos, {name = def.temporarygate_offstate, param2=node.param2})
|
|
else
|
|
timer:start(time)
|
|
end
|
|
end
|
|
|
|
-- Register the 2 (states) x 4 (delay times) temporarygates
|
|
|
|
for i = 1, 4 do
|
|
local groups = {}
|
|
if i == 1 then
|
|
groups = {bendy=2,snappy=1,dig_immediate=2}
|
|
else
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1}
|
|
end
|
|
|
|
local delaytime
|
|
delaytime = i
|
|
|
|
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
|
|
{ -3/16, -7/16, -3/16, 3/16, -26/64, -2/16 },
|
|
{ -4/16, -7/16, -2/16, 4/16, -26/64, 2/16 },
|
|
{ -3/16, -7/16, 2/16, 3/16, -26/64, 3/16 },
|
|
{ -2/16, -7/16, 3/16, 2/16, -26/64, 4/16 },
|
|
|
|
{ -6/16, -7/16, -6/16, -4/16, -27/64, -4/16 }, -- the timer indicator
|
|
{ -8/16, -8/16, -1/16, -6/16, -7/16, 1/16 }, -- the two wire stubs
|
|
{ 6/16, -8/16, -1/16, 8/16, -7/16, 1/16 }}
|
|
|
|
minetest.register_node("moremesecons_temporarygate:temporarygate_off_"..tostring(i), {
|
|
description = "temporarygate",
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
"mesecons_temporarygate_off_"..tostring(i)..".png",
|
|
"mesecons_temporarygate_bottom.png",
|
|
"mesecons_temporarygate_ends_off.png",
|
|
"mesecons_temporarygate_ends_off.png",
|
|
"mesecons_temporarygate_sides_off.png",
|
|
"mesecons_temporarygate_sides_off.png"
|
|
},
|
|
inventory_image = "mesecons_temporarygate_off_1.png",
|
|
wield_image = "mesecons_temporarygate_off_1.png",
|
|
walkable = true,
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = boxes
|
|
},
|
|
groups = groups,
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
sunlight_propagates = true,
|
|
is_ground_content = true,
|
|
drop = 'moremesecons_temporarygate:temporarygate_off_1',
|
|
on_punch = function (pos, node)
|
|
if node.name=="moremesecons_temporarygate:temporarygate_off_1" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_off_2", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_off_2" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_off_3", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_off_3" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_off_4", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_off_4" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_off_1", param2=node.param2})
|
|
end
|
|
end,
|
|
temporarygate_time = delaytime,
|
|
temporarygate_onstate = "moremesecons_temporarygate:temporarygate_on_"..tostring(i),
|
|
sounds = default.node_sound_stone_defaults(),
|
|
mesecons = {
|
|
receptor =
|
|
{
|
|
state = mesecon.state.off,
|
|
rules = temporarygate_get_output_rules
|
|
},
|
|
effector =
|
|
{
|
|
rules = temporarygate_get_input_rules,
|
|
action_on = temporarygate_activate
|
|
}
|
|
},
|
|
on_timer = temporarygate_activate
|
|
})
|
|
|
|
|
|
minetest.register_node("moremesecons_temporarygate:temporarygate_on_"..tostring(i), {
|
|
description = "MoreMesecons TemporaryGate",
|
|
drawtype = "nodebox",
|
|
tiles = {
|
|
"mesecons_temporarygate_on_"..tostring(i)..".png",
|
|
"mesecons_temporarygate_bottom.png",
|
|
"mesecons_temporarygate_ends_on.png",
|
|
"mesecons_temporarygate_ends_on.png",
|
|
"mesecons_temporarygate_sides_on.png",
|
|
"mesecons_temporarygate_sides_on.png"
|
|
},
|
|
walkable = true,
|
|
selection_box = {
|
|
type = "fixed",
|
|
fixed = { -8/16, -8/16, -8/16, 8/16, -6/16, 8/16 },
|
|
},
|
|
node_box = {
|
|
type = "fixed",
|
|
fixed = boxes
|
|
},
|
|
groups = {bendy = 2, snappy = 1, dig_immediate = 2, not_in_creative_inventory = 1},
|
|
paramtype = "light",
|
|
paramtype2 = "facedir",
|
|
sunlight_propagates = true,
|
|
is_ground_content = true,
|
|
drop = 'moremesecons_temporarygate:temporarygate_off_1',
|
|
on_punch = function (pos, node)
|
|
if node.name=="moremesecons_temporarygate:temporarygate_on_1" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_on_2", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_on_2" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_on_3", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_on_3" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_on_4", param2=node.param2})
|
|
elseif node.name=="moremesecons_temporarygate:temporarygate_on_4" then
|
|
minetest.swap_node(pos, {name = "moremesecons_temporarygate:temporarygate_on_1", param2=node.param2})
|
|
end
|
|
end,
|
|
temporarygate_time = delaytime,
|
|
temporarygate_offstate = "moremesecons_temporarygate:temporarygate_off_"..tostring(i),
|
|
mesecons = {
|
|
receptor =
|
|
{
|
|
state = mesecon.state.on,
|
|
rules = temporarygate_get_output_rules
|
|
},
|
|
effector =
|
|
{
|
|
rules = temporarygate_get_input_rules,
|
|
}
|
|
}
|
|
})
|
|
end
|
|
|
|
minetest.register_craft({
|
|
output = "moremesecons_temporarygate:temporarygate_off_1",
|
|
recipe = {
|
|
{"mesecons_torch:mesecon_torch_on", "group:mesecon_conductor_craftable", "mesecons_torch:mesecon_torch_on"},
|
|
{"default:wood","default:wood", "default:wood"},
|
|
}
|
|
})
|