fix mithril scythe node naming

This commit is contained in:
tenplus1 2024-07-03 08:27:07 +01:00
parent 5c050f3516
commit 49c8ba1892

View File

@ -350,7 +350,22 @@ minetest.register_craftitem("farming:hoe_bomb", {
end, 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"} 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) table.insert(farming.scythe_not_drops, item)
end end
-- Mithril Scythe (special item)
minetest.register_tool("farming:scythe_mithril", { minetest.register_tool("farming:scythe_mithril", {
description = S("Mithril Scythe (Use to harvest and replant crops)"), description = S("Mithril Scythe (Use to harvest and replant crops)"),
inventory_image = "farming_scythe_mithril.png", inventory_image = "farming_scythe_mithril.png",
@ -396,12 +413,9 @@ minetest.register_tool("farming:scythe_mithril", {
-- get crop name -- get crop name
local mname = node.name:split(":")[1] local mname = node.name:split(":")[1]
local pname = node.name:split(":")[2] local pname = node_not_num(node.name:split(":")[2])
local sname = tonumber(pname:split("_")[2])
pname = pname:split("_")[1] if not pname then
if not sname then
return return
end end
@ -439,7 +453,8 @@ minetest.register_tool("farming:scythe_mithril", {
-- play sound -- play sound
minetest.sound_play("default_grass_footstep", {pos = pos, gain = 1.0}, true) 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 if minetest.registered_nodes[replace] then