mirror of
https://github.com/minetest-mods/moreblocks.git
synced 2025-07-02 08:00:44 +02:00
fix some bugs, starting to track down all the compatability issues
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
local api = stairsplus.api
|
||||
|
||||
local in_creative_inventory = stairsplus.settings.in_creative_inventory
|
||||
|
||||
api.passthrough_groups = {}
|
||||
api.scale_groups = {}
|
||||
api.ignore_groups = {}
|
||||
@ -33,3 +35,28 @@ function api.register_ignore_groups(groups)
|
||||
api.register_ignore_group(group)
|
||||
end
|
||||
end
|
||||
|
||||
function api.build_groups(node, shape)
|
||||
local node_def = minetest.registered_nodes[node]
|
||||
|
||||
local groups = {
|
||||
[("shape_%s"):format(shape)] = 1,
|
||||
not_in_creative_inventory = in_creative_inventory and 1 or 0,
|
||||
}
|
||||
|
||||
local shape_def = api.registered_shapes[shape]
|
||||
|
||||
for group, value in pairs(node_def.groups) do
|
||||
if api.passthrough_groups[group] then
|
||||
groups[group] = value
|
||||
|
||||
elseif api.scale_groups[group] then
|
||||
groups[group] = (shape_def.eighths / 8) * value
|
||||
|
||||
elseif not api.ignore_groups[group] then
|
||||
groups[shape_def.name_format:format(group)] = value
|
||||
end
|
||||
end
|
||||
|
||||
return groups
|
||||
end
|
@ -1,7 +1,7 @@
|
||||
stairsplus.api = {}
|
||||
|
||||
stairsplus.dofile("api", "shape")
|
||||
stairsplus.dofile("api", "groups")
|
||||
stairsplus.dofile("api", "group_filters")
|
||||
stairsplus.dofile("api", "node")
|
||||
stairsplus.dofile("api", "alias")
|
||||
stairsplus.dofile("api", "recipe")
|
||||
|
@ -11,7 +11,6 @@ local S = stairsplus.S
|
||||
|
||||
local legacy_mode = stairsplus.settings.legacy_mode
|
||||
local legacy_place_mechanic = stairsplus.settings.legacy_place_mechanic
|
||||
local in_creative_inventory = stairsplus.settings.in_creative_inventory
|
||||
local default_align_style = stairsplus.settings.default_align_style
|
||||
|
||||
api.nodes_by_shape = {}
|
||||
@ -59,7 +58,6 @@ local function check_node_validity(node_def, meta)
|
||||
paramtype2 == "degrotate" or
|
||||
paramtype2 == "meshoptions" or
|
||||
paramtype2 == "color" or
|
||||
paramtype2 == "colorfacedir" or
|
||||
paramtype2 == "colorwallmounted" or
|
||||
paramtype2 == "glasslikeliquidlevel" or
|
||||
paramtype2 == "colordegrotate"
|
||||
@ -68,29 +66,6 @@ local function check_node_validity(node_def, meta)
|
||||
end
|
||||
end
|
||||
|
||||
local function build_groups(shape, node_groups)
|
||||
local groups = {
|
||||
[("shape_%s"):format(shape)] = 1,
|
||||
not_in_creative_inventory = in_creative_inventory and 1 or 0,
|
||||
}
|
||||
|
||||
local shape_def = api.registered_shapes[shape]
|
||||
|
||||
for group, value in pairs(node_groups) do
|
||||
if api.passthrough_groups[group] then
|
||||
groups[group] = value
|
||||
|
||||
elseif api.scale_groups[group] then
|
||||
groups[group] = (shape_def.eighths / 8) * value
|
||||
|
||||
elseif not api.ignore_groups[group] then
|
||||
groups[shape_def.name_format:format(group)] = value
|
||||
end
|
||||
end
|
||||
|
||||
return groups
|
||||
end
|
||||
|
||||
local wall_right_dirmap = {9, 18, 7, 12}
|
||||
local wall_left_dirmap = {11, 16, 5, 14}
|
||||
local ceil_dirmap = {20, 23, 22, 21}
|
||||
@ -190,6 +165,9 @@ function api.register_single(node, shape, overrides, meta)
|
||||
stairsplus.log("info", "registering %s %s", shape, node)
|
||||
meta = meta or {}
|
||||
overrides = overrides or {}
|
||||
if not minetest.registered_nodes[node] then
|
||||
error(("%q is not defined"):format(node))
|
||||
end
|
||||
local node_def = table.copy(minetest.registered_nodes[node])
|
||||
check_node_validity(node_def, meta)
|
||||
|
||||
@ -204,6 +182,13 @@ function api.register_single(node, shape, overrides, meta)
|
||||
|
||||
local shape_def = api.registered_shapes[shape]
|
||||
|
||||
local paramtype2
|
||||
if node_def.paramtype2 == "colorfacedir" then
|
||||
paramtype2 = "colorfacedir"
|
||||
else
|
||||
paramtype2 = shape_def.paramtype2 or "facedir"
|
||||
end
|
||||
|
||||
-- shaped_node definition
|
||||
local def = {
|
||||
description = S(shape_def.description, node_def.description or node),
|
||||
@ -214,15 +199,16 @@ function api.register_single(node, shape, overrides, meta)
|
||||
collision_box = shape_def.collision_box,
|
||||
selection_box = shape_def.selection_box,
|
||||
paramtype = shape_def.paramtype or "light",
|
||||
paramtype2 = shape_def.paramtype2 or "facedir",
|
||||
paramtype2 = paramtype2,
|
||||
|
||||
light_source = scale_light(node_def.light_source, shape_def),
|
||||
groups = build_groups(shape, node_def.groups),
|
||||
groups = api.build_groups(node, shape),
|
||||
|
||||
tiles = node_def.tiles,
|
||||
overlay_tiles = node_def.overlay_tiles,
|
||||
use_texture_alpha = node_def.use_texture_alpha,
|
||||
color = node_def.color,
|
||||
palette = node_def.palette, -- for coloredfacedir
|
||||
stack_max = node_def.stack_max,
|
||||
sound = node_def.sound,
|
||||
is_ground_content = node_def.is_ground_content,
|
||||
@ -249,7 +235,7 @@ function api.register_single(node, shape, overrides, meta)
|
||||
end
|
||||
|
||||
-- if there's a drop defined, and we can drop a shaped version, do so
|
||||
if node_def.drop then
|
||||
if node_def.drop and type(node_def.drop) == "string" then
|
||||
local item = api.get_shaped_node(node_def.drop, shape)
|
||||
if item then
|
||||
def.drop = item
|
||||
@ -260,6 +246,7 @@ function api.register_single(node, shape, overrides, meta)
|
||||
def.on_place = api.legacy_on_place
|
||||
end
|
||||
|
||||
overrides.groups = nil
|
||||
table_set_all(def, overrides)
|
||||
|
||||
-- set backface_culling and align_style
|
||||
@ -353,13 +340,14 @@ function api.get_shapes_hash(node)
|
||||
end
|
||||
|
||||
function api.get_shaped_node(node, shape_or_item)
|
||||
local name, count = shape_or_item:match("^([^ ]+) (%d+)")
|
||||
if not name then
|
||||
name = shape_or_item
|
||||
if shape_or_item == "" then
|
||||
return ""
|
||||
end
|
||||
|
||||
if name == "" then
|
||||
return ""
|
||||
local name, count = shape_or_item:match("^([^ ]+) (%d+)")
|
||||
|
||||
if not name then
|
||||
name = shape_or_item
|
||||
end
|
||||
|
||||
count = tonumber(count)
|
||||
@ -396,8 +384,6 @@ end
|
||||
minetest.register_on_mods_loaded(function()
|
||||
stairsplus.log("info", "registering schema crafts")
|
||||
for node, shapes in pairs(api.shapes_by_node) do
|
||||
api.register_schema_crafts_for_node(node)
|
||||
|
||||
for shape in pairs(shapes) do
|
||||
local shaped_node = api.format_name(node, shape)
|
||||
api.node_by_shaped_node[shaped_node] = node
|
||||
@ -406,5 +392,7 @@ minetest.register_on_mods_loaded(function()
|
||||
|
||||
api.node_by_shaped_node[node] = node
|
||||
api.shape_by_shaped_node[node] = "node"
|
||||
|
||||
api.register_schema_crafts_for_node(node)
|
||||
end
|
||||
end)
|
||||
|
@ -32,16 +32,14 @@ api.register_crafts_for_shapes({
|
||||
]]
|
||||
local api = stairsplus.api
|
||||
|
||||
local function is_valid_item(item, shapes)
|
||||
local item_name = item:match("^([^ ]*)")
|
||||
|
||||
return shapes[item_name] or item_name == "" or item_name == "node" or item_name:match(":")
|
||||
end
|
||||
|
||||
local function is_valid_output(item, shapes)
|
||||
local item_name = item:match("^([^ ]+)")
|
||||
|
||||
return shapes[item_name] or item_name == "node" or item_name:match(":")
|
||||
return item_name and (shapes[item_name] or item_name == "node" or item_name:match(":"))
|
||||
end
|
||||
|
||||
local function is_valid_item(item, shapes)
|
||||
return is_valid_output(item, shapes) or item == ""
|
||||
end
|
||||
|
||||
local function verify_schema(schema)
|
||||
@ -135,44 +133,28 @@ local function has_the_right_shapes(schema, shapes)
|
||||
return true
|
||||
end
|
||||
|
||||
local function register_for_schema(node, shapes, schema)
|
||||
local function register_for_schema(node, schema)
|
||||
local recipe = table.copy(schema)
|
||||
|
||||
if is_valid_output(recipe.output, shapes) then
|
||||
recipe.output = api.get_shaped_node(node, recipe.output)
|
||||
else
|
||||
return
|
||||
end
|
||||
recipe.output = api.get_shaped_node(node, recipe.output)
|
||||
|
||||
if recipe.replacements then
|
||||
for _, replacement in ipairs(recipe.replacements) do
|
||||
for i, item in ipairs(replacement) do
|
||||
if is_valid_item(item, shapes) then
|
||||
replacement[i] = api.get_shaped_node(node, item)
|
||||
else
|
||||
return
|
||||
end
|
||||
replacement[i] = api.get_shaped_node(node, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if recipe.type == "shapeless" then
|
||||
for i, item in ipairs(recipe.recipe) do
|
||||
if is_valid_item(item, shapes) then
|
||||
recipe.recipe[i] = api.get_shaped_node(node, item)
|
||||
else
|
||||
return
|
||||
end
|
||||
recipe.recipe[i] = api.get_shaped_node(node, item)
|
||||
end
|
||||
|
||||
elseif recipe.type == "shaped" or recipe.type == nil then
|
||||
for _, row in ipairs(schema.recipe) do
|
||||
for _, row in ipairs(recipe.recipe) do
|
||||
for i, item in ipairs(row) do
|
||||
if is_valid_item(item, shapes) then
|
||||
row[i] = api.get_shaped_node(node, item)
|
||||
else
|
||||
return
|
||||
end
|
||||
row[i] = api.get_shaped_node(node, item)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -183,10 +165,12 @@ local function register_for_schema(node, shapes, schema)
|
||||
end
|
||||
|
||||
function api.register_schema_crafts_for_node(node)
|
||||
stairsplus.log("info", "registering schema crafts for %q", node)
|
||||
local shapes = api.get_shapes_hash(node)
|
||||
for _, schema in ipairs(api.registered_recipe_schemas) do
|
||||
if has_the_right_shapes(schema, shapes) then
|
||||
register_for_schema(node, shapes, schema)
|
||||
stairsplus.log("debug", "using schema %q", minetest.serialize(schema):sub(#("return ")))
|
||||
register_for_schema(node, schema)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user