From 49c8ba189256f9ebed12b0ec08edfafc5a7597f7 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 3 Jul 2024 08:27:07 +0100 Subject: [PATCH] fix mithril scythe node naming --- hoes.lua | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/hoes.lua b/hoes.lua index b548197..9618472 100644 --- a/hoes.lua +++ b/hoes.lua @@ -350,7 +350,22 @@ minetest.register_craftitem("farming:hoe_bomb", { end, }) --- Mithril Scythe (special item) +-- helper function + +local function node_not_num(nodename) + + local num = #nodename:split("_") + local str = "" + + if not num or num == 1 then return end + + for v = 1, (num - 1) do + bit = nodename:split("_")[v] + str = str .. nodename:split("_")[v] .. "_" + end + + return str +end farming.scythe_not_drops = {"farming:trellis", "farming:beanpole"} @@ -358,6 +373,8 @@ farming.add_to_scythe_not_drops = function(item) table.insert(farming.scythe_not_drops, item) end +-- Mithril Scythe (special item) + minetest.register_tool("farming:scythe_mithril", { description = S("Mithril Scythe (Use to harvest and replant crops)"), inventory_image = "farming_scythe_mithril.png", @@ -396,12 +413,9 @@ minetest.register_tool("farming:scythe_mithril", { -- get crop name local mname = node.name:split(":")[1] - local pname = node.name:split(":")[2] - local sname = tonumber(pname:split("_")[2]) + local pname = node_not_num(node.name:split(":")[2]) - pname = pname:split("_")[1] - - if not sname then + if not pname then return end @@ -439,7 +453,8 @@ minetest.register_tool("farming:scythe_mithril", { -- play sound minetest.sound_play("default_grass_footstep", {pos = pos, gain = 1.0}, true) - local replace = mname .. ":" .. pname .. "_1" + -- replace with seed or crop_1 + local replace = mname .. ":" .. pname .. "1" if minetest.registered_nodes[replace] then