Properly handle multiple cookable drops

This commit is contained in:
LoneWolfHT 2022-02-02 12:22:05 -08:00
parent 4cef3ba46f
commit 94d6bd9b44

View File

@ -113,28 +113,41 @@ function lavastuff.burn_drops(tool)
-- loop through current node drops
for _, drop in pairs(drops) do -- get cooked output of current drops
local stack = ItemStack(drop)
local output = minetest.get_craft_result({
method = "cooking",
width = 1,
items = {drop}
})
local safety = 0
for _, name in pairs(lavastuff.blacklisted_items) do
if name == drop then
return old_handle_node_drops(pos, drops, digger, ...)
repeat
local output, leftover = minetest.get_craft_result({
method = "cooking",
width = 1,
items = {stack:to_string()}
})
for _, name in pairs(lavastuff.blacklisted_items) do
if name == drop then
return old_handle_node_drops(pos, drops, digger, ...)
end
end
end
-- if we have cooked result then add to new list
if output and output.item and not output.item:is_empty() and output.time <= lavastuff.cook_limit then
table.insert(hot_drops,
ItemStack({
name = output.item:get_name(),
count = output.item:to_table().count,
})
)
else -- if not then return normal drops
table.insert(hot_drops, stack)
-- if we have cooked result then add to new list
if output and output.item and not output.item:is_empty() and output.time <= lavastuff.cook_limit then
table.insert(hot_drops,
ItemStack({
name = output.item:get_name(),
count = output.item:to_table().count,
})
)
stack = leftover.items[1]
else -- if not then return normal drops
table.insert(hot_drops, stack)
stack = nil
end
safety = safety + 1
until (safety > 999 or not stack or stack:get_count() <= 0)
if safety > 999 then
minetest.log("error", "[lavastuff]: Something went wrong with drop cooking")
end
end