From acc6e2ebea53e2df8086d7131fae226c47d6e622 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Thu, 16 Jun 2022 16:32:55 -0700 Subject: [PATCH] fix some bugs, starting to track down all the compatability issues --- .../api/{groups.lua => group_filters.lua} | 27 +++++++++ stairsplus/api/init.lua | 2 +- stairsplus/api/node.lua | 58 ++++++++----------- stairsplus/api/recipe.lua | 44 +++++--------- stairsplus/compat/init.lua | 10 +++- stairsplus/compat/legacy.lua | 10 +++- stairsplus/compat/stairs.lua | 45 ++++++++++---- .../craft_schemas/standard_composition.lua | 4 +- stairsplus/groups/builtin.lua | 1 + stairsplus/init.lua | 1 + stairsplus/mod.conf | 2 +- stairsplus/shapes/stairs.lua | 2 +- 12 files changed, 121 insertions(+), 85 deletions(-) rename stairsplus/api/{groups.lua => group_filters.lua} (52%) diff --git a/stairsplus/api/groups.lua b/stairsplus/api/group_filters.lua similarity index 52% rename from stairsplus/api/groups.lua rename to stairsplus/api/group_filters.lua index 22f3501..9f9abe1 100644 --- a/stairsplus/api/groups.lua +++ b/stairsplus/api/group_filters.lua @@ -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 diff --git a/stairsplus/api/init.lua b/stairsplus/api/init.lua index bf82d54..aaed6ee 100644 --- a/stairsplus/api/init.lua +++ b/stairsplus/api/init.lua @@ -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") diff --git a/stairsplus/api/node.lua b/stairsplus/api/node.lua index 475d503..94aed9f 100644 --- a/stairsplus/api/node.lua +++ b/stairsplus/api/node.lua @@ -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) diff --git a/stairsplus/api/recipe.lua b/stairsplus/api/recipe.lua index 9f2ede6..81d6f05 100644 --- a/stairsplus/api/recipe.lua +++ b/stairsplus/api/recipe.lua @@ -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 diff --git a/stairsplus/compat/init.lua b/stairsplus/compat/init.lua index 2070544..0f603ca 100644 --- a/stairsplus/compat/init.lua +++ b/stairsplus/compat/init.lua @@ -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") diff --git a/stairsplus/compat/legacy.lua b/stairsplus/compat/legacy.lua index a486584..bc42f11 100644 --- a/stairsplus/compat/legacy.lua +++ b/stairsplus/compat/legacy.lua @@ -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) diff --git a/stairsplus/compat/stairs.lua b/stairsplus/compat/stairs.lua index 62e0e61..bed10fc 100644 --- a/stairsplus/compat/stairs.lua +++ b/stairsplus/compat/stairs.lua @@ -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 diff --git a/stairsplus/craft_schemas/standard_composition.lua b/stairsplus/craft_schemas/standard_composition.lua index 8e0245e..226efd6 100644 --- a/stairsplus/craft_schemas/standard_composition.lua +++ b/stairsplus/craft_schemas/standard_composition.lua @@ -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), diff --git a/stairsplus/groups/builtin.lua b/stairsplus/groups/builtin.lua index 82a2024..dcaae0d 100644 --- a/stairsplus/groups/builtin.lua +++ b/stairsplus/groups/builtin.lua @@ -19,4 +19,5 @@ stairsplus.api.register_ignore_groups({ "attached_node", "connect_to_raillike", "tool", + "type_node", }) diff --git a/stairsplus/init.lua b/stairsplus/init.lua index 513d078..c887822 100644 --- a/stairsplus/init.lua +++ b/stairsplus/init.lua @@ -20,6 +20,7 @@ stairsplus = { S = S, has = { + default = minetest.get_modpath("default"), stairs = minetest.get_modpath("stairs"), }, diff --git a/stairsplus/mod.conf b/stairsplus/mod.conf index 7a1b8ef..eb7cd30 100644 --- a/stairsplus/mod.conf +++ b/stairsplus/mod.conf @@ -1,4 +1,4 @@ name = stairsplus title = Stairs+ description = Microblock API -optional_depends = stairs +optional_depends = default, stairs diff --git a/stairsplus/shapes/stairs.lua b/stairsplus/shapes/stairs.lua index 4d91ae0..8043c44 100644 --- a/stairsplus/shapes/stairs.lua +++ b/stairsplus/shapes/stairs.lua @@ -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",