From 5dc4929cfdf30097ea19880093fb91955cac13a4 Mon Sep 17 00:00:00 2001 From: SpaghettiToastBook Date: Sun, 30 Dec 2018 04:11:55 -0500 Subject: [PATCH] Use farming mod's API to register hoes --- depends.txt | 1 + init.lua | 128 ++++++++++++++++++++++------------------------------ 2 files changed, 55 insertions(+), 74 deletions(-) diff --git a/depends.txt b/depends.txt index 0219052..d3401e0 100644 --- a/depends.txt +++ b/depends.txt @@ -1,2 +1,3 @@ default +farming? mg? diff --git a/init.lua b/init.lua index 0a85392..04b5112 100644 --- a/init.lua +++ b/init.lua @@ -37,37 +37,6 @@ end local default_stone_sounds = default.node_sound_stone_defaults() local default_metal_sounds = default.node_sound_metal_defaults() -local function hoe_on_use(itemstack, user, pointed_thing, uses) - local pt = pointed_thing - -- Check if pointing at a node: - if not pt then - return - end - if pt.type ~= "node" then - return - end - - local under = minetest.get_node(pt.under) - local pos = {x = pt.under.x, y = pt.under.y + 1, z = pt.under.z} - local above = minetest.get_node(pos) - - -- Return if any of the nodes is not registered: - if not minetest.registered_nodes[under.name] then return end - if not minetest.registered_nodes[above.name] then return end - - -- Check if the node above the pointed thing is air: - if above.name ~= "air" then return end - - -- Check if pointing at dirt: - if minetest.get_item_group(under.name, "soil") ~= 1 then return end - - -- Turn the node into soil, wear out item and play sound: - minetest.set_node(pt.under, {name ="farming:soil"}) - minetest.sound_play("default_dig_crumbly", {pos = pt.under, gain = 0.5}) - itemstack:add_wear(65535 / (uses - 1)) - return itemstack -end - local function get_recipe(c, name) if name == "sword" then return {{c}, {c}, {"group:stick"}} @@ -188,50 +157,61 @@ local function add_ore(modname, description, mineral_name, oredef) }, sound = {breaks = "default_tool_breaks"}, } - - if tool_name == "sword" then - tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval - tdef.tool_capabilities.damage_groups = oredef.damage_groups - tdef.description = S("%s Sword"):format(S(description)) - end - - if tool_name == "pick" then - tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval - tdef.tool_capabilities.damage_groups = oredef.damage_groups - tdef.description = S("%s Pickaxe"):format(S(description)) - end - - if tool_name == "axe" then - tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval - tdef.tool_capabilities.damage_groups = oredef.damage_groups - tdef.description = S("%s Axe"):format(S(description)) - end - - if tool_name == "shovel" then - tdef.full_punch_interval = oredef.full_punch_interval - tdef.tool_capabilities.damage_groups = oredef.damage_groups - tdef.description = S("%s Shovel"):format(S(description)) - tdef.wield_image = toolimg_base .. tool_name .. ".png^[transformR90" - end - - if tool_name == "hoe" then - tdef.description = S("%s Hoe"):format(S(description)) - local uses = tooldef.uses - tooldef.uses = nil - tdef.on_use = function(itemstack, user, pointed_thing) - return hoe_on_use(itemstack, user, pointed_thing, uses) - end - end - + local fulltool_name = tool_base .. tool_name .. tool_post - minetest.register_tool(fulltool_name, tdef) - minetest.register_alias(tool_name .. tool_post, fulltool_name) - if oredef.makes.ingot then - minetest.register_craft({ - output = fulltool_name, - recipe = get_recipe(ingot, tool_name) - }) - end + + if tool_name == "hoe" and minetest.get_modpath("farming") then + local uses = tooldef.uses + tooldef.uses = nil + + tdef.max_uses = uses + tdef.description = S("%s Hoe"):format(S(description)) + + farming.register_hoe(fulltool_name, tdef) + minetest.register_alias(tool_name .. tool_post, fulltool_name) + + if oredef.makes.ingot then + minetest.register_craft({ + output = fulltool_name, + recipe = get_recipe(ingot, tool_name) + }) + end + + else + if tool_name == "sword" then + tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval + tdef.tool_capabilities.damage_groups = oredef.damage_groups + tdef.description = S("%s Sword"):format(S(description)) + end + + if tool_name == "pick" then + tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval + tdef.tool_capabilities.damage_groups = oredef.damage_groups + tdef.description = S("%s Pickaxe"):format(S(description)) + end + + if tool_name == "axe" then + tdef.tool_capabilities.full_punch_interval = oredef.full_punch_interval + tdef.tool_capabilities.damage_groups = oredef.damage_groups + tdef.description = S("%s Axe"):format(S(description)) + end + + if tool_name == "shovel" then + tdef.full_punch_interval = oredef.full_punch_interval + tdef.tool_capabilities.damage_groups = oredef.damage_groups + tdef.description = S("%s Shovel"):format(S(description)) + tdef.wield_image = toolimg_base .. tool_name .. ".png^[transformR90" + end + + minetest.register_tool(fulltool_name, tdef) + minetest.register_alias(tool_name .. tool_post, fulltool_name) + if oredef.makes.ingot then + minetest.register_craft({ + output = fulltool_name, + recipe = get_recipe(ingot, tool_name) + }) + end + end end end