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 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

View File

@ -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")

View File

@ -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)

View File

@ -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

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", "legacy")

View File

@ -3,13 +3,19 @@
-- existing servers
local api = stairsplus.api
local is_legacy_drawtype = stairsplus.compat.is_legacy_drawtype
local legacy_mode = stairsplus.settings.legacy_mode
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
api.register_group(recipeitem, "legacy", fields)
api.register_group(recipeitem, "legacy", fields, meta)
else
api.register_group(recipeitem, "common", fields)
api.register_group(recipeitem, "common", fields, meta)
end
local old_name = ("%s:%s"):format(modname, subname)

View File

@ -7,57 +7,78 @@ local api = stairsplus.api
local S = stairsplus.S
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...
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", {
groups = groups,
tiles = tiles,
description = description,
sounds = sounds,
}, {
align_style = worldaligntex and "world" or default_align_style
})
}, meta)
minetest.register_alias(("stairs:stair_%s"):format(subname), api.format_name(node, "stair"))
end
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", {
groups = groups,
tiles = images,
description = description,
sounds = sounds,
}, {
align_style = worldaligntex and "world" or default_align_style
})
}, meta)
minetest.register_alias(("stairs:slab_%s"):format(subname), api.format_name(node, "slab_8"))
end
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", {
groups = groups,
tiles = tiles,
description = full_description or S("Inner @1", description),
sounds = sounds,
}, {
align_style = worldaligntex and "world" or default_align_style
})
}, meta)
minetest.register_alias(("stairs:stair_inner_%s"):format(subname), api.format_name(node, "stair_inner"))
end
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", {
groups = groups,
tiles = tiles,
description = full_description or S("Inner @1", description),
sounds = sounds,
}, {
align_style = worldaligntex and "world" or default_align_style
})
}, meta)
minetest.register_alias(("stairs:stair_outer_%s"):format(subname), api.format_name(node, "stair_outer"))
end

View File

@ -76,7 +76,7 @@ for _, shape in ipairs({"micro", "panel", "slab"}) do
local shape2 = ("%s_%s"):format(shape, slice2)
local def1 = api.registered_shapes[shape1]
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({
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 def1 = api.registered_shapes[shape1]
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({
output = ("%s %s"):format(shape2, n),

View File

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

View File

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

View File

@ -1,4 +1,4 @@
name = stairsplus
title = Stairs+
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",
description = "@1 Outer Stair",
shape_groups = {stair = 1, common = 1, legacy = 1, basic = 1},
eighths = 5,
eighths = 7,
drawtype = "nodebox",
node_box = {
type = "fixed",