]> git.lizzy.rs Git - minetest.git/commitdiff
Fix crash when crafting callbacks return strings (#12685)
authorZughy <63455151+Zughy@users.noreply.github.com>
Fri, 12 Aug 2022 09:17:37 +0000 (11:17 +0200)
committerGitHub <noreply@github.com>
Fri, 12 Aug 2022 09:17:37 +0000 (10:17 +0100)
Co-authored-by: Zughy <4279489-marco_a@users.noreply.gitlab.com>
builtin/game/register.lua

index ee4edabbf73c545e7c069aa89a7456a2942c4670..8b6f5b990648a8ee923541d9618301c0f698e1a9 100644 (file)
@@ -303,14 +303,16 @@ end
 
 function core.on_craft(itemstack, player, old_craft_list, craft_inv)
        for _, func in ipairs(core.registered_on_crafts) do
-               itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
+               -- cast to ItemStack since func() could return a string
+               itemstack = ItemStack(func(itemstack, player, old_craft_list, craft_inv) or itemstack)
        end
        return itemstack
 end
 
 function core.craft_predict(itemstack, player, old_craft_list, craft_inv)
        for _, func in ipairs(core.registered_craft_predicts) do
-               itemstack = func(itemstack, player, old_craft_list, craft_inv) or itemstack
+               -- cast to ItemStack since func() could return a string
+               itemstack = ItemStack(func(itemstack, player, old_craft_list, craft_inv) or itemstack)
        end
        return itemstack
 end