fix some bugs, starting to track down all the compatability issues

This commit is contained in:
flux 2022-06-16 16:32:55 -07:00
parent 03b189e927
commit acc6e2ebea
12 changed files with 121 additions and 85 deletions

View File

@ -1,5 +1,7 @@
local api = stairsplus.api local api = stairsplus.api
local in_creative_inventory = stairsplus.settings.in_creative_inventory
api.passthrough_groups = {} api.passthrough_groups = {}
api.scale_groups = {} api.scale_groups = {}
api.ignore_groups = {} api.ignore_groups = {}
@ -33,3 +35,28 @@ function api.register_ignore_groups(groups)
api.register_ignore_group(group) api.register_ignore_group(group)
end end
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

View File

@ -1,7 +1,7 @@
stairsplus.api = {} stairsplus.api = {}
stairsplus.dofile("api", "shape") stairsplus.dofile("api", "shape")
stairsplus.dofile("api", "groups") stairsplus.dofile("api", "group_filters")
stairsplus.dofile("api", "node") stairsplus.dofile("api", "node")
stairsplus.dofile("api", "alias") stairsplus.dofile("api", "alias")
stairsplus.dofile("api", "recipe") stairsplus.dofile("api", "recipe")

View File

@ -11,7 +11,6 @@ local S = stairsplus.S
local legacy_mode = stairsplus.settings.legacy_mode local legacy_mode = stairsplus.settings.legacy_mode
local legacy_place_mechanic = stairsplus.settings.legacy_place_mechanic 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 local default_align_style = stairsplus.settings.default_align_style
api.nodes_by_shape = {} api.nodes_by_shape = {}
@ -59,7 +58,6 @@ local function check_node_validity(node_def, meta)
paramtype2 == "degrotate" or paramtype2 == "degrotate" or
paramtype2 == "meshoptions" or paramtype2 == "meshoptions" or
paramtype2 == "color" or paramtype2 == "color" or
paramtype2 == "colorfacedir" or
paramtype2 == "colorwallmounted" or paramtype2 == "colorwallmounted" or
paramtype2 == "glasslikeliquidlevel" or paramtype2 == "glasslikeliquidlevel" or
paramtype2 == "colordegrotate" paramtype2 == "colordegrotate"
@ -68,29 +66,6 @@ local function check_node_validity(node_def, meta)
end end
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_right_dirmap = {9, 18, 7, 12}
local wall_left_dirmap = {11, 16, 5, 14} local wall_left_dirmap = {11, 16, 5, 14}
local ceil_dirmap = {20, 23, 22, 21} 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) stairsplus.log("info", "registering %s %s", shape, node)
meta = meta or {} meta = meta or {}
overrides = overrides 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]) local node_def = table.copy(minetest.registered_nodes[node])
check_node_validity(node_def, meta) 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 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 -- shaped_node definition
local def = { local def = {
description = S(shape_def.description, node_def.description or node), 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, collision_box = shape_def.collision_box,
selection_box = shape_def.selection_box, selection_box = shape_def.selection_box,
paramtype = shape_def.paramtype or "light", paramtype = shape_def.paramtype or "light",
paramtype2 = shape_def.paramtype2 or "facedir", paramtype2 = paramtype2,
light_source = scale_light(node_def.light_source, shape_def), 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, tiles = node_def.tiles,
overlay_tiles = node_def.overlay_tiles, overlay_tiles = node_def.overlay_tiles,
use_texture_alpha = node_def.use_texture_alpha, use_texture_alpha = node_def.use_texture_alpha,
color = node_def.color, color = node_def.color,
palette = node_def.palette, -- for coloredfacedir
stack_max = node_def.stack_max, stack_max = node_def.stack_max,
sound = node_def.sound, sound = node_def.sound,
is_ground_content = node_def.is_ground_content, is_ground_content = node_def.is_ground_content,
@ -249,7 +235,7 @@ function api.register_single(node, shape, overrides, meta)
end end
-- if there's a drop defined, and we can drop a shaped version, do so -- 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) local item = api.get_shaped_node(node_def.drop, shape)
if item then if item then
def.drop = item def.drop = item
@ -260,6 +246,7 @@ function api.register_single(node, shape, overrides, meta)
def.on_place = api.legacy_on_place def.on_place = api.legacy_on_place
end end
overrides.groups = nil
table_set_all(def, overrides) table_set_all(def, overrides)
-- set backface_culling and align_style -- set backface_culling and align_style
@ -353,13 +340,14 @@ function api.get_shapes_hash(node)
end end
function api.get_shaped_node(node, shape_or_item) function api.get_shaped_node(node, shape_or_item)
local name, count = shape_or_item:match("^([^ ]+) (%d+)") if shape_or_item == "" then
if not name then return ""
name = shape_or_item
end end
if name == "" then local name, count = shape_or_item:match("^([^ ]+) (%d+)")
return ""
if not name then
name = shape_or_item
end end
count = tonumber(count) count = tonumber(count)
@ -396,8 +384,6 @@ end
minetest.register_on_mods_loaded(function() minetest.register_on_mods_loaded(function()
stairsplus.log("info", "registering schema crafts") stairsplus.log("info", "registering schema crafts")
for node, shapes in pairs(api.shapes_by_node) do for node, shapes in pairs(api.shapes_by_node) do
api.register_schema_crafts_for_node(node)
for shape in pairs(shapes) do for shape in pairs(shapes) do
local shaped_node = api.format_name(node, shape) local shaped_node = api.format_name(node, shape)
api.node_by_shaped_node[shaped_node] = node 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.node_by_shaped_node[node] = node
api.shape_by_shaped_node[node] = "node" api.shape_by_shaped_node[node] = "node"
api.register_schema_crafts_for_node(node)
end end
end) end)

View File

@ -32,16 +32,14 @@ api.register_crafts_for_shapes({
]] ]]
local api = stairsplus.api 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 function is_valid_output(item, shapes)
local item_name = item:match("^([^ ]+)") 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 end
local function verify_schema(schema) local function verify_schema(schema)
@ -135,44 +133,28 @@ local function has_the_right_shapes(schema, shapes)
return true return true
end end
local function register_for_schema(node, shapes, schema) local function register_for_schema(node, schema)
local recipe = table.copy(schema) local recipe = table.copy(schema)
if is_valid_output(recipe.output, shapes) then recipe.output = api.get_shaped_node(node, recipe.output)
recipe.output = api.get_shaped_node(node, recipe.output)
else
return
end
if recipe.replacements then if recipe.replacements then
for _, replacement in ipairs(recipe.replacements) do for _, replacement in ipairs(recipe.replacements) do
for i, item in ipairs(replacement) do for i, item in ipairs(replacement) do
if is_valid_item(item, shapes) then replacement[i] = api.get_shaped_node(node, item)
replacement[i] = api.get_shaped_node(node, item)
else
return
end
end end
end end
end end
if recipe.type == "shapeless" then if recipe.type == "shapeless" then
for i, item in ipairs(recipe.recipe) do for i, item in ipairs(recipe.recipe) do
if is_valid_item(item, shapes) then recipe.recipe[i] = api.get_shaped_node(node, item)
recipe.recipe[i] = api.get_shaped_node(node, item)
else
return
end
end end
elseif recipe.type == "shaped" or recipe.type == nil then 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 for i, item in ipairs(row) do
if is_valid_item(item, shapes) then row[i] = api.get_shaped_node(node, item)
row[i] = api.get_shaped_node(node, item)
else
return
end
end end
end end
end end
@ -183,10 +165,12 @@ local function register_for_schema(node, shapes, schema)
end end
function api.register_schema_crafts_for_node(node) function api.register_schema_crafts_for_node(node)
stairsplus.log("info", "registering schema crafts for %q", node)
local shapes = api.get_shapes_hash(node) local shapes = api.get_shapes_hash(node)
for _, schema in ipairs(api.registered_recipe_schemas) do for _, schema in ipairs(api.registered_recipe_schemas) do
if has_the_right_shapes(schema, shapes) then 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 end
end end

