mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-07-01 23:50:40 +02:00
functional, except saw, legacy, other compatability
This commit is contained in:
@ -4,10 +4,16 @@
|
||||
]]
|
||||
local api = stairsplus.api
|
||||
|
||||
local table_set_all = stairsplus.util.table_set_all
|
||||
local table_sort_keys = stairsplus.util.table_sort_keys
|
||||
|
||||
local S = stairsplus.S
|
||||
|
||||
local legacy_mode = stairsplus.settings.legacy_mode
|
||||
local in_creative_inventory = stairsplus.settings.in_creative_inventory
|
||||
|
||||
local S = stairsplus.S
|
||||
api.nodes_by_shape = {}
|
||||
api.shapes_by_node = {}
|
||||
|
||||
local function scale_light(light_source, shape_def)
|
||||
if not light_source or light_source == 0 then
|
||||
@ -19,14 +25,19 @@ local function scale_light(light_source, shape_def)
|
||||
return math.max(1, math.min(math.round(light_source * shape_def.eighths / 4), light_source))
|
||||
end
|
||||
|
||||
function api.register_single(node, shape, overrides)
|
||||
function api.format_name(shape, node)
|
||||
local mod, name = node:match("^([^:]+):(.*)$")
|
||||
local shape_def = api.registered_shapes[shape]
|
||||
return ("%s:%s"):format(mod, shape_def.name_format:format(name))
|
||||
end
|
||||
|
||||
function api.register_single(node, shape, overrides)
|
||||
local node_def = table.copy(minetest.registered_nodes[node])
|
||||
local shape_def = api.registered_shapes[shape]
|
||||
|
||||
local groups = {
|
||||
[shape] = 1,
|
||||
not_in_creative_inventory = in_creative_inventory,
|
||||
not_in_creative_inventory = in_creative_inventory and 1 or 0,
|
||||
}
|
||||
|
||||
for group, value in pairs(node_def.groups) do
|
||||
@ -47,6 +58,13 @@ function api.register_single(node, shape, overrides)
|
||||
light_source = scale_light(node_def.light_source, shape_def),
|
||||
}
|
||||
|
||||
local tiles = node_def.tiles
|
||||
if #tiles > 1 and (node_def.drawtype or ""):match("glass") then
|
||||
def.tiles = {tiles[1]}
|
||||
else
|
||||
def.tiles = tiles
|
||||
end
|
||||
|
||||
if node_def.short_description then
|
||||
def.short_description = S(shape_def.description, node_def.short_description)
|
||||
end
|
||||
@ -62,39 +80,72 @@ function api.register_single(node, shape, overrides)
|
||||
end
|
||||
end
|
||||
|
||||
for k, v in pairs(overrides or {}) do
|
||||
def[k] = v
|
||||
end
|
||||
table_set_all(def, overrides or {})
|
||||
|
||||
minetest.register_node((":%s:%s"):format(mod, shape_def.name_format:format(name)), def)
|
||||
local shaped_name = api.format_name(shape, node)
|
||||
minetest.register_node(":" .. shaped_name, def)
|
||||
|
||||
if shape_def.aliases then
|
||||
local mod, name = node:match("^([^:]+):(.*)$")
|
||||
for _, alias in ipairs(shape_def.aliases) do
|
||||
minetest.register_alias(
|
||||
("%s:%s"):format(mod, alias:format(name)),
|
||||
("%s:%s"):format(mod, shape_def.name_format:format(name))
|
||||
shaped_name
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
local nodes = api.nodes_by_shape[shape] or {}
|
||||
nodes[node] = true
|
||||
api.nodes_by_shape[shape] = nodes
|
||||
|
||||
local shapes = api.shapes_by_node[node] or {}
|
||||
shapes[shape] = true
|
||||
api.shapes_by_node[node] = shapes
|
||||
end
|
||||
|
||||
function api.register_all(node, overrides)
|
||||
for shape in pairs(api.registered_shapes) do
|
||||
api.register_single(node, shape, overrides)
|
||||
end
|
||||
api.register_schema_crafts_for_node(node)
|
||||
end
|
||||
|
||||
function api.register_custom(node, list, overrides)
|
||||
for _, shape in ipairs(list) do
|
||||
api.register_single(node, shape, overrides)
|
||||
end
|
||||
api.register_schema_crafts_for_node(node)
|
||||
end
|
||||
|
||||
function api.register_group(node, group, overrides)
|
||||
for _, shape in ipairs(api.shapes_by_group[group] or {}) do
|
||||
api.register_single(node, shape, overrides)
|
||||
end
|
||||
api.register_schema_crafts_for_node(node)
|
||||
end
|
||||
|
||||
function api.get_shapes(node)
|
||||
return table_sort_keys(api.shapes_by_node[node])
|
||||
end
|
||||
|
||||
function api.get_shapes_hash(node)
|
||||
return api.shapes_by_node[node]
|
||||
end
|
||||
|
||||
function api.get_shaped_name(node, shape_or_item)
|
||||
local t = ItemStack(shape_or_item):to_table()
|
||||
|
||||
if api.registered_shapes[t.name] then
|
||||
t.name = api.format_name(t.name, node)
|
||||
|
||||
elseif t.name == "node" then
|
||||
t.name = node
|
||||
end
|
||||
|
||||
return ItemStack(t):to_string()
|
||||
end
|
||||
|
||||
minetest.register_on_mods_loaded(function()
|
||||
stairsplus.log("info", "registering schema crafts")
|
||||
for node in pairs(api.shapes_by_node) do
|
||||
api.register_schema_crafts_for_node(node)
|
||||
end
|
||||
end)
|
||||
|
Reference in New Issue
Block a user