1
0
mirror of https://github.com/mt-mods/moretrees.git synced 2024-12-26 18:50:23 +01:00

Fix bug with coconut-milk craft

When crafting, tool used was fully repaired.
Now crafting will do damages on tool used instead.
This commit is contained in:
Louis 2020-02-02 15:13:01 +01:00
parent 6fd3729669
commit 89bffdecaf
2 changed files with 32 additions and 1 deletions

View File

@ -117,10 +117,39 @@ for i in ipairs(moretrees.cutting_tools) do
},
replacements = {
{ "moretrees:coconut", "moretrees:raw_coconut" },
{ tool, tool }
}
})
end
-- give tool back with wear preserved
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
if (itemstack:get_name() == "moretrees:coconut_milk") then
for i, j in pairs(old_craft_grid) do
-- find tool used to do the craft
local ocg_name = j:get_name()
if ((ocg_name ~= "") and (ocg_name ~= "moretrees:coconut") and (ocg_name ~= "vessels:drinking_glass")) then
-- create a new tool and set wear
local t = ItemStack(ocg_name)
local w = j:get_wear()
-- works if tool used is an axe
local uses = j:get_tool_capabilities().groupcaps.choppy.uses or 0
if (w == 0 and uses ~= 0) then
-- tool has never been used
-- use tool once
t:set_wear(65535/(9*(uses - 1)))
else
-- set wear back
t:set_wear(w)
-- use tool once
if (uses ~= 0) then
t:add_wear(65535/(9*(uses - 1)))
end
end
-- add to craft inventory
craft_inv:add_item("craft", t)
end
end
end
end)
minetest.register_craft({
type = "shapeless",

View File

@ -1 +1,3 @@
name = moretrees
depends = default, biome_lib, vessels
optional_depends = doors stairs, moreblocks, intllib, farming