minetest-toolranks-extras/hoe.lua

46 lines
1.2 KiB
Lua
Raw Permalink Normal View History

2020-02-12 12:40:48 +01:00
local function add_hoe(material)
2020-08-10 22:06:35 +02:00
-- registering as tool
2020-02-12 12:40:48 +01:00
local name = "farming:hoe_"..material
2020-08-10 22:06:35 +02:00
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
2020-02-12 12:40:48 +01:00
minetest.override_item(name, {
2020-03-07 14:37:47 +01:00
-- we also want hoes to increase dugnodes when farming soil
on_use = function(itemstack, user, pointed_thing, uses)
2020-08-10 22:06:35 +02:00
local under = minetest.get_node(pointed_thing.under)
-- get origin wear
2020-03-07 14:37:47 +01:00
local wear = itemstack:get_wear()
2020-08-10 22:06:35 +02:00
-- apply previous on_use
2020-03-07 14:37:47 +01:00
local ret_itemstack = hoe_on_use(itemstack, user, pointed_thing, uses)
2020-08-10 22:06:35 +02:00
if ret_itemstack == nil then
return nil
2020-03-07 14:37:47 +01:00
end
2020-08-10 22:06:35 +02:00
-- 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})
2020-03-07 14:37:47 +01:00
end
2020-02-12 12:40:48 +01:00
})
end
add_hoe("wood")
add_hoe("stone")
add_hoe("steel")
-- Following hoes are not available in creative inventory, but
-- it is possible to /give them
add_hoe("bronze")
add_hoe("mese")
add_hoe("diamond")