Browse Source

Fix bug with coconut-milk craft

When crafting, tool used was fully repaired.
Now crafting will do damages on tool used instead.
merge-requests/3/head
Louis 3 weeks ago
parent
commit
89bffdecaf
2 changed files with 32 additions and 1 deletions
  1. +30
    -1
      crafts.lua
  2. +2
    -0
      mod.conf

+ 30
- 1
crafts.lua 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",

+ 2
- 0
mod.conf View File

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

Loading…
Cancel
Save