New function for block registration

This commit is contained in:
JoseDouglas26 2024-06-07 09:34:47 -03:00
parent 0ce870a9de
commit b399b4913a
2 changed files with 70 additions and 36 deletions

View File

@ -19,14 +19,61 @@ end
_G.table.copy = table.copy
_G.table.merge = table.merge
function voxelibre.load_mod_files(modpath)
if not modpath then
return
end
for _, file in pairs(minetest.get_dir_list(modpath, false)) do
if file:sub(-4) == ".lua" and file ~= "init.lua" then
dofile(modpath.."/"..file)
local function set_images(mod_name, identifier, definitions)
local base_image_name = mod_name.."_"..identifier..".png"
if definitions.drawtype and definitions.drawtype:find("plantlike") then
if not definitions.inventory_image then
definitions.inventory_image = base_image_name
end
if not definitions.wield_image then
definitions.wield_image = base_image_name
end
end
end
local function set_tiles(mod_name, identifier, definitions)
local base_image_name = mod_name.."_"..identifier..".png"
if not definitions.tiles then
definitions.tiles = {base_image_name}
end
end
function voxelibre.load_mod_files(mod_path)
if not mod_path then
return
end
for _, file in pairs(minetest.get_dir_list(mod_path, false)) do
if file:sub(-4) == ".lua" and file ~= "init.lua" then
dofile(mod_path.."/"..file)
end
end
end
function voxelibre.register_block(identifier, definitions)
local mod_name = minetest.get_current_modname()
if not mod_name then
return
end
if not definitions._blast_resistance then
definitions._blast_resistance = 0
end
if not definitions._hardness then
definitions._hardness = 0
end
if not definitions.stack_max then
definitions.stack_max = 64
end
set_images(mod_name, identifier, definitions)
set_tiles(mod_name, identifier, definitions)
minetest.register_node(":blocks:"..identifier, definitions)
end

View File

@ -2,71 +2,58 @@ local S = building.translator
local commondefs = {
planks = {
_blast_resistance = 3,
_hardness = 2,
_mcl_blast_resistance = 3,
_mcl_hardness = 2,
groups = {axey = 1, building_blocks = 1, handy = 1, planks = 1},
sounds = mcl_sounds.node_sound_wood_defaults(),
stack_max = 64
sounds = mcl_sounds.node_sound_wood_defaults()
}
}
local planks = {
["acacia"] = {
description = S("Acacia Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_acacia_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["bamboo"] = {
description = S("Bamboo Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_bamboo_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["birch"] = {
description = S("Birch Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_birch_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["cherry"] = {
description = S("Cherry Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_cherry_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["crimson"] = {
description = S("Crimson Planks"),
tiles = {"building_crimson_planks.png"}
description = S("Crimson Planks")
},
["dark_oak"] = {
description = S("Dark Oak Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_dark_oak_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["jungle"] = {
description = S("Jungle Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_jungle_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["mangrove"] = {
description = S("Mangrove Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_mangrove_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["oak"] = {
description = S("Oak Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_oak_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["spruce"] = {
description = S("Spruce Planks"),
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
tiles = {"building_spruce_planks.png"}
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
},
["warped"] = {
description = S("Warped Planks"),
tiles = {"building_warped_planks.png"}
description = S("Warped Planks")
}
}
for identifier, definitions in pairs(planks) do
identifier = ":blocks:"..identifier.."_planks"
minetest.register_node(identifier, table.merge(commondefs.planks, definitions))
voxelibre.register_block(identifier.."_planks", table.merge(commondefs.planks, definitions))
end