2024-06-07 11:47:58 +02:00
|
|
|
voxelibre = {}
|
2024-06-07 15:24:26 +02:00
|
|
|
voxelibre.colors = {
|
|
|
|
"black", "blue", "brown", "cyan", "gray", "green", "light_blue", "light_gray",
|
|
|
|
"lime", "magenta", "orange", "pink", "purple", "red", "white", "yellow"
|
|
|
|
}
|
2024-06-07 11:47:58 +02:00
|
|
|
|
|
|
|
function table.merge(tbl, ...)
|
|
|
|
local new_tbl = table.copy(tbl)
|
|
|
|
|
|
|
|
for _, tbl2 in ipairs({...}) do
|
|
|
|
for key, value in pairs(tbl2) do
|
|
|
|
if type(value) == "table" and type(new_tbl[key]) == "table" then
|
|
|
|
new_tbl[key] = table.merge(new_tbl[key], value)
|
|
|
|
else
|
|
|
|
new_tbl[key] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return new_tbl
|
|
|
|
end
|
|
|
|
|
2024-06-07 13:52:09 +02:00
|
|
|
_G.table.copy = table.copy
|
2024-06-07 11:47:58 +02:00
|
|
|
_G.table.merge = table.merge
|
2024-06-07 14:07:17 +02:00
|
|
|
|
2024-06-14 16:08:54 +02:00
|
|
|
---comment
|
|
|
|
---@param string string
|
|
|
|
---@param position integer
|
|
|
|
---@param substring string
|
|
|
|
---@return string
|
2024-06-13 20:41:52 +02:00
|
|
|
function string.insert(string, position, substring)
|
|
|
|
if position < 1 or position > #string + 1 then
|
2024-06-14 16:08:54 +02:00
|
|
|
return string
|
2024-06-13 20:41:52 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local part1 = string.sub(string, 1, position - 1)
|
|
|
|
local part2 = string.sub(string, position, #string)
|
|
|
|
|
|
|
|
local new_string = part1..substring..part2
|
|
|
|
|
|
|
|
return new_string
|
|
|
|
end
|
|
|
|
|
|
|
|
_G.string.insert = string.insert
|
|
|
|
|
2024-06-07 15:50:14 +02:00
|
|
|
function voxelibre.load_mod_files()
|
|
|
|
local mod_path = minetest.get_modpath(minetest.get_current_modname())
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2024-06-07 15:24:26 +02:00
|
|
|
function voxelibre.description_from_identifier(identifier)
|
|
|
|
local description = ""
|
|
|
|
local words = {}
|
|
|
|
|
|
|
|
for word in string.gmatch(identifier, "[^_]+") do
|
|
|
|
table.insert(words, word)
|
|
|
|
end
|
|
|
|
|
|
|
|
for i, word in ipairs(words) do
|
|
|
|
if i > 1 then
|
|
|
|
description = description .. " "
|
|
|
|
end
|
|
|
|
|
|
|
|
if word == "of" or word == "the" then
|
|
|
|
description = description .. word
|
|
|
|
else
|
|
|
|
description = description .. word:gsub("^%l", string.upper)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return description
|
|
|
|
end
|
|
|
|
|
|
|
|
local function set_description(mod_name, identifier, definitions)
|
|
|
|
if not definitions.description then
|
|
|
|
definitions.description = voxelibre.description_from_identifier(identifier)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-09 16:45:52 +02:00
|
|
|
local function set_groups(definitions)
|
|
|
|
if definitions.walkable == false then
|
|
|
|
definitions.groups.solidity = 0
|
|
|
|
else
|
|
|
|
definitions.groups.solidity = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if not definitions.drawtype and not definitions.groups.opacity then
|
|
|
|
definitions.groups.opacity = 1
|
|
|
|
else
|
|
|
|
definitions.groups.opacity = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-06-12 13:49:09 +02:00
|
|
|
local function set_images(mod_name, identifier, definitions, is_item)
|
2024-06-07 14:34:47 +02:00
|
|
|
local base_image_name = mod_name.."_"..identifier..".png"
|
|
|
|
|
2024-06-12 13:49:09 +02:00
|
|
|
if (definitions.drawtype and definitions.drawtype:find("plantlike")) or is_item then
|
2024-06-07 14:34:47 +02:00
|
|
|
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}
|
2024-06-08 00:03:57 +02:00
|
|
|
else
|
|
|
|
if type(definitions.tiles) == "table" then
|
|
|
|
if definitions.tiles.type then
|
|
|
|
if definitions.tiles.type == "loglike" then
|
|
|
|
local top_base_image_name = base_image_name:gsub(".png", "_top.png")
|
|
|
|
|
|
|
|
definitions.tiles = {
|
|
|
|
top_base_image_name, top_base_image_name, base_image_name
|
|
|
|
}
|
2024-06-09 18:29:44 +02:00
|
|
|
elseif definitions.tiles.type == "modified" then
|
|
|
|
definitions.tiles = {
|
|
|
|
base_image_name..(definitions.tiles.modifiers.top or ""),
|
|
|
|
base_image_name..(definitions.tiles.modifiers.bottom or ""),
|
|
|
|
base_image_name..(definitions.tiles.modifiers.right or ""),
|
|
|
|
base_image_name..(definitions.tiles.modifiers.left or ""),
|
|
|
|
base_image_name..(definitions.tiles.modifiers.back or ""),
|
|
|
|
base_image_name..(definitions.tiles.modifiers.front or "")
|
|
|
|
}
|
2024-06-08 00:03:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
2024-06-07 14:34:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function voxelibre.register_block(identifier, definitions)
|
|
|
|
local mod_name = minetest.get_current_modname()
|
|
|
|
|
|
|
|
if not mod_name then
|
|
|
|
return
|
|
|
|
end
|
2024-06-07 15:24:26 +02:00
|
|
|
|
2024-06-07 14:34:47 +02:00
|
|
|
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
|
|
|
|
|
2024-06-07 15:24:26 +02:00
|
|
|
set_description(mod_name, identifier, definitions)
|
2024-06-09 16:45:52 +02:00
|
|
|
set_groups(definitions)
|
2024-06-12 13:49:09 +02:00
|
|
|
set_images(mod_name, identifier, definitions, false)
|
2024-06-07 14:34:47 +02:00
|
|
|
set_tiles(mod_name, identifier, definitions)
|
|
|
|
|
|
|
|
minetest.register_node(":blocks:"..identifier, definitions)
|
|
|
|
end
|
2024-06-12 13:49:09 +02:00
|
|
|
|
|
|
|
function voxelibre.register_item(identifier, definitions)
|
|
|
|
local mod_name = minetest.get_current_modname()
|
|
|
|
|
|
|
|
if not mod_name then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if not definitions.stack_max then
|
|
|
|
definitions.stack_max = 64
|
|
|
|
end
|
|
|
|
|
|
|
|
set_description(mod_name, identifier, definitions)
|
|
|
|
set_images(mod_name, identifier, definitions, true)
|
|
|
|
|
|
|
|
minetest.register_craftitem(":items:"..identifier, definitions)
|
|
|
|
end
|