mirror of
https://github.com/louisroyer/minetest-toolranks-extras.git
synced 2024-09-28 15:50:57 +02:00
commit
96cb1092f4
32
hoe.lua
32
hoe.lua
@ -1,21 +1,33 @@
|
|||||||
local function add_hoe(material)
|
local function add_hoe(material)
|
||||||
|
-- registering as tool
|
||||||
local name = "farming:hoe_"..material
|
local name = "farming:hoe_"..material
|
||||||
local desc = ItemStack(name):get_definition().description
|
toolranks.add_tool(name)
|
||||||
local hoe_on_use = ItemStack(name):get_definition().on_use
|
|
||||||
|
-- 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, {
|
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
|
-- we also want hoes to increase dugnodes when farming soil
|
||||||
on_use = function(itemstack, user, pointed_thing, uses)
|
on_use = function(itemstack, user, pointed_thing, uses)
|
||||||
|
local under = minetest.get_node(pointed_thing.under)
|
||||||
|
-- get origin wear
|
||||||
local wear = itemstack:get_wear()
|
local wear = itemstack:get_wear()
|
||||||
|
-- apply previous on_use
|
||||||
local ret_itemstack = hoe_on_use(itemstack, user, pointed_thing, uses)
|
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 ret_itemstack == nil then
|
||||||
if (hoe_uses > 0) then -- increase dugnode if tool damaged
|
return nil
|
||||||
return toolranks.new_afteruse(ret_itemstack, user, nil, {wear = hoe_uses})
|
|
||||||
else
|
|
||||||
return ret_itemstack or nil
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
})
|
})
|
||||||
|
20
init.lua
20
init.lua
@ -3,18 +3,36 @@ local MP = minetest.get_modpath("toolranks_extras")
|
|||||||
toolranks_extras = {}
|
toolranks_extras = {}
|
||||||
|
|
||||||
-- mod information
|
-- mod information
|
||||||
toolranks_extras.mod = {version = "1.3.2", author = "Louis Royer"}
|
toolranks_extras.mod = {version = "1.3.3", author = "Louis Royer"}
|
||||||
|
|
||||||
-- settings
|
-- settings
|
||||||
toolranks_extras.settings =
|
toolranks_extras.settings =
|
||||||
{enable_farming_tools = minetest.settings:get_bool("toolranks_extra.farming", true)}
|
{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
|
-- mods detection
|
||||||
local use_farming = minetest.get_modpath("farming")
|
local use_farming = minetest.get_modpath("farming")
|
||||||
-- farming redo (https://notabug.org/tenplus1/farming)
|
-- farming redo (https://notabug.org/tenplus1/farming)
|
||||||
-- already implements toolranks support
|
-- already implements toolranks support
|
||||||
local use_farming_redo = use_farming and (farming.mod == "redo") or false
|
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)
|
if use_farming and (not use_farming_redo)
|
||||||
and toolranks_extras.settings.enable_farming_tools then
|
and toolranks_extras.settings.enable_farming_tools then
|
||||||
|
Loading…
Reference in New Issue
Block a user