Refactor button registration

This commit is contained in:
Wuzzy 2017-11-22 22:24:05 +01:00
parent 6efddc833c
commit a2fefb264b
1 changed files with 85 additions and 127 deletions

View File

@ -82,12 +82,18 @@ local on_button_place = function(itemstack, placer, pointed_thing)
end end
local buttonuse = "Rightclick the button to push it." local buttonuse = "Rightclick the button to push it."
minetest.register_node("mesecons_button:button_stone_off", {
mesecon.register_button = function(basename, description, texture, recipeitem, sounds, plusgroups, button_timer, longdesc)
local groups_off = {handy=1,pickaxey=1, attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1}
local groups_on = table.copy(groups_off)
groups_on.not_in_creative_inventory=1
minetest.register_node("mesecons_button:button_"..basename.."_off", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"default_stone.png"}, tiles = {texture},
wield_image = "mesecons_button_wield_mask.png^default_stone.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", wield_image = "mesecons_button_wield_mask.png^"..texture.."^mesecons_button_wield_mask.png^[makealpha:255,126,126",
-- FIXME: Use proper 3D inventory image -- FIXME: Use proper 3D inventory image
inventory_image = "mesecons_button_wield_mask.png^default_stone.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", inventory_image = "mesecons_button_wield_mask.png^"..texture.."^mesecons_button_wield_mask.png^[makealpha:255,126,126",
wield_scale = { x=1, y=1, z=1}, wield_scale = { x=1, y=1, z=1},
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
@ -95,32 +101,32 @@ minetest.register_node("mesecons_button:button_stone_off", {
walkable = false, walkable = false,
sunlight_propagates = true, sunlight_propagates = true,
node_box = boxes_off, node_box = boxes_off,
groups = {handy=1,pickaxey=1, attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1}, groups = groups_off,
description = "Stone Button", description = description,
_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).", _doc_items_longdesc = longdesc,
_doc_items_usagehelp = buttonuse, _doc_items_usagehelp = buttonuse,
on_place = on_button_place, on_place = on_button_place,
node_placement_prediction = "", node_placement_prediction = "",
on_rightclick = function (pos, node) on_rightclick = function (pos, node)
minetest.swap_node(pos, {name="mesecons_button:button_stone_on", param2=node.param2}) minetest.swap_node(pos, {name="mesecons_button:button_"..basename.."_on", param2=node.param2})
mesecon.receptor_on(pos, button_get_output_rules(node)) mesecon.receptor_on(pos, button_get_output_rules(node))
minetest.sound_play("mesecons_button_push", {pos=pos}) minetest.sound_play("mesecons_button_push", {pos=pos})
minetest.after(1, mesecon.button_turnoff, pos) minetest.after(button_timer, mesecon.button_turnoff, pos)
end, end,
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = sounds,
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.off, state = mesecon.state.off,
rules = button_get_output_rules, rules = button_get_output_rules,
}}, }},
_mcl_blast_resistance = 2.5, _mcl_blast_resistance = 2.5,
_mcl_hardness = 0.5, _mcl_hardness = 0.5,
}) })
minetest.register_node("mesecons_button:button_stone_on", { minetest.register_node("mesecons_button:button_"..basename.."_on", {
drawtype = "nodebox", drawtype = "nodebox",
tiles = {"default_stone.png"}, tiles = {texture},
wield_image = "mesecons_button_wield_mask.png^default_stone.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", wield_image = "mesecons_button_wield_mask.png^"..texture.."^mesecons_button_wield_mask.png^[makealpha:255,126,126",
inventory_image = "mesecons_button_wield_mask.png^default_stone.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", inventory_image = "mesecons_button_wield_mask.png^"..texture.."^mesecons_button_wield_mask.png^[makealpha:255,126,126",
wield_scale = { x=1, y=1, z=0.5}, wield_scale = { x=1, y=1, z=0.5},
paramtype = "light", paramtype = "light",
paramtype2 = "wallmounted", paramtype2 = "wallmounted",
@ -128,92 +134,44 @@ minetest.register_node("mesecons_button:button_stone_on", {
walkable = false, walkable = false,
sunlight_propagates = true, sunlight_propagates = true,
node_box = boxes_on, node_box = boxes_on,
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}, groups = groups_on,
drop = 'mesecons_button:button_stone_off', drop = 'mesecons_button:button_'..basename..'_off',
description = "Stone Button",
_doc_items_create_entry = false, _doc_items_create_entry = false,
node_placement_prediction = "", node_placement_prediction = "",
sounds = mcl_sounds.node_sound_stone_defaults(), sounds = sounds,
mesecons = {receptor = { mesecons = {receptor = {
state = mesecon.state.on, state = mesecon.state.on,
rules = button_get_output_rules rules = button_get_output_rules
}}, }},
_mcl_blast_resistance = 2.5, _mcl_blast_resistance = 2.5,
_mcl_hardness = 0.5, _mcl_hardness = 0.5,
}) })
minetest.register_node("mesecons_button:button_wood_off", { minetest.register_craft({
drawtype = "nodebox", output = "mesecons_button:button_"..basename.."_off",
tiles = {"default_wood.png"}, recipe = {{ recipeitem }},
wield_image = "mesecons_button_wield_mask.png^default_wood.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", })
inventory_image = "mesecons_button_wield_mask.png^default_wood.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", end
wield_scale = { x=1, y=1, z=1},
paramtype = "light",
paramtype2 = "wallmounted",
is_ground_content = false,
walkable = false,
sunlight_propagates = true,
node_box = boxes_off,
groups = {handy=1,axey=1, attached_node=1, dig_by_water=1,destroy_by_lava_flow=1, dig_by_piston=1},
description = "Wooden Button",
_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).",
_doc_items_usagehelp = buttonuse,
on_place = on_button_place,
node_placement_prediction = "",
on_rightclick = function (pos, node)
minetest.swap_node(pos, {name="mesecons_button:button_wood_on", param2=node.param2})
mesecon.receptor_on(pos, button_get_output_rules(node))
minetest.sound_play("mesecons_button_push", {pos=pos})
minetest.after(1.5, mesecon.button_turnoff, pos)
end,
sounds = mcl_sounds.node_sound_wood_defaults(),
mesecons = {receptor = {
state = mesecon.state.off,
rules = button_get_output_rules,
}},
_mcl_blast_resistance = 2.5,
_mcl_hardness = 0.5,
})
minetest.register_node("mesecons_button:button_wood_on", { mesecon.register_button(
drawtype = "nodebox", "stone",
tiles = {"default_wood.png"}, "Stone Button",
wield_image = "mesecons_button_wield_mask.png^default_wood.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", "default_stone.png",
inventory_image = "mesecons_button_wield_mask.png^default_wood.png^mesecons_button_wield_mask.png^[makealpha:255,126,126", "mcl_core:stone",
wield_scale = { x=1, y=1, z=0.5}, mcl_sounds.node_sound_stone_defaults(),
paramtype = "light", {material_stone=1,handy=1,pickaxey=1},
paramtype2 = "wallmounted", 1,
is_ground_content = false, "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).")
walkable = false,
sunlight_propagates = true,
node_box = boxes_on,
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},
drop = 'mesecons_button:button_wood_off',
description = "Wooden Button",
_doc_items_create_entry = false,
node_placement_prediction = "",
sounds = mcl_sounds.node_sound_wood_defaults(),
mesecons = {receptor = {
state = mesecon.state.on,
rules = button_get_output_rules,
}},
_mcl_blast_resistance = 2.5,
_mcl_hardness = 0.5,
})
minetest.register_craft({ mesecon.register_button(
output = 'mesecons_button:button_stone_off', "wood",
recipe = { "Oak Wood Button",
{'mcl_core:stone'}, "default_wood.png",
} "mcl_core:wood",
}) mcl_sounds.node_sound_wood_defaults(),
{material_wood=1,handy=1,axey=1},
minetest.register_craft({ 1.5,
output = 'mesecons_button:button_wood_off', "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).")
recipe = {
{'group:wood'},
}
})
minetest.register_craft({ minetest.register_craft({
type = "fuel", type = "fuel",