From 2cdf9bdb652d8f8fca1f6bf17766bbd82f0c0812 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Fri, 7 Feb 2025 20:53:17 +0300 Subject: [PATCH 01/10] registered_crafts table --- builtin/game/register.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 3e4b9be968ac7..256729aca25d3 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -26,6 +26,7 @@ core.registered_nodes = {} core.registered_craftitems = {} core.registered_tools = {} core.registered_aliases = {} +core.registered_crafts = {} -- For tables that are indexed by item name: -- If table[X] does not exist, default to table[core.registered_aliases[X]] @@ -320,6 +321,12 @@ function core.register_alias_force(name, convert_to) register_alias_raw(name, convert_to) end +local old_register_craft = core.register_craft +function core.register_craft(recipe) + table.insert(core.registered_crafts, recipe) + old_register_craft(recipe) +end + function core.on_craft(itemstack, player, old_craft_list, craft_inv) for _, func in ipairs(core.registered_on_crafts) do -- cast to ItemStack since func() could return a string From b45599f8f27a9d903384534e33873175fff8cfe5 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Fri, 7 Feb 2025 22:40:59 +0300 Subject: [PATCH 02/10] Tabs --- builtin/game/register.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 256729aca25d3..f4a0555baf850 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -323,8 +323,8 @@ end local old_register_craft = core.register_craft function core.register_craft(recipe) - table.insert(core.registered_crafts, recipe) - old_register_craft(recipe) + table.insert(core.registered_crafts, recipe) + old_register_craft(recipe) end function core.on_craft(itemstack, player, old_craft_list, craft_inv) From 33367eb936cd6f55eb37ac53f6da9c5c8d3424be Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Fri, 7 Feb 2025 22:52:20 +0300 Subject: [PATCH 03/10] Deprecation --- builtin/game/deprecated.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 87b7859955e0c..3449bacd1f332 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -61,3 +61,36 @@ function core.register_on_auth_fail(func) end end) end + +-- +-- core.get_all_craft_recipes +-- + +local old_get_all_craft_recipes = core.get_all_craft_recipes +function core.get_all_craft_recipes(...) + core.log("deprecated", "core.get_all_craft_recipes " .. + "is deprecated, use core.registered_crafts instead.") + old_get_all_craft_recipes(...) +end + +-- +-- core.get_craft_recipe +-- + +local old_get_craft_recipe = core.get_craft_recipe +function core.get_craft_recipe(...) + core.log("deprecated", "core.get_craft_recipe " .. + "is deprecated, use core.registered_crafts instead.") + old_get_craft_recipe(...) +end + +-- +-- core.get_craft_result +-- + +local old_get_craft_result = core.get_craft_result +function core.get_craft_result(...) + core.log("deprecated", "core.get_craft_result " .. + "is deprecated, use core.registered_crafts instead.") + old_get_craft_result(...) +end From ad5805c61a4de7d8db15bdc5bee07725418a001b Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:23:12 +0300 Subject: [PATCH 04/10] Crash fixes --- builtin/game/deprecated.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 3449bacd1f332..28d7c5f08bbd3 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -70,7 +70,7 @@ local old_get_all_craft_recipes = core.get_all_craft_recipes function core.get_all_craft_recipes(...) core.log("deprecated", "core.get_all_craft_recipes " .. "is deprecated, use core.registered_crafts instead.") - old_get_all_craft_recipes(...) + return old_get_all_craft_recipes(...) end -- @@ -81,7 +81,7 @@ local old_get_craft_recipe = core.get_craft_recipe function core.get_craft_recipe(...) core.log("deprecated", "core.get_craft_recipe " .. "is deprecated, use core.registered_crafts instead.") - old_get_craft_recipe(...) + return old_get_craft_recipe(...) end -- @@ -92,5 +92,5 @@ local old_get_craft_result = core.get_craft_result function core.get_craft_result(...) core.log("deprecated", "core.get_craft_result " .. "is deprecated, use core.registered_crafts instead.") - old_get_craft_result(...) + return old_get_craft_result(...) end From e3ada303fbd928441af2a4e3d6e6ad4e91b7744c Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Fri, 7 Feb 2025 23:34:34 +0300 Subject: [PATCH 05/10] Better detection --- builtin/game/register.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index f4a0555baf850..383662ac30041 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -323,7 +323,20 @@ end local old_register_craft = core.register_craft function core.register_craft(recipe) - table.insert(core.registered_crafts, recipe) + local name = recipe.output + if not name then + if recipe.type ~= "fuel" then + name = recipe.type + else + name = recipe.recipe + end + else + name = ItemStack(name):get_name() + end + if not core.registered_crafts[name] then + core.registered_crafts[name] = {} + end + table.insert(core.registered_crafts[name], recipe) old_register_craft(recipe) end From 6b2aab90f763f018adf70b974bde7f501c4df0d2 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Sat, 8 Feb 2025 20:09:33 +0300 Subject: [PATCH 06/10] clear_craft addition --- builtin/game/register.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 383662ac30041..2d0aa75e151fa 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -340,6 +340,24 @@ function core.register_craft(recipe) old_register_craft(recipe) end +local old_clear_craft = core.clear_craft +function core.clear_craft(recipe) + local name = recipe.output + local pos + for i, def in pairs(core.registered_crafts[name]) do + if dump(def) == dump(recipe) or ((def.output and recipe.output and def.output == recipe.output) and def.recipe == recipe.recipe) then + pos = i + end + end + if pos then + core.registered_crafts[name][pos] = nil + if #core.registered_crafts[name] == 0 then + core.registered_crafts[name] = nil + end + end + old_clear_craft(recipe) +end + function core.on_craft(itemstack, player, old_craft_list, craft_inv) for _, func in ipairs(core.registered_on_crafts) do -- cast to ItemStack since func() could return a string From 7b8c7e1436a399784071885a93e73392221be829 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Sat, 8 Feb 2025 20:13:45 +0300 Subject: [PATCH 07/10] Some sort changes --- builtin/game/register.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 2d0aa75e151fa..445b5f3da67e5 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -345,7 +345,9 @@ function core.clear_craft(recipe) local name = recipe.output local pos for i, def in pairs(core.registered_crafts[name]) do - if dump(def) == dump(recipe) or ((def.output and recipe.output and def.output == recipe.output) and def.recipe == recipe.recipe) then + if dump(def) == dump(recipe) or + ((def.output and recipe.output and def.output == recipe.output) + and def.recipe == recipe.recipe) then pos = i end end From 918f124eb77e9215d18eee14e3d627df873567b4 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Sat, 8 Feb 2025 20:29:18 +0300 Subject: [PATCH 08/10] table fix --- builtin/game/register.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index 445b5f3da67e5..ead76d5abfb00 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -342,7 +342,11 @@ end local old_clear_craft = core.clear_craft function core.clear_craft(recipe) - local name = recipe.output + local name = recipe.output or "" + if not core.registered_crafts[name] then + old_clear_craft(recipe) + return + end local pos for i, def in pairs(core.registered_crafts[name]) do if dump(def) == dump(recipe) or From 76b4cc0ed0a11024a44e231a69bb51068e318f3e Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Sun, 9 Feb 2025 09:59:15 +0300 Subject: [PATCH 09/10] Remain it as it was --- builtin/game/deprecated.lua | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/builtin/game/deprecated.lua b/builtin/game/deprecated.lua index 28d7c5f08bbd3..87b7859955e0c 100644 --- a/builtin/game/deprecated.lua +++ b/builtin/game/deprecated.lua @@ -61,36 +61,3 @@ function core.register_on_auth_fail(func) end end) end - --- --- core.get_all_craft_recipes --- - -local old_get_all_craft_recipes = core.get_all_craft_recipes -function core.get_all_craft_recipes(...) - core.log("deprecated", "core.get_all_craft_recipes " .. - "is deprecated, use core.registered_crafts instead.") - return old_get_all_craft_recipes(...) -end - --- --- core.get_craft_recipe --- - -local old_get_craft_recipe = core.get_craft_recipe -function core.get_craft_recipe(...) - core.log("deprecated", "core.get_craft_recipe " .. - "is deprecated, use core.registered_crafts instead.") - return old_get_craft_recipe(...) -end - --- --- core.get_craft_result --- - -local old_get_craft_result = core.get_craft_result -function core.get_craft_result(...) - core.log("deprecated", "core.get_craft_result " .. - "is deprecated, use core.registered_crafts instead.") - return old_get_craft_result(...) -end From da05359e1599a67e454a9e1888f8387e2f60cf47 Mon Sep 17 00:00:00 2001 From: BlackImpostor <106878493+SkyBuilder1717@users.noreply.github.com> Date: Mon, 10 Feb 2025 10:57:04 +0300 Subject: [PATCH 10/10] Helper function --- builtin/game/register.lua | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/builtin/game/register.lua b/builtin/game/register.lua index ead76d5abfb00..86f960bb65915 100644 --- a/builtin/game/register.lua +++ b/builtin/game/register.lua @@ -340,6 +340,20 @@ function core.register_craft(recipe) old_register_craft(recipe) end +-- Helper function to compare tables +local function compare(def, recipe) + local correct = 0 + for key, value in pairs(def) do + if value == recipe[key] then + correct = correct + 1 + end + end + if correct == #recipe then + return true + end + return false +end + local old_clear_craft = core.clear_craft function core.clear_craft(recipe) local name = recipe.output or "" @@ -349,9 +363,8 @@ function core.clear_craft(recipe) end local pos for i, def in pairs(core.registered_crafts[name]) do - if dump(def) == dump(recipe) or - ((def.output and recipe.output and def.output == recipe.output) - and def.recipe == recipe.recipe) then + if compare(def, recipe) or + (def.type == recipe.type and def.output == recipe.output or def.recipe == recipe.recipe) then pos = i end end