Skip to content

Commit

Permalink
opt-depend on default
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay committed Jan 29, 2024
1 parent f17f5fd commit 0d0eeb4
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 184 deletions.
60 changes: 60 additions & 0 deletions api.lua
Original file line number Diff line number Diff line change
@@ -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
135 changes: 135 additions & 0 deletions default.lua
Original file line number Diff line number Diff line change
@@ -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()
)
189 changes: 6 additions & 183 deletions init.lua
Original file line number Diff line number Diff line change
@@ -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()
)
if minetest.get_modpath("default") then
-- register default slats
dofile(MP .. "/default.lua")
end
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name = slats
description = Adds decorative slats that have a lot of uses
depends = default
optional_depends = default
Loading

0 comments on commit 0d0eeb4

Please sign in to comment.