From 89bffdecaf6454c5305efb80b13b7f9c7af4627b Mon Sep 17 00:00:00 2001 From: Louis <4259825-lroyer@users.noreply.gitlab.com> Date: Sun, 2 Feb 2020 15:13:01 +0100 Subject: [PATCH] Fix bug with coconut-milk craft When crafting, tool used was fully repaired. Now crafting will do damages on tool used instead. --- crafts.lua | 31 ++++++++++++++++++++++++++++++- mod.conf | 2 ++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crafts.lua b/crafts.lua index 9d1fe79..f383b6f 100644 --- a/crafts.lua +++ b/crafts.lua @@ -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", diff --git a/mod.conf b/mod.conf index b95f3e8..4eef24a 100644 --- a/mod.conf +++ b/mod.conf @@ -1 +1,3 @@ name = moretrees +depends = default, biome_lib, vessels +optional_depends = doors stairs, moreblocks, intllib, farming