From 586b05da56d060567c948119b97f1e5d4f4c250f Mon Sep 17 00:00:00 2001 From: addi Date: Sun, 10 Jul 2016 10:41:34 +0200 Subject: [PATCH] Rewrite building.lua simplified registration of reinforced stuff --- building.lua | 394 +++++++++++++++++++++++---------------------------- 1 file changed, 177 insertions(+), 217 deletions(-) diff --git a/building.lua b/building.lua index 0ba2029..425595b 100644 --- a/building.lua +++ b/building.lua @@ -1,3 +1,161 @@ +--[[ + This function registers the nodes and craft rezieps for the reinforce stuff + * name: String which is used in description and as technical name (lower letters) + * craftItem: the Item where the reinforce is crafted out of + * nodedef: Nodedefinition table as used as in minetest.register_node() + + The Nodes are caled + :reinforced_ + :reinforced__slope + :reinforced__arrow + :reinforced__bars + + The modname is automatically the mod that currently calls this function. + e.g. if you call darkage.register_reinforce from the mod medieval modname will be medieval +]] +function darkage.register_reinforce(name, craftItem, nodedef) + assert(type(nodedef.tiles)=="table","ERRROR: nodedef.tiles have to be a table") + assert(nodedef.tiles[1], "ERROR: "..dump(nodedef.tiles).." requires at least 1 entry") + local modname = minetest.get_current_modname(); + local tname = name:lower(); -- Technical name + +-- Reinforced X + local reinforced = table.copy(nodedef); + local reinforced_tname = modname..":reinforced_"..tname + reinforced.description = "Reinforced "..name + for i,tile in ipairs(reinforced.tiles) do + reinforced.tiles[i] = tile .."^darkage_reinforce.png" + end + + minetest.register_node(reinforced_tname, reinforced) + + minetest.register_craft({ + output = reinforced_tname, + recipe = { + {"group:stick", craftItem, "group:stick"}, + {craftItem, "group:stick", craftItem}, + {"group:stick", craftItem, "group:stick"}, + } + }) + -- Recycling + minetest.register_craft({ + output = craftItem, + recipe = { + { reinforced_tname }, + } + }) + +-- Reinforced Slope + local slope = table.copy(nodedef); + local slope_tname = modname..":reinforced_"..tname.."_slope" + slope.description = "Reinforced "..name.." Slope\nHint: use the screwdriver to rotate." + slope.paramtype2 = "facedir"; + local slope_tile_extend = {"^darkage_reinforce_right.png" , "^darkage_reinforce_right.png" , --top ,down + "^darkage_reinforce_right.png" , "^darkage_reinforce_right.png" , --right, left + "^darkage_reinforce_left.png" , "^darkage_reinforce_left.png"} -- front, back + for i=1,6 do + local tile = slope.tiles[i] or nodedef.tiles[1]; -- There have to be at least one tile. + slope.tiles[i] = tile ..slope_tile_extend[i] + end + + minetest.register_node(slope_tname, slope) + + minetest.register_craft({ + output = slope_tname, + recipe = { + {craftItem, craftItem, "group:stick"}, + {craftItem, "group:stick", craftItem}, + {"group:stick", craftItem, craftItem}, + } + }) + -- Flipped recipe + minetest.register_craft({ + output = slope_tname, + recipe = { + {"group:stick", craftItem, craftItem}, + {craftItem, "group:stick", craftItem}, + {craftItem, craftItem, "group:stick"}, + } + }) + -- Recycling + minetest.register_craft({ + output = craftItem, + recipe = { + { slope_tname } + } + }) + + -- Alias to convert old nodes + minetest.register_alias(modname..":reinforced_"..tname.."_right", slope_tname) + minetest.register_alias(modname..":reinforced_"..tname.."_left", slope_tname) + +-- Arrow bar + local arrow = table.copy(nodedef) + local arrow_tname = modname..":reinforced_"..tname.."_arrow" + arrow.paramtype2 = "facedir"; + arrow.description = "Reinforced "..name.." Arrow \nHint: use the screwdriver to rotate." + local arrow_tile_extend = {"" , "" , --top ,down + "^(darkage_reinforce_arrow.png^[transformR90)" , "^(darkage_reinforce_arrow.png^[transformR270)" , --right, left + "^(darkage_reinforce_arrow.png^[transformR180)" , "^darkage_reinforce_arrow.png"} -- front, back + for i=1,6 do + local tile = arrow.tiles[i] or arrow.tiles[1]; -- There have to be at least one tile. + arrow.tiles[i] = tile .. arrow_tile_extend[i] + end + minetest.register_node(arrow_tname, arrow) + + minetest.register_craft({ + output = arrow_tname, + recipe = { + {craftItem, "group:stick", craftItem}, + {"group:stick", craftItem, "group:stick"}, + {"group:stick", craftItem, "group:stick"}, + } + }) + -- Recycling + minetest.register_craft({ + output = craftItem, + recipe = { + { arrow_tname } + } + }) + +-- Reinforced Bars + local bars = table.copy(nodedef) + local bars_tname = modname..":reinforced_"..tname.."_bars" + bars.description = name.." Bars" + for i,tile in ipairs(bars.tiles) do + bars.tiles[i] = tile .."^darkage_reinforce_bars.png" + end + minetest.register_node(bars_tname, bars) + + minetest.register_craft({ + output = bars_tname, + recipe = { + {"group:stick", craftItem, "group:stick"}, + {"group:stick", craftItem, "group:stick"}, + {"group:stick", craftItem, "group:stick"}, + } + }) + minetest.register_craft({ + output = craftItem, + recipe = { + { bars_tname } + } + }) +end + +darkage.register_reinforce("Chalk", "darkage:chalk_powder", { + tiles = {"darkage_chalk.png"}, + groups = {cracky=3}, + sounds = default.node_sound_stone_defaults() +}) + +darkage.register_reinforce("Wood", "default:wood", { + tiles = {"default_wood.png"}, + groups = {snappy=2, choppy=3, flammable=3}, + sounds = default.node_sound_wood_defaults() +}) + minetest.register_node("darkage:glass", { description = "Medieval Glass", drawtype = "glasslike", @@ -22,248 +180,50 @@ minetest.register_node("darkage:glow_glass", { }) minetest.register_craft({ - output = 'darkage:glow_glass 1', + output = "darkage:glow_glass 1", recipe = { - {'darkage:glass', '', ''}, - {'default:torch', '', ''}, - {'', '', ''}, + {"darkage:glass", "", ""}, + {"default:torch", "", ""}, + {"", "", ""}, } }) minetest.register_craft({ - output = 'darkage:glass 1', + output = "darkage:glass 1", recipe = { - {'darkage:glow_glass'}, - } -}) - - -minetest.register_craft({ - output = 'darkage:glass 8', - recipe = { - {'default:glass', 'default:steel_ingot', 'default:glass'}, - {'default:steel_ingot', 'default:glass', 'default:steel_ingot'}, - {'default:glass', 'default:steel_ingot', 'default:glass'}, - } -}) - -minetest.register_node("darkage:reinforced_chalk", { - description = "Reinforced Chalk", - tiles = {"darkage_chalk.png^darkage_reinforce.png"}, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults() -}) - -minetest.register_node("darkage:reinforced_chalk_right", { - description = "Reinforced Chalk", - tiles = {"darkage_chalk.png^darkage_reinforce_right.png"}, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults() -}) - -minetest.register_node("darkage:reinforced_chalk_left", { - description = "Reinforced Chalk", - tiles = {"darkage_chalk.png^darkage_reinforce_left.png"}, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults() -}) - -minetest.register_node("darkage:reinforced_chalk_arrow", { - description = "Reinforced Chalk Arrow \nHint: use the screwdriver to rotate.", - tiles = {"darkage_chalk.png" , "darkage_chalk.png" , --top ,down - "darkage_chalk.png^(darkage_reinforce_arrow.png^[transformR90)" , "darkage_chalk.png^(darkage_reinforce_arrow.png^[transformR270)" , --right, left - "darkage_chalk.png^(darkage_reinforce_arrow.png^[transformR180)" , "darkage_chalk.png^darkage_reinforce_arrow.png"}, -- front, back - paramtype2 = "facedir", - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_craft({ - output = 'darkage:reinforced_chalk_arrow 4', - recipe = { - {'darkage:chalk_powder', 'group:stick', 'darkage:chalk_powder'}, - {'group:stick', 'darkage:chalk_powder', 'group:stick'}, - {'group:stick', 'darkage:chalk_powder', 'group:stick'}, - } -}) - -minetest.register_node("darkage:reinforced_chalk_bars", { - description = "Chalk Bars", - tiles = {"darkage_chalk.png^darkage_reinforce_bars.png"}, - groups = {cracky=3}, - sounds = default.node_sound_stone_defaults(), -}) - -minetest.register_craft({ - output = 'darkage:reinforced_chalk_bars 4', - recipe = { - {'group:stick', 'darkage:chalk_powder', 'group:stick'}, - {'group:stick', 'darkage:chalk_powder', 'group:stick'}, - {'group:stick', 'darkage:chalk_powder', 'group:stick'}, - } -}) - -minetest.register_node("darkage:reinforced_wood", { - description = "Reinforced Wood", - tiles = {"default_wood.png^darkage_reinforce.png"}, - groups = {snappy=2,choppy=3,oddly_breakable_by_hand=3,flammable=3}, - sounds = default.node_sound_wood_defaults() -}) - -minetest.register_node("darkage:reinforced_wood_right", { - description = "Reinforced Wood Right", - tiles = {"default_wood.png^darkage_reinforce_right.png"}, - groups = {snappy=2,choppy=3,oddly_breakable_by_hand=3,flammable=3}, - sounds = default.node_sound_wood_defaults() -}) - -minetest.register_node("darkage:reinforced_wood_left", { - description = "Reinforced Wood Left", - tiles = {"default_wood.png^darkage_reinforce_left.png"}, - groups = {snappy=2,choppy=3,oddly_breakable_by_hand=3,flammable=3}, - sounds = default.node_sound_wood_defaults() -}) - -minetest.register_node("darkage:reinforced_wood_arrow", { - description = "Reinforced Wood Arrow \nHint: use the screwdriver to rotate.", - tiles = {"default_wood.png" , "default_wood.png" , --top ,down - "default_wood.png^(darkage_reinforce_arrow.png^[transformR90)" , "default_wood.png^(darkage_reinforce_arrow.png^[transformR270)" , --right, left - "default_wood.png^(darkage_reinforce_arrow.png^[transformR180)" , "default_wood.png^darkage_reinforce_arrow.png"}, -- front, back - paramtype2 = "facedir", - groups = {snappy=2,choppy=3,oddly_breakable_by_hand=3,flammable=3}, - sounds = default.node_sound_wood_defaults(), -}) - -minetest.register_craft({ - output = 'darkage:reinforced_wood_arrow 4', - recipe = { - {'default:wood', 'group:stick', 'default:wood'}, - {'group:stick', 'default:wood', 'group:stick'}, - {'group:stick', 'default:wood', 'group:stick'}, - } -}) - -minetest.register_node("darkage:reinforced_wood_bars", { - description = "Wooden Bars", - tiles = {"default_wood.png^darkage_reinforce_bars.png"}, - groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1}, - sounds = default.node_sound_wood_defaults(), -}) - -minetest.register_craft({ - output = 'darkage:reinforced_wood_bars 4', - recipe = { - {'group:stick', 'default:wood', 'group:stick'}, - {'group:stick', 'default:wood', 'group:stick'}, - {'group:stick', 'default:wood', 'group:stick'}, + {"darkage:glow_glass"}, } }) minetest.register_craft({ - output = 'darkage:reinforced_chalk', + output = "darkage:glass 8", recipe = { - {'group:stick','','group:stick'}, - {'','darkage:chalk',''}, - {'group:stick','','group:stick'}, + {"default:glass", "default:steel_ingot", "default:glass"}, + {"default:steel_ingot", "default:glass", "default:steel_ingot"}, + {"default:glass", "default:steel_ingot", "default:glass"}, } }) minetest.register_craft({ - output = 'darkage:reinforced_chalk_right', + output = "darkage:chalk", recipe = { - {'','','group:stick'}, - {'','darkage:chalk',''}, - {'group:stick','',''}, + {"darkage:chalk_powder","darkage:chalk_powder"}, + {"darkage:chalk_powder","darkage:chalk_powder"}, } }) minetest.register_craft({ - output = 'darkage:reinforced_chalk_left', + output = "darkage:glow_glass 1", recipe = { - {'group:stick','',''}, - {'','darkage:chalk',''}, - {'','','group:stick'}, + {"darkage:glass", "", ""}, + {"default:torch", "", ""}, + {"", "", ""}, } }) minetest.register_craft({ - output = 'darkage:chalk', + output = "darkage:glass 1", recipe = { - {'darkage:chalk_powder','darkage:chalk_powder'}, - {'darkage:chalk_powder','darkage:chalk_powder'}, - } -}) - -minetest.register_craft({ - output = 'darkage:reinforced_wood', - recipe = { - {'group:stick','','group:stick'}, - {'','default:wood',''}, - {'group:stick','','group:stick'}, - } -}) - -minetest.register_craft({ - output = 'default:wood', - recipe = { - {'darkage:reinforced_wood'}, - } -}) - -minetest.register_craft({ - output = 'darkage:reinforced_wood_left', - recipe = { - {'group:stick','',''}, - {'','default:wood',''}, - {'','','group:stick'}, - } -}) - -minetest.register_craft({ - output = 'default:wood', - recipe = { - {'darkage:reinforced_wood_left'}, - } -}) - -minetest.register_craft({ - output = 'darkage:reinforced_wood_right', - recipe = { - {'','','group:stick'}, - {'','default:wood',''}, - {'group:stick','',''}, - } -}) - -minetest.register_craft({ - output = 'default:wood', - recipe = { - {'darkage:reinforced_wood_right'}, - } -}) - -minetest.register_craft({ - output = 'darkage:glow_glass 1', - recipe = { - {'darkage:glass', '', ''}, - {'default:torch', '', ''}, - {'', '', ''}, - } -}) - -minetest.register_craft({ - output = 'darkage:glass 1', - recipe = { - {'darkage:glow_glass'}, - } -}) - - -minetest.register_craft({ - output = 'darkage:glass 8', - recipe = { - {'default:glass', 'default:steel_ingot', 'default:glass'}, - {'default:steel_ingot', 'default:glass', 'default:steel_ingot'}, - {'default:glass', 'default:steel_ingot', 'default:glass'}, + {"darkage:glow_glass"}, } })