From 2c7977f10116017b0c3607b6b41051b53bf11213 Mon Sep 17 00:00:00 2001 From: flux <25628292+fluxionary@users.noreply.github.com> Date: Mon, 8 Aug 2022 13:26:53 -0700 Subject: [PATCH] handle legacy drop definitions correctly --- stairsplus/api/node.lua | 10 +++++++++- stairsplus/compat/old_moreblocks.lua | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/stairsplus/api/node.lua b/stairsplus/api/node.lua index 81975a0..7d891de 100644 --- a/stairsplus/api/node.lua +++ b/stairsplus/api/node.lua @@ -149,7 +149,15 @@ 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 and type(node_def.drop) == "string" then + if meta.legacy_drop then + if type(meta.legacy_drop) == "string" then + local item = api.get_schema_recipe_item(meta.legacy_drop, shape) + if item then + def.drop = item + end + end + + elseif node_def.drop and type(node_def.drop) == "string" then local item = api.get_schema_recipe_item(node_def.drop, shape) if item then def.drop = item diff --git a/stairsplus/compat/old_moreblocks.lua b/stairsplus/compat/old_moreblocks.lua index ecc9e83..10a69aa 100644 --- a/stairsplus/compat/old_moreblocks.lua +++ b/stairsplus/compat/old_moreblocks.lua @@ -35,9 +35,7 @@ local function clean_legacy_fields(fields) fields.collision_box = nil fields.legacy_facedir_simple = nil fields.legacy_wallmounted = nil - if type(fields.drop) ~= "string" then - fields.drop = nil - end + fields.drop = nil fields.on_construct = nil fields.on_destruct = nil fields.after_destruct = nil @@ -49,22 +47,41 @@ local function clean_legacy_fields(fields) fields.on_dig = nil fields.on_timer = nil fields.on_receive_fields = nil + return fields end +local function handle_legacy_drop(modname, drop) + if not drop then + return + end + + if type(drop) == "table" then + return drop + else + return ("%s:%s"):format(modname, drop) + end +end + local function register_group(modname, subname, recipeitem, fields, group) if not minetest.registered_nodes[recipeitem] then error(("cannot register stairs for %s before the node is defined"):format(recipeitem)) end - fields = clean_legacy_fields(fields) + local meta = {} + + meta.legacy_drop = handle_legacy_drop(modname, fields.drop) + if is_legacy_drawtype(recipeitem) then meta.ignore_drawtype = true end + if is_legacy_paramtype2(recipeitem) then meta.ignore_paramtype2 = true end + fields = clean_legacy_fields(fields) + api.register_group(recipeitem, group, fields, meta) local old_name = ("%s:%s"):format(modname, subname)