2015-06-29 17:55:56 +00:00
-- Function that get the input/output rules of the delayer
local delayer_get_output_rules = function ( node )
2017-03-11 23:09:55 +00:00
local rules = { { x = - 1 , y = 0 , z = 0 } }
2015-06-29 17:55:56 +00:00
for i = 0 , node.param2 do
rules = mesecon : rotate_rules_left ( rules )
end
return rules
end
local delayer_get_input_rules = function ( node )
2017-03-11 23:09:55 +00:00
local rules = { { x = 1 , y = 0 , z = 0 } }
2015-06-29 17:55:56 +00:00
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 delayer_turnon = function ( params )
local rules = delayer_get_output_rules ( params.node )
mesecon : receptor_on ( params.pos , rules )
end
local delayer_turnoff = function ( params )
local rules = delayer_get_output_rules ( params.node )
mesecon : receptor_off ( params.pos , rules )
end
local delayer_activate = function ( pos , node )
local def = minetest.registered_nodes [ node.name ]
local time = def.delayer_time
mesecon : swap_node ( pos , def.delayer_onstate )
minetest.after ( time , delayer_turnon , { pos = pos , node = node } )
end
local delayer_deactivate = function ( pos , node )
local def = minetest.registered_nodes [ node.name ]
local time = def.delayer_time
mesecon : swap_node ( pos , def.delayer_offstate )
minetest.after ( time , delayer_turnoff , { pos = pos , node = node } )
end
-- Register the 2 (states) x 4 (delay times) delayers
for i = 1 , 4 do
local groups = { }
if i == 1 then
2017-03-11 22:36:38 +00:00
groups = { dig_immediate = 3 , dig_by_water = 1 , attached_node = 1 }
2015-06-29 17:55:56 +00:00
else
2017-03-11 22:36:38 +00:00
groups = { dig_immediate = 3 , dig_by_water = 1 , attached_node = 1 , not_in_creative_inventory = 1 }
2015-06-29 17:55:56 +00:00
end
local delaytime
2017-03-11 22:29:46 +00:00
if i == 1 then delaytime = 0.1
elseif i == 2 then delaytime = 0.2
elseif i == 3 then delaytime = 0.3
elseif i == 4 then delaytime = 0.4
2015-06-29 17:55:56 +00:00
end
local boxes
if i == 1 then
boxes = {
{ - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } , -- the main slab
2017-03-11 23:09:55 +00:00
{ - 1 / 16 , - 6 / 16 , 6 / 16 , 1 / 16 , - 1 / 16 , 4 / 16 } , -- still torch
{ - 1 / 16 , - 6 / 16 , 0 / 16 , 1 / 16 , - 1 / 16 , 2 / 16 } , -- moved torch
2015-06-29 17:55:56 +00:00
}
elseif i == 2 then
boxes = {
{ - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } , -- the main slab
2017-03-11 23:09:55 +00:00
{ - 1 / 16 , - 6 / 16 , 6 / 16 , 1 / 16 , - 1 / 16 , 4 / 16 } , -- still torch
{ - 1 / 16 , - 6 / 16 , - 2 / 16 , 1 / 16 , - 1 / 16 , 0 / 16 } , -- moved torch
2015-06-29 17:55:56 +00:00
}
elseif i == 3 then
boxes = {
{ - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } , -- the main slab
2017-03-11 23:09:55 +00:00
{ - 1 / 16 , - 6 / 16 , 6 / 16 , 1 / 16 , - 1 / 16 , 4 / 16 } , -- still torch
{ - 1 / 16 , - 6 / 16 , - 4 / 16 , 1 / 16 , - 1 / 16 , - 2 / 16 } , -- moved torch
2015-06-29 17:55:56 +00:00
}
elseif i == 4 then
boxes = {
{ - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } , -- the main slab
2017-03-11 23:09:55 +00:00
{ - 1 / 16 , - 6 / 16 , 6 / 16 , 1 / 16 , - 1 / 16 , 4 / 16 } , -- still torch
{ - 1 / 16 , - 6 / 16 , - 6 / 16 , 1 / 16 , - 1 / 16 , - 4 / 16 } , -- moved torch
2015-06-29 17:55:56 +00:00
}
end
2017-03-11 23:17:10 +00:00
local help , longdesc , usagehelp , icon
if i == 1 then
help = true
2017-03-11 22:28:22 +00:00
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. "
2017-03-11 23:17:10 +00:00
icon = " mesecons_delayer_item.png "
else
help = false
2017-03-11 22:28:22 +00:00
end
2015-06-29 17:55:56 +00:00
minetest.register_node ( " mesecons_delayer:delayer_off_ " .. tostring ( i ) , {
2017-01-04 05:20:13 +00:00
description = " Redstone Repeater " ,
2017-03-11 23:17:10 +00:00
inventory_image = icon ,
wield_image = icon ,
2017-03-11 22:28:22 +00:00
_doc_items_create_entry = help ,
_doc_items_longdesc = longdesc ,
_doc_items_usagehelp = usagehelp ,
2015-06-29 17:55:56 +00:00
drawtype = " nodebox " ,
tiles = {
" mesecons_delayer_off.png " ,
2017-03-11 23:09:55 +00:00
" stairs_stone_slab_top.png " ,
" mesecons_delayer_sides_off.png " ,
" mesecons_delayer_sides_off.png " ,
2015-06-29 17:55:56 +00:00
" mesecons_delayer_ends_off.png " ,
" mesecons_delayer_ends_off.png " ,
} ,
wield_image = " mesecons_delayer_off.png " ,
walkable = true ,
selection_box = {
type = " fixed " ,
fixed = { - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } ,
} ,
2017-03-11 22:38:15 +00:00
collision_box = {
type = " fixed " ,
fixed = { - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } ,
} ,
2015-06-29 17:55:56 +00:00
node_box = {
type = " fixed " ,
fixed = boxes
} ,
groups = groups ,
paramtype = " light " ,
paramtype2 = " facedir " ,
2017-03-11 23:54:16 +00:00
sunlight_propagates = false ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
drop = ' mesecons_delayer:delayer_off_1 ' ,
2017-02-05 16:57:33 +00:00
on_rightclick = function ( pos , node )
2015-06-29 17:55:56 +00:00
if node.name == " mesecons_delayer:delayer_off_1 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_off_2 " )
elseif node.name == " mesecons_delayer:delayer_off_2 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_off_3 " )
elseif node.name == " mesecons_delayer:delayer_off_3 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_off_4 " )
elseif node.name == " mesecons_delayer:delayer_off_4 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_off_1 " )
end
end ,
delayer_time = delaytime ,
delayer_onstate = " mesecons_delayer:delayer_on_ " .. tostring ( i ) ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_stone_defaults ( ) ,
2015-06-29 17:55:56 +00:00
mesecons = {
receptor =
{
state = mesecon.state . off ,
rules = delayer_get_output_rules
} ,
effector =
{
rules = delayer_get_input_rules ,
action_on = delayer_activate
}
}
} )
minetest.register_node ( " mesecons_delayer:delayer_on_ " .. tostring ( i ) , {
2017-03-11 23:09:55 +00:00
description = " Redstone Repeater (Powered) " ,
2017-03-02 18:53:53 +00:00
_doc_items_create_entry = false ,
2015-06-29 17:55:56 +00:00
drawtype = " nodebox " ,
tiles = {
" mesecons_delayer_on.png " ,
2017-03-11 23:09:55 +00:00
" stairs_stone_slab_top.png " ,
" mesecons_delayer_sides_on.png " ,
" mesecons_delayer_sides_on.png " ,
2015-06-29 17:55:56 +00:00
" mesecons_delayer_ends_on.png " ,
" mesecons_delayer_ends_on.png " ,
} ,
walkable = true ,
selection_box = {
type = " fixed " ,
fixed = { - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } ,
} ,
2017-03-11 22:38:15 +00:00
collision_box = {
type = " fixed " ,
fixed = { - 8 / 16 , - 8 / 16 , - 8 / 16 , 8 / 16 , - 6 / 16 , 8 / 16 } ,
} ,
2015-06-29 17:55:56 +00:00
node_box = {
type = " fixed " ,
fixed = boxes
} ,
2017-03-11 22:36:38 +00:00
groups = { dig_immediate = 3 , dig_by_water = 1 , attached_node = 1 , not_in_creative_inventory = 1 } ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
paramtype2 = " facedir " ,
2017-03-11 23:54:16 +00:00
sunlight_propagates = false ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
drop = ' mesecons_delayer:delayer_off_1 ' ,
2017-02-05 16:57:33 +00:00
on_rightclick = function ( pos , node )
2015-06-29 17:55:56 +00:00
if node.name == " mesecons_delayer:delayer_on_1 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_on_2 " )
elseif node.name == " mesecons_delayer:delayer_on_2 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_on_3 " )
elseif node.name == " mesecons_delayer:delayer_on_3 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_on_4 " )
elseif node.name == " mesecons_delayer:delayer_on_4 " then
mesecon : swap_node ( pos , " mesecons_delayer:delayer_on_1 " )
end
end ,
delayer_time = delaytime ,
delayer_offstate = " mesecons_delayer:delayer_off_ " .. tostring ( i ) ,
mesecons = {
receptor =
{
state = mesecon.state . on ,
rules = delayer_get_output_rules
} ,
effector =
{
rules = delayer_get_input_rules ,
action_off = delayer_deactivate
}
}
} )
end
minetest.register_craft ( {
output = " mesecons_delayer:delayer_off_1 " ,
recipe = {
2017-02-08 00:44:07 +00:00
{ " mesecons_torch:mesecon_torch_on " , " mesecons:redstone " , " mesecons_torch:mesecon_torch_on " } ,
2017-01-31 22:32:56 +00:00
{ " mcl_core:stone " , " mcl_core:stone " , " mcl_core:stone " } ,
2015-06-29 17:55:56 +00:00
}
} )
2017-03-21 03:27:50 +00:00
-- Add entry aliases for the Help
if minetest.get_modpath ( " doc " ) then
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_off_2 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_off_3 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_off_4 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_on_1 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_on_2 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_on_3 " )
doc.add_entry_alias ( " nodes " , " mesecons_delayer:delayer_off_1 " , " nodes " , " mesecons_delayer:delayer_on_4 " )
end