diff --git a/README.md b/README.md index abecd4a..ffc1cf5 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ To download you can play this game with the following minetest engines: * minetest default and xtras * integrated the killme/game_commands were simplified into default mod, and provide CC-BY-SA-NC license + * farming is default older but has build-in toolrank detection support * xdecor as `xdecor` [mods/xdecor](mods/xdecor) a super reduced version of homedecor pack, for performance * sorceredkid auth mod * minetest Auth Redux as `auth_rx` [mods/auth_rx](mods/auth_rx) from https://codeberg.org/minenux/minetest-mod-auth_rx @@ -48,7 +49,7 @@ To download you can play this game with the following minetest engines: * simple_skins as `skins` [mods/skins](mods/skins) from https://codeberg.org/minenux/minetest-mod-simple_skins * regrow as `regrow` [mods/regrow](mods/regrow) from https://codeberg.org/minenux/minetest-mod-regrow * ethereal as `ethereal` [mods/ethereal](mods/ethereal) from https://codeberg.org/minenux/minetest-mod-ethereal - * toolranks as `toolranks` [mods/toolranks](mods/toolranks) from https://codeberg.org/minenux/minetest-mod-toolranks + * toolranks as `toolranks` [mods/toolranks](mods/toolranks) (reduced) from https://codeberg.org/minenux/minetest-mod-toolranks * armors and stuff mods * 3d_armor and shields [mods/3d_armor](mods/3d_armor) https://codeberg.org/minenux/minetest-mod-3d_armor * player stuffs: diff --git a/mods/farming/hoes.lua b/mods/farming/hoes.lua index 5aae390..340bf45 100644 --- a/mods/farming/hoes.lua +++ b/mods/farming/hoes.lua @@ -1,3 +1,8 @@ +local use_toolranks = minetest.get_modpath("toolranks") or false +local use_extratoolranks = minetest.get_modpath("toolranks_extra") or false + +local use_tr = (use_toolranks and (not use_extratoolranks)) or false + farming.register_hoe(":farming:hoe_wood", { description = "Wooden Hoe", inventory_image = "farming_tool_woodhoe.png", @@ -5,6 +10,7 @@ farming.register_hoe(":farming:hoe_wood", { material = "group:wood", groups = {flammable = 2}, }) +if use_tr then farming.add_hoe("farming:hoe_wood") end farming.register_hoe(":farming:hoe_stone", { description = "Stone Hoe", @@ -12,6 +18,7 @@ farming.register_hoe(":farming:hoe_stone", { max_uses = 90, material = "group:stone" }) +if use_tr then farming.add_hoe("farming:hoe_stone") end farming.register_hoe(":farming:hoe_steel", { description = "Steel Hoe", @@ -19,6 +26,7 @@ farming.register_hoe(":farming:hoe_steel", { max_uses = 200, material = "default:steel_ingot" }) +if use_tr then farming.add_hoe("farming:hoe_steel") end farming.register_hoe(":farming:hoe_bronze", { description = "Bronze Hoe", @@ -26,6 +34,7 @@ farming.register_hoe(":farming:hoe_bronze", { max_uses = 220, material = "default:bronze_ingot" }) +if use_tr then farming.add_hoe("farming:hoe_bronze") end farming.register_hoe(":farming:hoe_mese", { description = "Mese Hoe", @@ -33,6 +42,7 @@ farming.register_hoe(":farming:hoe_mese", { max_uses = 350, material = "default:mese_crystal" }) +if use_tr then farming.add_hoe("farming:hoe_mese") end farming.register_hoe(":farming:hoe_diamond", { description = "Diamond Hoe", @@ -40,3 +50,4 @@ farming.register_hoe(":farming:hoe_diamond", { max_uses = 500, material = "default:diamond" }) +if use_tr then farming.add_hoe("farming:hoe_diamond") end diff --git a/mods/farming/init.lua b/mods/farming/init.lua index fff48fa..da649ae 100644 --- a/mods/farming/init.lua +++ b/mods/farming/init.lua @@ -4,13 +4,53 @@ farming = {} farming.path = minetest.get_modpath("farming") +-- toolranks support +if minetest.get_modpath("toolranks") then + function farming.add_hoe(material) + -- registering as tool + local name = material + toolranks.add_tool(material) + + -- 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, { + -- we also want hoes to increase dugnodes when farming soil + on_use = function(itemstack, user, pointed_thing, uses) + -- if no node is pointed, the hoe cannot be used + if pointed_thing.under == nil then + return nil + end + 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) + 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 + }) + end +end + -- Load files dofile(farming.path .. "/api.lua") dofile(farming.path .. "/nodes.lua") dofile(farming.path .. "/hoes.lua") - -- WHEAT farming.register_plant("farming:wheat", { diff --git a/mods/toolranks/mod.conf b/mods/toolranks/mod.conf index b1341b9..59abf23 100644 --- a/mods/toolranks/mod.conf +++ b/mods/toolranks/mod.conf @@ -1,4 +1,4 @@ name = toolranks depends = -optional_depens = default +optional_depends = default description = TOOL gains levels for digging nodes. Higher level take longer to wear out