View File

@ -1,4 +1,12 @@
stairsplus.compat = {} stairsplus.compat = {
is_legacy_drawtype = function(node)
local def = minetest.registered_nodes[node]
return (
def.drawtype == "mesh" or
def.drawtype == "plantlike"
)
end
}
stairsplus.dofile("compat", "stairs") stairsplus.dofile("compat", "stairs")
stairsplus.dofile("compat", "legacy") stairsplus.dofile("compat", "legacy")

View File

@ -3,13 +3,19 @@
-- existing servers -- existing servers
local api = stairsplus.api local api = stairsplus.api
local is_legacy_drawtype = stairsplus.compat.is_legacy_drawtype
local legacy_mode = stairsplus.settings.legacy_mode local legacy_mode = stairsplus.settings.legacy_mode
function stairsplus:register_all(modname, subname, recipeitem, fields) function stairsplus:register_all(modname, subname, recipeitem, fields)
local meta = {}
if is_legacy_drawtype(recipeitem) then
meta.ignore_drawtype = true
end
if legacy_mode then if legacy_mode then
api.register_group(recipeitem, "legacy", fields) api.register_group(recipeitem, "legacy", fields, meta)
else else
api.register_group(recipeitem, "common", fields) api.register_group(recipeitem, "common", fields, meta)
end end
local old_name = ("%s:%s"):format(modname, subname) local old_name = ("%s:%s"):format(modname, subname)

