1
0
mirror of https://codeberg.org/tenplus1/mobs_monster.git synced 2024-12-23 01:10:26 +01:00

refactor lava pick dig function

This commit is contained in:
tenplus1 2024-06-28 11:31:26 +01:00
parent 50039fe67d
commit 4ab678d7ec

View File

@ -138,46 +138,43 @@ local old_handle_node_drops = minetest.handle_node_drops
function minetest.handle_node_drops(pos, drops, digger) function minetest.handle_node_drops(pos, drops, digger)
-- are we the player holding a Lava Pick? -- are we a player using the lava pick?
if not digger if digger and digger:get_wielded_item():get_name() == ("mobs:pick_lava") then
or (digger and digger:get_wielded_item():get_name() ~= ("mobs:pick_lava")) then
return old_handle_node_drops(pos, drops, digger)
end
-- reset new smelted drops local hot_drops = {}
local hot_drops = {}
-- loop through current node drops for _, drop in ipairs(drops) do
for _, drop in ipairs(drops) do
-- get cooked output of current drops local stack = ItemStack(drop)
local stack = ItemStack(drop)
while not stack:is_empty() do while not stack:is_empty() do
local output, decremented_input = minetest.get_craft_result({ local output, decremented_input = minetest.get_craft_result({
method = "cooking", method = "cooking",
width = 1, width = 1,
items = {stack} items = {stack}
}) })
if output.item:is_empty() then if output.item:is_empty() then
table.insert_all(hot_drops, decremented_input.items) table.insert_all(hot_drops, decremented_input.items)
break break
else else
if not output.item:is_empty() then if not output.item:is_empty() then
table.insert(hot_drops, output.item) table.insert(hot_drops, output.item)
end
table.insert_all(hot_drops, output.replacements)
stack = decremented_input.items[1] or ItemStack()
end end
table.insert_all(hot_drops, output.replacements)
stack = decremented_input.items[1] or ItemStack()
end end
end end
drops = hot_drops -- replace normal drops with cooked versions
end end
return old_handle_node_drops(pos, hot_drops, digger) return old_handle_node_drops(pos, drops, digger)
end end
minetest.register_tool(":mobs:pick_lava", { minetest.register_tool(":mobs:pick_lava", {