Move the trunk registration process to a separate function

This commit is contained in:
2025-12-07 12:52:35 +01:00
parent e80e7555d0
commit bacd1320fd

View File

@@ -38,41 +38,42 @@ stripped_tree.swap_node = function(pos, user, in_creative_mode, tool)
return tool return tool
end end
-- Function to register nodes -- Function to register a single strippable trunk
function stripped_tree.register_trunk(mod_name, trunk_names) function stripped_tree.register_strippable_trunk(trunk_name, stripped_tiles)
for _, name in ipairs(trunk_names) do local mod_name, trunk_node = unpack(trunk_name:split(":"))
core.register_node( local stripped_name = ":" .. mod_name .. ":stripped_" .. trunk_node
":" .. mod_name .. ":stripped_" .. name, { stripped_tiles = stripped_tiles or {
description = "Stripped " .. name, "stripped_" .. mod_name .. "_" .. trunk_node .. "_top.png",
tiles = { "stripped_" .. mod_name .. "_" .. trunk_node .. "_top.png",
"stripped_" .. mod_name .. "_" .. name .. "_top.png", "stripped_" .. mod_name .. "_" .. trunk_node .. ".png",
"stripped_" .. mod_name .. "_" .. name .. "_top.png", }
"stripped_" .. mod_name .. "_" .. name .. ".png",
},
groups = {
tree = 1,
choppy = 2,
oddly_breakable_by_hand = 1,
flammable = 2,
not_in_creative_inventory = 1,
},
sounds = default.node_sound_wood_defaults(),
paramtype2 = "facedir",
on_place = core.rotate_node,
}
)
core.register_craft( core.register_node(
{ stripped_name, {
output = mod_name .. ":" .. name, description = "Stripped " .. trunk_node,
recipe = { tiles = stripped_tiles,
{"", "default:tree_bark", ""}, groups = {tree = 1, choppy = 2, oddly_breakable_by_hand = 1, flammable = 2, not_in_creative_inventory = 1},
{"default:tree_bark", mod_name .. ":stripped_" .. name, "default:tree_bark"}, sounds = default.node_sound_wood_defaults(),
{"", "default:tree_bark", ""}, paramtype2 = "facedir",
}, on_place = core.rotate_node,
} }
) )
end
core.register_craft(
{
output = trunk_name,
recipe = {
{"", "default:tree_bark", ""},
{"default:tree_bark", stripped_name, "default:tree_bark"},
{"", "default:tree_bark", ""},
},
}
)
end
-- Compatibility function from the previous version, able to register multiple stripped tree nodes at once
function stripped_tree.register_trunk(mod_name, trunk_names)
for _, name in ipairs(trunk_names) do stripped_tree.register_strippable_trunk(mod_name .. ":" .. name) end
end end
-- Function to override axes -- Function to override axes