forked from VoxeLibre/VoxeLibre
New function for block registration
This commit is contained in:
parent
0ce870a9de
commit
b399b4913a
|
@ -19,14 +19,61 @@ end
|
||||||
_G.table.copy = table.copy
|
_G.table.copy = table.copy
|
||||||
_G.table.merge = table.merge
|
_G.table.merge = table.merge
|
||||||
|
|
||||||
function voxelibre.load_mod_files(modpath)
|
local function set_images(mod_name, identifier, definitions)
|
||||||
if not modpath then
|
local base_image_name = mod_name.."_"..identifier..".png"
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
for _, file in pairs(minetest.get_dir_list(modpath, false)) do
|
if definitions.drawtype and definitions.drawtype:find("plantlike") then
|
||||||
if file:sub(-4) == ".lua" and file ~= "init.lua" then
|
if not definitions.inventory_image then
|
||||||
dofile(modpath.."/"..file)
|
definitions.inventory_image = base_image_name
|
||||||
|
end
|
||||||
|
|
||||||
|
if not definitions.wield_image then
|
||||||
|
definitions.wield_image = base_image_name
|
||||||
end
|
end
|
||||||
end
|
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
|
||||||
|
|
|
@ -2,71 +2,58 @@ local S = building.translator
|
||||||
|
|
||||||
local commondefs = {
|
local commondefs = {
|
||||||
planks = {
|
planks = {
|
||||||
_blast_resistance = 3,
|
_mcl_blast_resistance = 3,
|
||||||
_hardness = 2,
|
_mcl_hardness = 2,
|
||||||
groups = {axey = 1, building_blocks = 1, handy = 1, planks = 1},
|
groups = {axey = 1, building_blocks = 1, handy = 1, planks = 1},
|
||||||
sounds = mcl_sounds.node_sound_wood_defaults(),
|
sounds = mcl_sounds.node_sound_wood_defaults()
|
||||||
stack_max = 64
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local planks = {
|
local planks = {
|
||||||
["acacia"] = {
|
["acacia"] = {
|
||||||
description = S("Acacia Planks"),
|
description = S("Acacia Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_acacia_planks.png"}
|
|
||||||
},
|
},
|
||||||
["bamboo"] = {
|
["bamboo"] = {
|
||||||
description = S("Bamboo Planks"),
|
description = S("Bamboo Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_bamboo_planks.png"}
|
|
||||||
},
|
},
|
||||||
["birch"] = {
|
["birch"] = {
|
||||||
description = S("Birch Planks"),
|
description = S("Birch Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_birch_planks.png"}
|
|
||||||
},
|
},
|
||||||
["cherry"] = {
|
["cherry"] = {
|
||||||
description = S("Cherry Planks"),
|
description = S("Cherry Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_cherry_planks.png"}
|
|
||||||
},
|
},
|
||||||
["crimson"] = {
|
["crimson"] = {
|
||||||
description = S("Crimson Planks"),
|
description = S("Crimson Planks")
|
||||||
tiles = {"building_crimson_planks.png"}
|
|
||||||
},
|
},
|
||||||
["dark_oak"] = {
|
["dark_oak"] = {
|
||||||
description = S("Dark Oak Planks"),
|
description = S("Dark Oak Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_dark_oak_planks.png"}
|
|
||||||
},
|
},
|
||||||
["jungle"] = {
|
["jungle"] = {
|
||||||
description = S("Jungle Planks"),
|
description = S("Jungle Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_jungle_planks.png"}
|
|
||||||
},
|
},
|
||||||
["mangrove"] = {
|
["mangrove"] = {
|
||||||
description = S("Mangrove Planks"),
|
description = S("Mangrove Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_mangrove_planks.png"}
|
|
||||||
},
|
},
|
||||||
["oak"] = {
|
["oak"] = {
|
||||||
description = S("Oak Planks"),
|
description = S("Oak Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_oak_planks.png"}
|
|
||||||
},
|
},
|
||||||
["spruce"] = {
|
["spruce"] = {
|
||||||
description = S("Spruce Planks"),
|
description = S("Spruce Planks"),
|
||||||
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15},
|
groups = {fire_encouragement = 20, fire_flammability = 5, fuel = 15}
|
||||||
tiles = {"building_spruce_planks.png"}
|
|
||||||
},
|
},
|
||||||
["warped"] = {
|
["warped"] = {
|
||||||
description = S("Warped Planks"),
|
description = S("Warped Planks")
|
||||||
tiles = {"building_warped_planks.png"}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for identifier, definitions in pairs(planks) do
|
for identifier, definitions in pairs(planks) do
|
||||||
identifier = ":blocks:"..identifier.."_planks"
|
voxelibre.register_block(identifier.."_planks", table.merge(commondefs.planks, definitions))
|
||||||
minetest.register_node(identifier, table.merge(commondefs.planks, definitions))
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue