2017-04-24 21:12:46 +02:00
|
|
|
local timegate_get_output_rules = function(node)
|
2015-08-28 12:24:33 +02:00
|
|
|
local rules = {{x = 0, y = 0, z = 1}}
|
2021-03-07 19:19:00 +01:00
|
|
|
for _ = 0, node.param2 do
|
2015-08-28 12:24:33 +02:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
2017-04-24 21:12:46 +02:00
|
|
|
local timegate_get_input_rules = function(node)
|
2015-08-28 12:24:33 +02:00
|
|
|
local rules = {{x = 0, y = 0, z = -1}}
|
2021-03-07 19:19:00 +01:00
|
|
|
for _ = 0, node.param2 do
|
2015-08-28 12:24:33 +02:00
|
|
|
rules = mesecon.rotate_rules_left(rules)
|
|
|
|
end
|
|
|
|
return rules
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Functions that are called after the delay time
|
|
|
|
|
2017-04-24 21:12:46 +02:00
|
|
|
local function timegate_activate(pos, node)
|
2015-09-04 22:08:42 +02:00
|
|
|
-- using a meta string allows writing the time in hexadecimals
|
|
|
|
local time = tonumber(minetest.get_meta(pos):get_string("time"))
|
|
|
|
if not time then
|
|
|
|
return
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
2017-04-24 21:12:46 +02:00
|
|
|
node.name = "moremesecons_timegate:timegate_on"
|
2015-09-04 22:08:42 +02:00
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
mesecon.receptor_on(pos)
|
2020-05-10 10:09:34 +02:00
|
|
|
minetest.after(time, function()
|
|
|
|
local node = minetest.get_node(pos)
|
|
|
|
if node.name == "moremesecons_timegate:timegate_on" then
|
|
|
|
mesecon.receptor_off(pos)
|
|
|
|
node.name = "moremesecons_timegate:timegate_off"
|
|
|
|
minetest.swap_node(pos, node)
|
|
|
|
end
|
|
|
|
end)
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
|
|
|
|
2021-03-08 19:34:21 +01:00
|
|
|
local boxes = {{ -6/16, -8/16, -6/16, 6/16, -7/16, 6/16 }, -- the main slab
|
2015-08-28 12:24:33 +02:00
|
|
|
|
|
|
|
{ -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 }}
|
|
|
|
|
2021-04-08 18:44:29 +02:00
|
|
|
local use_texture_alpha
|
|
|
|
if minetest.features.use_texture_alpha_string_modes then
|
|
|
|
use_texture_alpha = "opaque"
|
|
|
|
end
|
2017-04-24 21:12:46 +02:00
|
|
|
mesecon.register_node("moremesecons_timegate:timegate", {
|
|
|
|
description = "Time Gate",
|
2015-08-28 12:24:33 +02:00
|
|
|
drawtype = "nodebox",
|
2017-04-24 21:12:46 +02:00
|
|
|
inventory_image = "moremesecons_timegate_off.png",
|
|
|
|
wield_image = "moremesecons_timegate_off.png",
|
2015-08-28 12:24:33 +02:00
|
|
|
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
|
|
|
|
},
|
|
|
|
paramtype = "light",
|
|
|
|
paramtype2 = "facedir",
|
|
|
|
sunlight_propagates = true,
|
|
|
|
is_ground_content = true,
|
|
|
|
sounds = default.node_sound_stone_defaults(),
|
|
|
|
on_construct = function(pos)
|
2016-04-27 18:42:20 +02:00
|
|
|
minetest.get_meta(pos):set_string("formspec", "field[time;time;${time}]")
|
2015-08-28 12:24:33 +02:00
|
|
|
end,
|
2016-04-27 18:42:20 +02:00
|
|
|
on_receive_fields = function(pos, _, fields, player)
|
|
|
|
if fields.time
|
|
|
|
and not minetest.is_protected(pos, player:get_player_name()) then
|
2015-09-04 22:08:42 +02:00
|
|
|
minetest.get_meta(pos):set_string("time", fields.time)
|
|
|
|
end
|
2015-08-28 12:24:33 +02:00
|
|
|
end
|
|
|
|
},{
|
|
|
|
tiles = {
|
2017-04-24 21:12:46 +02:00
|
|
|
"moremesecons_timegate_off.png",
|
|
|
|
"moremesecons_timegate_bottom.png",
|
|
|
|
"moremesecons_timegate_ends_off.png",
|
|
|
|
"moremesecons_timegate_ends_off.png",
|
|
|
|
"moremesecons_timegate_sides_off.png",
|
|
|
|
"moremesecons_timegate_sides_off.png"
|
2015-08-28 12:24:33 +02:00
|
|
|
},
|
2021-04-08 18:44:29 +02:00
|
|
|
use_texture_alpha = use_texture_alpha,
|
2015-08-28 12:24:33 +02:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2},
|
|
|
|
mesecons = {
|
|
|
|
receptor =
|
|
|
|
{
|
|
|
|
state = mesecon.state.off,
|
2017-04-24 21:12:46 +02:00
|
|
|
rules = timegate_get_output_rules
|
2015-08-28 12:24:33 +02:00
|
|
|
},
|
|
|
|
effector =
|
|
|
|
{
|
2017-04-24 21:12:46 +02:00
|
|
|
rules = timegate_get_input_rules,
|
|
|
|
action_on = timegate_activate
|
2015-08-28 12:24:33 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
},{
|
|
|
|
tiles = {
|
2017-04-24 21:12:46 +02:00
|
|
|
"moremesecons_timegate_on.png",
|
|
|
|
"moremesecons_timegate_bottom.png",
|
|
|
|
"moremesecons_timegate_ends_on.png",
|
|
|
|
"moremesecons_timegate_ends_on.png",
|
|
|
|
"moremesecons_timegate_sides_on.png",
|
|
|
|
"moremesecons_timegate_sides_on.png"
|
2015-08-28 12:24:33 +02:00
|
|
|
},
|
2021-04-08 18:44:29 +02:00
|
|
|
use_texture_alpha = use_texture_alpha,
|
2015-08-28 12:24:33 +02:00
|
|
|
groups = {bendy=2,snappy=1,dig_immediate=2, not_in_creative_inventory=1},
|
2015-08-30 11:49:32 +02:00
|
|
|
mesecons = {
|
|
|
|
receptor = {
|
|
|
|
state = mesecon.state.on,
|
2017-04-24 21:12:46 +02:00
|
|
|
rules = timegate_get_output_rules
|
2015-08-30 11:49:32 +02:00
|
|
|
},
|
|
|
|
effector = {
|
2017-04-24 21:12:46 +02:00
|
|
|
rules = timegate_get_input_rules,
|
2015-08-30 11:49:32 +02:00
|
|
|
}
|
|
|
|
},
|
2015-08-28 12:24:33 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_craft({
|
2017-04-24 21:12:46 +02:00
|
|
|
output = "moremesecons_timegate:timegate_off 2",
|
2015-08-28 12:24:33 +02:00
|
|
|
recipe = {
|
2015-08-30 11:49:32 +02:00
|
|
|
{"group:mesecon_conductor_craftable", "mesecons_delayer:delayer_off_1", "group:mesecon_conductor_craftable"},
|
2015-08-28 12:24:33 +02:00
|
|
|
{"default:wood","default:wood", "default:wood"},
|
|
|
|
}
|
|
|
|
})
|
2017-04-24 21:12:46 +02:00
|
|
|
|
|
|
|
minetest.register_alias("moremesecons_temporarygate:temporarygate_off", "moremesecons_timegate:timegate_off")
|
|
|
|
minetest.register_alias("moremesecons_temporarygate:temporarygate_on", "moremesecons_timegate:timegate_on")
|