View File

@ -7,57 +7,78 @@ local api = stairsplus.api
local S = stairsplus.S local S = stairsplus.S
local default_align_style = stairsplus.settings.default_align_style local default_align_style = stairsplus.settings.default_align_style
local is_legacy_drawtype = stairsplus.compat.is_legacy_drawtype
-- stairs compat: override what stairs does, and "fix" any stairs which were already registered... -- stairs compat: override what stairs does, and "fix" any stairs which were already registered...
function stairs.register_stair(subname, node, groups, tiles, description, sounds, worldaligntex) function stairs.register_stair(subname, node, groups, tiles, description, sounds, worldaligntex)
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
if is_legacy_drawtype(node) then
meta.ignore_drawtype = true
end
api.register_single(node, "stair", { api.register_single(node, "stair", {
groups = groups, groups = groups,
tiles = tiles, tiles = tiles,
description = description, description = description,
sounds = sounds, sounds = sounds,
}, { }, meta)
align_style = worldaligntex and "world" or default_align_style
})
minetest.register_alias(("stairs:stair_%s"):format(subname), api.format_name(node, "stair")) minetest.register_alias(("stairs:stair_%s"):format(subname), api.format_name(node, "stair"))
end end
function stairs.register_slab(subname, node, groups, images, description, sounds, worldaligntex) function stairs.register_slab(subname, node, groups, images, description, sounds, worldaligntex)
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
if is_legacy_drawtype(node) then
meta.ignore_drawtype = true
end
api.register_single(node, "slab_8", { api.register_single(node, "slab_8", {
groups = groups, groups = groups,
tiles = images, tiles = images,
description = description, description = description,
sounds = sounds, sounds = sounds,
}, { }, meta)
align_style = worldaligntex and "world" or default_align_style
})
minetest.register_alias(("stairs:slab_%s"):format(subname), api.format_name(node, "slab_8")) minetest.register_alias(("stairs:slab_%s"):format(subname), api.format_name(node, "slab_8"))
end end
function stairs.register_stair_inner(subname, node, groups, tiles, description, sounds, worldaligntex, full_description) function stairs.register_stair_inner(subname, node, groups, tiles, description, sounds, worldaligntex, full_description)
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
if is_legacy_drawtype(node) then
meta.ignore_drawtype = true
end
api.register_single(node, "stair_inner", { api.register_single(node, "stair_inner", {
groups = groups, groups = groups,
tiles = tiles, tiles = tiles,
description = full_description or S("Inner @1", description), description = full_description or S("Inner @1", description),
sounds = sounds, sounds = sounds,
}, { }, meta)
align_style = worldaligntex and "world" or default_align_style
})
minetest.register_alias(("stairs:stair_inner_%s"):format(subname), api.format_name(node, "stair_inner")) minetest.register_alias(("stairs:stair_inner_%s"):format(subname), api.format_name(node, "stair_inner"))
end end
function stairs.register_stair_outer(subname, node, groups, tiles, description, sounds, worldaligntex, full_description) function stairs.register_stair_outer(subname, node, groups, tiles, description, sounds, worldaligntex, full_description)
local meta = {
align_style = worldaligntex and "world" or default_align_style
}
if is_legacy_drawtype(node) then
meta.ignore_drawtype = true
end
api.register_single(node, "stair_outer", { api.register_single(node, "stair_outer", {
groups = groups, groups = groups,
tiles = tiles, tiles = tiles,
description = full_description or S("Inner @1", description), description = full_description or S("Inner @1", description),
sounds = sounds, sounds = sounds,
}, { }, meta)
align_style = worldaligntex and "world" or default_align_style
})
minetest.register_alias(("stairs:stair_outer_%s"):format(subname), api.format_name(node, "stair_outer")) minetest.register_alias(("stairs:stair_outer_%s"):format(subname), api.format_name(node, "stair_outer"))
end end

