Minetest_Game_Mushroom_Fork/mods/specific to Mushroom Fork/runes/debug.lua

38 lines
1.6 KiB
Lua

minetest.register_chatcommand("updatetool", {
description = "Fix a shovel or sword that has the debug buff.",
func = function(name, arg)
local player = minetest.get_player_by_name(name)
local tool = player:get_wielded_item()
local tool_type = tool:get_name()
local meta = tool:get_meta()
-- Currently, a feature in the stable version but not the development
-- version of Minetest prevents setting the value to integer zero from
-- working correctly, but setting to string zero should work just fine.
local debug_level = tonumber(meta:get_string("debug"))
if debug_level then
if tool_type == "runes:shovel" then
meta:set_string("thirst", debug_level)
meta:set_string("debug") -- set to nil to remove key/value pair
local description = minetest.registered_tools["runes:shovel"].description.."\nRepair count: "..meta:get_int("repair").."\nThirst ("..debug_level..")"
meta:set_string("description", description)
player:set_wielded_item(tool)
elseif tool_type == "runes:sword" then
local thirst = math.ceil((debug_level - 1) / 2)
local pruner = math.floor((debug_level - 1) / 2)
local description = minetest.registered_tools["runes:shovel"].description.."\nRepair count: "..meta:get_int("repair")
if thirst > -1 then
meta:set_string("thirst", thirst)
description = description.."\nThirst ("..thirst..")"
end
if pruner > -1 then
meta:set_string("pruner", pruner)
description = description.."\nPruner ("..pruner..")"
end
meta:set_string("debug") -- set to nil to remove key/value pair
meta:set_string("description", description)
player:set_wielded_item(tool)
end
end
end,
})