This commit is contained in:
Louis 2020-08-10 22:06:35 +02:00
parent a0d3b0451e
commit 5318f91f75
2 changed files with 41 additions and 11 deletions

32
hoe.lua

@ -1,21 +1,33 @@
local function add_hoe(material)
-- registering as tool
local name = "farming:hoe_"..material
local desc = ItemStack(name):get_definition().description
local hoe_on_use = ItemStack(name):get_definition().on_use
toolranks.add_tool(name)
-- getting after_use
local def = minetest.registered_items[name]
local hoe_on_use = def.on_use
local hoe_after_use = def.after_use
if (hoe_on_use == nil) or (hoe_after_use == nil) then
return
end
minetest.override_item(name, {
original_description = desc,
description = toolranks.create_description(desc),
after_use = toolranks.new_afteruse,
-- we also want hoes to increase dugnodes when farming soil
on_use = function(itemstack, user, pointed_thing, uses)
local under = minetest.get_node(pointed_thing.under)
-- get origin wear
local wear = itemstack:get_wear()
-- apply previous on_use
local ret_itemstack = hoe_on_use(itemstack, user, pointed_thing, uses)
local hoe_uses = ret_itemstack and ret_itemstack:get_wear() - wear or 0
if (hoe_uses > 0) then -- increase dugnode if tool damaged
return toolranks.new_afteruse(ret_itemstack, user, nil, {wear = hoe_uses})
else
return ret_itemstack or nil
if ret_itemstack == nil then
return nil
end
-- compute wear diff
local hoe_uses = ret_itemstack:get_wear() - wear
-- set wear back because it is up to hoe_after_use to add wear
ret_itemstack:set_wear(wear)
-- apply afteruse
return hoe_after_use(ret_itemstack, user, under, {wear = hoe_uses})
end
})

@ -3,18 +3,36 @@ local MP = minetest.get_modpath("toolranks_extras")
toolranks_extras = {}
-- mod information
toolranks_extras.mod = {version = "1.3.2", author = "Louis Royer"}
toolranks_extras.mod = {version = "1.3.3", author = "Louis Royer"}
-- settings
toolranks_extras.settings =
{enable_farming_tools = minetest.settings:get_bool("toolranks_extra.farming", true)}
-- XXX: when https://github.com/minetest/minetest/pull/7377
-- is merged, we can remove this function
-- and %s/toolranks_extras\.log/minetest\.log/g
toolranks_extras.log = function(level, text)
local prefix = "[toolranks_extra] "
if text then
minetest.log(level, prefix..text)
else
minetest.log(prefix..level)
end
end
-- mods detection
local use_farming = minetest.get_modpath("farming")
-- farming redo (https://notabug.org/tenplus1/farming)
-- already implements toolranks support
local use_farming_redo = use_farming and (farming.mod == "redo") or false
-- toolranks version
if toolranks.add_tool == nil then
toolranks_extras.log("error", "Please a more recent version of"
.." toolranks (at least version 1.2).")
end
if use_farming and (not use_farming_redo)
and toolranks_extras.settings.enable_farming_tools then