Skip to content

Commit

Permalink
Fix crash when crafting callbacks return strings (minetest#12685)
Browse files Browse the repository at this point in the history
Co-authored-by: Zughy <[email protected]>
  • Loading branch information
Zughy and Zughy committed Aug 12, 2022
1 parent c8ee755 commit 8bf1609
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions builtin/game/register.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8bf1609

Please sign in to comment.