MoreMesecons/moremesecons_dual_delayer/init.lua

101 lines
3.2 KiB
Lua
Raw Normal View History

local function dual_delayer_get_input_rules(node)
local rules = {{x=1, y=0, z=0}}
2021-03-07 19:19:00 +01:00
for _ = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local function dual_delayer_get_output_rules(node)
local rules = {{x=0, y=0, z=1}, {x=0, y=0, z=-1}}
2021-03-07 19:19:00 +01:00
for _ = 0, node.param2 do
rules = mesecon.rotate_rules_left(rules)
end
return rules
end
local dual_delayer_activate = function(pos, node)
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn on the port 1
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
minetest.after(0.4, function()
mesecon.receptor_on(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn on the port 2
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_11", param2 = node.param2})
end)
end
local dual_delayer_deactivate = function(pos, node, link)
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[2]}) -- Turn off the port 2
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_10", param2 = node.param2})
minetest.after(0.4, function()
mesecon.receptor_off(pos, {dual_delayer_get_output_rules(node)[1]}) -- Turn off the port 1
minetest.swap_node(pos, {name = "moremesecons_dual_delayer:dual_delayer_00", param2 = node.param2})
end)
end
2015-09-02 20:02:09 +02:00
for n,i in pairs({{0,0},{1,0},{1,1}}) do
local i1,i2 = unpack(i)
2015-09-02 20:02:09 +02:00
local groups = {dig_immediate = 2}
if n ~= 1 then
groups.not_in_creative_inventory = 1
end
local top_texture = "^moremesecons_dual_delayer_overlay.png^[makealpha:255,126,126"
if i1 == i2 then
if i1 == 0 then
top_texture = "mesecons_wire_off.png"..top_texture
else
top_texture = "mesecons_wire_on.png"..top_texture
end
else
local pre = "mesecons_wire_off.png^[lowpart:50:mesecons_wire_on.png^[transformR"
if i1 == 0 then
pre = pre.. 90
else
pre = pre.. 270
end
top_texture = pre..top_texture
end
local use_texture_alpha
if minetest.features.use_texture_alpha_string_modes then
use_texture_alpha = "opaque"
end
2015-09-02 20:02:09 +02:00
minetest.register_node("moremesecons_dual_delayer:dual_delayer_"..i1 ..i2, {
description = "Dual Delayer",
drop = "moremesecons_dual_delayer:dual_delayer_00",
inventory_image = top_texture,
wield_image = top_texture,
paramtype = "light",
paramtype2 = "facedir",
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = {{-6/16, -8/16, -8/16, 6/16, -7/16, 1/16 },
2015-09-02 20:02:09 +02:00
{-8/16, -8/16, 1/16, -6/16, -7/16, -1/16},
{8/16, -8/16, -1/16, 6/16, -7/16, 1/16}}
},
2015-09-02 20:02:09 +02:00
groups = groups,
tiles = {top_texture, "moremesecons_dual_delayer_bottom.png", "moremesecons_dual_delayer_side_left.png", "moremesecons_dual_delayer_side_right.png", "moremesecons_dual_delayer_ends.png", "moremesecons_dual_delayer_ends.png"},
use_texture_alpha = use_texture_alpha,
2015-09-02 20:02:09 +02:00
mesecons = {
receptor = {
state = mesecon.state.off,
rules = dual_delayer_get_output_rules
},
effector = {
rules = dual_delayer_get_input_rules,
action_on = dual_delayer_activate,
action_off = dual_delayer_deactivate
}
}
2015-09-02 20:02:09 +02:00
})
end
minetest.register_craft({
type = "shapeless",
output = "moremesecons_dual_delayer:dual_delayer_00 2",
2015-08-30 11:49:32 +02:00
recipe = {"mesecons_delayer:delayer_off_1", "mesecons_delayer:delayer_off_1"}
})