diff --git a/api.lua b/api.lua new file mode 100644 index 0000000..0f9bbc1 --- /dev/null +++ b/api.lua @@ -0,0 +1,60 @@ + +local has_default_mod = minetest.get_modpath("default") + +-- main crafting ingredient for the slat recipe +local base_recipe_ingredient +if has_default_mod then + base_recipe_ingredient = "default:paper" +end + +function slats.register_slat(subname, recipeitem, groups, image, description, sounds) + groups.slab = 1 + + -- nodebox limits + local nb1 = 0.5 + local nb2 = 0.49 + + minetest.register_node(":slats:slat_" .. subname, { + description = description, + drawtype = "nodebox", + tiles = {image}, + inventory_image = image, + wield_image = image, + paramtype = "light", + paramtype2 = "wallmounted", + is_ground_content = false, + sunlight_propagates = true, + groups = groups, + sounds = sounds, + node_box = { + type = "wallmounted", + wall_top = {-nb1, nb2, -nb1, nb1, nb2, nb1}, + wall_bottom = {-nb1, -nb2, -nb1, nb1, -nb2, nb1}, + wall_side = {-nb2, -nb1, -nb1, -nb2, nb1, nb1}, + }, + }) + + if recipeitem then + if base_recipe_ingredient then + minetest.register_craft({ + type = "shapeless", + output = 'slats:slat_' .. subname .. ' 12', + recipe = {recipeitem, base_recipe_ingredient}, + }) + end + + -- Fuel + local baseburntime = minetest.get_craft_result({ + method = "fuel", + width = 1, + items = {recipeitem} + }).time + if baseburntime > 0 then + minetest.register_craft({ + type = "fuel", + recipe = 'slats:slat_' .. subname, + burntime = math.floor(baseburntime * 0.5), + }) + end + end +end diff --git a/default.lua b/default.lua new file mode 100644 index 0000000..1d7c66e --- /dev/null +++ b/default.lua @@ -0,0 +1,135 @@ + +slats.register_slat( + "stone_block", + "default:stone_block", + {cracky = 2}, + "default_stone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Stone Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "desert_stone_block", + "default:desert_stone_block", + {cracky = 2}, + "default_desert_stone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Desert Stone Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "sandstone_block", + "default:sandstone_block", + {cracky = 2}, + "default_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Sandstone Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "desert_sandstone_block", + "default:desert_sandstone_block", + {cracky = 2}, + "default_desert_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Desert Sandstone Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "silver_sandstone_block", + "default:silver_sandstone_block", + {cracky = 2}, + "default_silver_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Silver Sandstone Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "obsidian_block", + "default:obsidian_block", + {cracky = 1, level = 2}, + "default_obsidian_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Obsidian Block Slat", + default.node_sound_stone_defaults() +) + +slats.register_slat( + "steelblock", + "default:steelblock", + {cracky = 1, level = 2}, + "default_steel_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Steel Block Slat", + default.node_sound_metal_defaults() +) + +slats.register_slat( + "copperblock", + "default:copperblock", + {cracky = 1, level = 2}, + "default_copper_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Copper Block Slat", + default.node_sound_metal_defaults() +) + +slats.register_slat( + "bronzeblock", + "default:bronzeblock", + {cracky = 1, level = 2}, + "default_bronze_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Bronze Block Slat", + default.node_sound_metal_defaults() +) + +slats.register_slat( + "goldblock", + "default:goldblock", + {cracky = 1}, + "default_gold_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Gold Block Slat", + default.node_sound_metal_defaults() +) + +slats.register_slat( + "wood", + "default:wood", + {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, + "default_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Wooden Slat", + default.node_sound_wood_defaults() +) + +slats.register_slat( + "junglewood", + "default:junglewood", + {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, + "default_junglewood.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Jungle Wood Slat", + default.node_sound_wood_defaults() +) + +slats.register_slat( + "pine_wood", + "default:pine_wood", + {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}, + "default_pine_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Pine Wood Slat", + default.node_sound_wood_defaults() +) + +slats.register_slat( + "acacia_wood", + "default:acacia_wood", + {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, + "default_acacia_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Acacia Wood Slat", + default.node_sound_wood_defaults() +) + +slats.register_slat( + "aspen_wood", + "default:aspen_wood", + {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}, + "default_aspen_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Aspen Wood Slat", + default.node_sound_wood_defaults() +) \ No newline at end of file diff --git a/init.lua b/init.lua index 2fe7019..a5ffd85 100644 --- a/init.lua +++ b/init.lua @@ -1,186 +1,9 @@ slats = {} -function slats.register_slat(subname, recipeitem, groups, image, description, sounds) - groups.slab = 1 +local MP = minetest.get_modpath("slats") +dofile(MP .. "/api.lua") - -- nodebox limits - local nb1 = 0.5 - local nb2 = 0.49 - - minetest.register_node(":slats:slat_" .. subname, { - description = description, - drawtype = "nodebox", - tiles = {image}, - inventory_image = image, - wield_image = image, - paramtype = "light", - paramtype2 = "wallmounted", - is_ground_content = false, - sunlight_propagates = true, - groups = groups, - sounds = sounds, - node_box = { - type = "wallmounted", - wall_top = {-nb1, nb2, -nb1, nb1, nb2, nb1}, - wall_bottom = {-nb1, -nb2, -nb1, nb1, -nb2, nb1}, - wall_side = {-nb2, -nb1, -nb1, -nb2, nb1, nb1}, - }, - }) - - if recipeitem then - minetest.register_craft({ - type = "shapeless", - output = 'slats:slat_' .. subname .. ' 12', - recipe = {recipeitem, "default:paper"}, - }) - - -- Fuel - local baseburntime = minetest.get_craft_result({ - method = "fuel", - width = 1, - items = {recipeitem} - }).time - if baseburntime > 0 then - minetest.register_craft({ - type = "fuel", - recipe = 'slats:slat_' .. subname, - burntime = math.floor(baseburntime * 0.5), - }) - end - end -end - -slats.register_slat( - "stone_block", - "default:stone_block", - {cracky = 2}, - "default_stone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Stone Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "desert_stone_block", - "default:desert_stone_block", - {cracky = 2}, - "default_desert_stone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Desert Stone Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "sandstone_block", - "default:sandstone_block", - {cracky = 2}, - "default_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Sandstone Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "desert_sandstone_block", - "default:desert_sandstone_block", - {cracky = 2}, - "default_desert_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Desert Sandstone Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "silver_sandstone_block", - "default:silver_sandstone_block", - {cracky = 2}, - "default_silver_sandstone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Silver Sandstone Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "obsidian_block", - "default:obsidian_block", - {cracky = 1, level = 2}, - "default_obsidian_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Obsidian Block Slat", - default.node_sound_stone_defaults() -) - -slats.register_slat( - "steelblock", - "default:steelblock", - {cracky = 1, level = 2}, - "default_steel_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Steel Block Slat", - default.node_sound_metal_defaults() -) - -slats.register_slat( - "copperblock", - "default:copperblock", - {cracky = 1, level = 2}, - "default_copper_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Copper Block Slat", - default.node_sound_metal_defaults() -) - -slats.register_slat( - "bronzeblock", - "default:bronzeblock", - {cracky = 1, level = 2}, - "default_bronze_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Bronze Block Slat", - default.node_sound_metal_defaults() -) - -slats.register_slat( - "goldblock", - "default:goldblock", - {cracky = 1}, - "default_gold_block.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Gold Block Slat", - default.node_sound_metal_defaults() -) - -slats.register_slat( - "wood", - "default:wood", - {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, - "default_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Wooden Slat", - default.node_sound_wood_defaults() -) - -slats.register_slat( - "junglewood", - "default:junglewood", - {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, - "default_junglewood.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Jungle Wood Slat", - default.node_sound_wood_defaults() -) - -slats.register_slat( - "pine_wood", - "default:pine_wood", - {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}, - "default_pine_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Pine Wood Slat", - default.node_sound_wood_defaults() -) - -slats.register_slat( - "acacia_wood", - "default:acacia_wood", - {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2}, - "default_acacia_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Acacia Wood Slat", - default.node_sound_wood_defaults() -) - -slats.register_slat( - "aspen_wood", - "default:aspen_wood", - {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3}, - "default_aspen_wood.png^slats_slat_overlay.png^[makealpha:255,126,126", - "Aspen Wood Slat", - default.node_sound_wood_defaults() -) \ No newline at end of file +if minetest.get_modpath("default") then + -- register default slats + dofile(MP .. "/default.lua") +end \ No newline at end of file diff --git a/mod.conf b/mod.conf index 2e099ff..77cffaa 100644 --- a/mod.conf +++ b/mod.conf @@ -1,3 +1,3 @@ name = slats description = Adds decorative slats that have a lot of uses -depends = default \ No newline at end of file +optional_depends = default \ No newline at end of file diff --git a/readme.md b/readme.md index acdcf81..2950350 100644 --- a/readme.md +++ b/readme.md @@ -12,6 +12,24 @@ Adds decorative slats that have a lot of uses ![](./screenshot.png) +# Api + +Modding api + +## slats.register_slat(subname, recipeitem, groups, image, description, sounds) + +Example: stone block registration from the `default` mod: +```lua +slats.register_slat( + "stone_block", + "default:stone_block", -- optional, can be nil + {cracky = 2}, -- optional, can be nil + "default_stone_block.png^slats_slat_overlay.png^[makealpha:255,126,126", + "Stone Block Slat", -- optional + default.node_sound_stone_defaults() -- optional +) +``` + # License * Code: `MIT`