2015-06-29 17:55:56 +00:00
-- WALL BUTTON
-- A button that when pressed emits power for 1 second
-- and then turns off again
2017-09-14 00:20:47 +00:00
-- FIXME: Power node behind as well
2017-03-27 23:52:09 +00:00
local button_get_output_rules = function ( node )
2017-09-14 00:20:47 +00:00
local rules = mesecon.rules . alldirs
2017-03-27 23:52:09 +00:00
return rules
end
2015-06-29 17:55:56 +00:00
mesecon.button_turnoff = function ( pos )
2017-01-11 17:21:46 +00:00
local node = minetest.get_node ( pos )
2015-06-29 17:55:56 +00:00
if node.name == " mesecons_button:button_stone_on " then --has not been dug
2017-07-30 22:12:21 +00:00
minetest.swap_node ( pos , { name = " mesecons_button:button_stone_off " , param2 = node.param2 } )
2015-06-29 17:55:56 +00:00
minetest.sound_play ( " mesecons_button_pop " , { pos = pos } )
2017-07-30 22:12:21 +00:00
mesecon.receptor_off ( pos , button_get_output_rules ( node ) )
2015-06-29 17:55:56 +00:00
elseif node.name == " mesecons_button:button_wood_on " then --has not been dug
2017-07-30 22:12:21 +00:00
minetest.swap_node ( pos , { name = " mesecons_button:button_wood_off " , param2 = node.param2 } )
2015-06-29 17:55:56 +00:00
minetest.sound_play ( " mesecons_button_pop " , { pos = pos } )
2017-07-30 22:12:21 +00:00
mesecon.receptor_off ( pos , button_get_output_rules ( node ) )
2015-06-29 17:55:56 +00:00
end
end
2017-03-27 23:22:01 +00:00
local boxes_off = {
type = " wallmounted " ,
wall_side = { - 8 / 16 , - 2 / 16 , - 4 / 16 , - 6 / 16 , 2 / 16 , 4 / 16 } ,
wall_bottom = { - 4 / 16 , - 8 / 16 , - 2 / 16 , 4 / 16 , - 6 / 16 , 2 / 16 } ,
wall_top = { - 4 / 16 , 6 / 16 , - 2 / 16 , 4 / 16 , 8 / 16 , 2 / 16 } ,
}
local boxes_on = {
type = " wallmounted " ,
wall_side = { - 8 / 16 , - 2 / 16 , - 4 / 16 , - 7 / 16 , 2 / 16 , 4 / 16 } ,
wall_bottom = { - 4 / 16 , - 8 / 16 , - 2 / 16 , 4 / 16 , - 7 / 16 , 2 / 16 } ,
wall_top = { - 4 / 16 , 7 / 16 , - 2 / 16 , 4 / 16 , 8 / 16 , 2 / 16 } ,
}
2015-06-29 17:55:56 +00:00
2017-05-27 16:09:11 +00:00
local on_button_place = function ( itemstack , placer , pointed_thing )
if pointed_thing.type ~= " node " then
-- no interaction possible with entities
return itemstack
end
local under = pointed_thing.under
local node = minetest.get_node ( under )
local def = minetest.registered_nodes [ node.name ]
2017-06-29 11:02:53 +00:00
if not def then return end
2017-05-27 16:09:11 +00:00
local groups = def.groups
-- Check special rightclick action of pointed node
if def and def.on_rightclick then
if not placer : get_player_control ( ) . sneak then
return def.on_rightclick ( under , node , placer , itemstack ,
pointed_thing ) or itemstack , false
end
end
2017-05-27 16:18:54 +00:00
-- If the pointed node is buildable, let's look at the node *behind* that node
if def.buildable_to then
local dir = vector.subtract ( pointed_thing.above , pointed_thing.under )
local actual = vector.subtract ( under , dir )
local actualnode = minetest.get_node ( actual )
def = minetest.registered_nodes [ actualnode.name ]
groups = def.groups
end
2017-05-27 16:09:11 +00:00
-- Only allow placement on full-cube solid opaque nodes
if ( not groups ) or ( not groups.solid ) or ( not groups.opaque ) or ( def.node_box and def.node_box . type ~= " regular " ) then
return itemstack
end
local above = pointed_thing.above
local idef = itemstack : get_definition ( )
2017-05-27 16:28:30 +00:00
local itemstack , success = minetest.item_place_node ( itemstack , placer , pointed_thing )
2017-05-27 16:09:11 +00:00
if success then
if idef.sounds and idef.sounds . place then
2017-05-27 16:28:30 +00:00
--minetest.sound_play(idef.sounds.place, {pos=above, gain=1})
2017-05-27 16:09:11 +00:00
end
end
return itemstack
end
2017-05-27 16:28:30 +00:00
local buttonuse = " Rightclick the button to push it. "
2015-06-29 17:55:56 +00:00
minetest.register_node ( " mesecons_button:button_stone_off " , {
drawtype = " nodebox " ,
tiles = { " default_stone.png " } ,
2017-03-02 15:58:32 +00:00
wield_image = " default_stone.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-27 23:31:58 +00:00
-- FIXME: Use proper 3D inventory image
inventory_image = " default_stone.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-02 15:58:32 +00:00
wield_scale = { x = 1 , y = 1 , z = 1 } ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
2017-03-27 23:22:01 +00:00
paramtype2 = " wallmounted " ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
walkable = false ,
sunlight_propagates = true ,
2017-03-27 23:22:01 +00:00
node_box = boxes_off ,
2017-05-20 02:11:14 +00:00
groups = { handy = 1 , pickaxey = 1 , attached_node = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 } ,
2015-06-29 17:55:56 +00:00
description = " Stone Button " ,
2017-05-27 16:28:30 +00:00
_doc_items_longdesc = " A stone button is a redstone component made out of stone which can be pushed to provide redstone power. When pushed, it powers adjacent redstone components for 1 second. It can only be placed on solid opaque full cubes (like cobblestone). " ,
2017-03-11 02:38:08 +00:00
_doc_items_usagehelp = buttonuse ,
2017-05-27 16:09:11 +00:00
on_place = on_button_place ,
2017-05-27 16:28:30 +00:00
node_placement_prediction = " " ,
2017-02-05 16:57:33 +00:00
on_rightclick = function ( pos , node )
2017-07-30 22:12:21 +00:00
minetest.swap_node ( pos , { name = " mesecons_button:button_stone_on " , param2 = node.param2 } )
mesecon.receptor_on ( pos , button_get_output_rules ( node ) )
2015-06-29 17:55:56 +00:00
minetest.sound_play ( " mesecons_button_push " , { pos = pos } )
minetest.after ( 1 , mesecon.button_turnoff , pos )
end ,
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 ,
2017-03-27 23:52:09 +00:00
rules = button_get_output_rules ,
2017-02-22 15:22:28 +00:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 00:52:24 +00:00
_mcl_hardness = 0.5 ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_node ( " mesecons_button:button_stone_on " , {
drawtype = " nodebox " ,
tiles = { " default_stone.png " } ,
2017-03-02 15:58:32 +00:00
wield_image = " default_stone.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-27 23:31:58 +00:00
inventory_image = " default_stone.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-02 15:58:32 +00:00
wield_scale = { x = 1 , y = 1 , z = 0.5 } ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
2017-03-27 23:22:01 +00:00
paramtype2 = " wallmounted " ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
walkable = false ,
sunlight_propagates = true ,
2017-03-27 23:22:01 +00:00
node_box = boxes_on ,
2017-05-20 02:11:14 +00:00
groups = { handy = 1 , pickaxey = 1 , not_in_creative_inventory = 1 , attached_node = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 } ,
2015-06-29 17:55:56 +00:00
drop = ' mesecons_button:button_stone_off ' ,
description = " Stone Button " ,
2017-03-02 18:53:53 +00:00
_doc_items_create_entry = false ,
2017-05-27 16:28:30 +00:00
node_placement_prediction = " " ,
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 . on ,
2017-03-27 23:52:09 +00:00
rules = button_get_output_rules
2017-02-22 15:22:28 +00:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 00:52:24 +00:00
_mcl_hardness = 0.5 ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_node ( " mesecons_button:button_wood_off " , {
drawtype = " nodebox " ,
tiles = { " default_wood.png " } ,
2017-03-02 15:58:32 +00:00
wield_image = " default_wood.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-27 23:31:58 +00:00
inventory_image = " default_wood.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-02 15:58:32 +00:00
wield_scale = { x = 1 , y = 1 , z = 1 } ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
2017-03-27 23:22:01 +00:00
paramtype2 = " wallmounted " ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
walkable = false ,
sunlight_propagates = true ,
2017-03-27 23:22:01 +00:00
node_box = boxes_off ,
2017-05-20 02:11:14 +00:00
groups = { handy = 1 , axey = 1 , attached_node = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 } ,
2017-01-11 23:27:26 +00:00
description = " Wooden Button " ,
2017-05-27 16:28:30 +00:00
_doc_items_longdesc = " A wooden button is a redstone component made out of wood which can be pushed to provide redstone power. When pushed, it powers adjacent redstone components for 1.5 seconds. It can only be placed on solid opaque full cubes (like cobblestone). " ,
2017-03-11 02:38:08 +00:00
_doc_items_usagehelp = buttonuse ,
2017-05-27 16:09:11 +00:00
on_place = on_button_place ,
2017-05-27 16:28:30 +00:00
node_placement_prediction = " " ,
2017-01-11 23:30:28 +00:00
on_rightclick = function ( pos , node )
2017-07-30 22:12:21 +00:00
minetest.swap_node ( pos , { name = " mesecons_button:button_wood_on " , param2 = node.param2 } )
mesecon.receptor_on ( pos , button_get_output_rules ( node ) )
2015-06-29 17:55:56 +00:00
minetest.sound_play ( " mesecons_button_push " , { pos = pos } )
2017-03-27 23:28:52 +00:00
minetest.after ( 1.5 , mesecon.button_turnoff , pos )
2015-06-29 17:55:56 +00:00
end ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2015-06-29 17:55:56 +00:00
mesecons = { receptor = {
state = mesecon.state . off ,
2017-03-27 23:52:09 +00:00
rules = button_get_output_rules ,
2017-02-22 15:22:28 +00:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 00:52:24 +00:00
_mcl_hardness = 0.5 ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_node ( " mesecons_button:button_wood_on " , {
drawtype = " nodebox " ,
tiles = { " default_wood.png " } ,
2017-03-02 15:58:32 +00:00
wield_image = " default_wood.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-27 23:31:58 +00:00
inventory_image = " default_wood.png^[mask:mesecons_button_wield_mask.png " ,
2017-03-02 15:58:32 +00:00
wield_scale = { x = 1 , y = 1 , z = 0.5 } ,
2015-06-29 17:55:56 +00:00
paramtype = " light " ,
2017-03-27 23:22:01 +00:00
paramtype2 = " wallmounted " ,
2017-01-04 21:36:51 +00:00
is_ground_content = false ,
2015-06-29 17:55:56 +00:00
walkable = false ,
sunlight_propagates = true ,
2017-03-27 23:22:01 +00:00
node_box = boxes_on ,
2017-05-20 02:11:14 +00:00
groups = { handy = 1 , axey = 1 , not_in_creative_inventory = 1 , attached_node = 1 , dig_by_water = 1 , destroy_by_lava_flow = 1 , dig_by_piston = 1 } ,
2015-06-29 17:55:56 +00:00
drop = ' mesecons_button:button_wood_off ' ,
2017-01-11 23:27:26 +00:00
description = " Wooden Button " ,
2017-03-02 18:53:53 +00:00
_doc_items_create_entry = false ,
2017-05-27 16:28:30 +00:00
node_placement_prediction = " " ,
2017-02-11 17:46:23 +00:00
sounds = mcl_sounds.node_sound_wood_defaults ( ) ,
2015-06-29 17:55:56 +00:00
mesecons = { receptor = {
state = mesecon.state . on ,
2017-03-27 23:52:09 +00:00
rules = button_get_output_rules ,
2017-02-22 15:22:28 +00:00
} } ,
_mcl_blast_resistance = 2.5 ,
2017-02-27 00:52:24 +00:00
_mcl_hardness = 0.5 ,
2015-06-29 17:55:56 +00:00
} )
minetest.register_craft ( {
output = ' mesecons_button:button_stone_off ' ,
recipe = {
2017-01-31 22:32:56 +00:00
{ ' mcl_core:stone ' } ,
2015-06-29 17:55:56 +00:00
}
} )
minetest.register_craft ( {
output = ' mesecons_button:button_wood_off ' ,
recipe = {
{ ' group:wood ' } ,
}
} )
2017-01-10 05:43:07 +00:00
minetest.register_craft ( {
type = " fuel " ,
recipe = ' mesecons_button:button_wood_off ' ,
burntime = 5 ,
} )
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_button:button_wood_off " , " nodes " , " mesecons_button:button_wood_on " )
doc.add_entry_alias ( " nodes " , " mesecons_button:button_stone_off " , " nodes " , " mesecons_button:button_stone_on " )
end