View File

@ -76,7 +76,7 @@ for _, shape in ipairs({"micro", "panel", "slab"}) do
local shape2 = ("%s_%s"):format(shape, slice2) local shape2 = ("%s_%s"):format(shape, slice2)
local def1 = api.registered_shapes[shape1] local def1 = api.registered_shapes[shape1]
local def2 = api.registered_shapes[shape2] local def2 = api.registered_shapes[shape2]
local n = math.floor(def1.eighths / def2.eighths) local n = math.floor(3 * def1.eighths / def2.eighths)
register_craft_schema({ register_craft_schema({
output = ("%s %s"):format(shape2, n), output = ("%s %s"):format(shape2, n),
@ -95,7 +95,7 @@ for _, shape in ipairs({"panel", "slab"}) do
local shape2 = ("%s_%s"):format(demotion[shape], slice) local shape2 = ("%s_%s"):format(demotion[shape], slice)
local def1 = api.registered_shapes[shape1] local def1 = api.registered_shapes[shape1]
local def2 = api.registered_shapes[shape2] local def2 = api.registered_shapes[shape2]
local n = math.floor(def1.eighths / def2.eighths) local n = math.floor(3 * def1.eighths / def2.eighths)
register_craft_schema({ register_craft_schema({
output = ("%s %s"):format(shape2, n), output = ("%s %s"):format(shape2, n),

View File

@ -19,4 +19,5 @@ stairsplus.api.register_ignore_groups({
"attached_node", "attached_node",
"connect_to_raillike", "connect_to_raillike",
"tool", "tool",
"type_node",
}) })

View File

@ -20,6 +20,7 @@ stairsplus = {
S = S, S = S,
has = { has = {
default = minetest.get_modpath("default"),
stairs = minetest.get_modpath("stairs"), stairs = minetest.get_modpath("stairs"),
}, },

View File

@ -1,4 +1,4 @@
name = stairsplus name = stairsplus
title = Stairs+ title = Stairs+
description = Microblock API description = Microblock API
optional_depends = stairs optional_depends = default, stairs

View File

@ -63,7 +63,7 @@ stairsplus.api.register_shape("stair_outer", {
name_format = "stair_%s_outer", name_format = "stair_%s_outer",
description = "@1 Outer Stair", description = "@1 Outer Stair",
shape_groups = {stair = 1, common = 1, legacy = 1, basic = 1}, shape_groups = {stair = 1, common = 1, legacy = 1, basic = 1},
eighths = 5, eighths = 7,
drawtype = "nodebox", drawtype = "nodebox",
node_box = { node_box = {
type = "fixed", type = "fixed",