Bug fix in tooltips for unknown items (#4610)

Reviewed-on: VoxeLibre/VoxeLibre#4610
Reviewed-by: Mikita Wiśniewski <rudzik8@protonmail.com>
Co-authored-by: kno10 <erich.schubert@gmail.com>
Co-committed-by: kno10 <erich.schubert@gmail.com>
This commit is contained in:
kno10 2024-08-31 10:18:12 +02:00 committed by the-real-herowl
parent 12214c5bd6
commit 573269afab
2 changed files with 8 additions and 28 deletions

View File

@ -20,23 +20,12 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua")
-- Apply item description updates -- Apply item description updates
local function apply_snippets(desc, itemstring, toolcaps, itemstack) local function apply_snippets(desc, itemstring, toolcaps, itemstack)
local first = true
-- Apply snippets -- Apply snippets
for s=1, #tt.registered_snippets do for s=1, #tt.registered_snippets do
local str, snippet_color = tt.registered_snippets[s](itemstring, toolcaps, itemstack) local str, snippet_color = tt.registered_snippets[s](itemstring, toolcaps, itemstack)
if snippet_color == nil then
snippet_color = tt.COLOR_DEFAULT
end
if str then if str then
if first then if snippet_color == nil then snippet_color = tt.COLOR_DEFAULT end
first = false desc = desc .. "\n" .. (snippet_color and minetest.colorize(snippet_color, str) or str)
end
desc = desc .. "\n"
if snippet_color then
desc = desc .. minetest.colorize(snippet_color, str)
else
desc = desc .. str
end
end end
end end
return desc return desc
@ -67,10 +56,7 @@ function tt.reload_itemstack_description(itemstack)
if def and def._mcl_generate_description then if def and def._mcl_generate_description then
def._mcl_generate_description(itemstack) def._mcl_generate_description(itemstack)
elseif should_change(itemstring, def) then elseif should_change(itemstring, def) then
local toolcaps local toolcaps = def.tool_capabilities and itemstack:get_tool_capabilities()
if def.tool_capabilities then
toolcaps = itemstack:get_tool_capabilities()
end
local orig_desc = def._tt_original_description or def.description local orig_desc = def._tt_original_description or def.description
if meta:get_string("name") ~= "" then if meta:get_string("name") ~= "" then
orig_desc = minetest.colorize(tt.NAME_COLOR, meta:get_string("name")) orig_desc = minetest.colorize(tt.NAME_COLOR, meta:get_string("name"))
@ -78,17 +64,13 @@ function tt.reload_itemstack_description(itemstack)
local potency = meta:get_int("mcl_potions:potion_potent") local potency = meta:get_int("mcl_potions:potion_potent")
local plus = meta:get_int("mcl_potions:potion_plus") local plus = meta:get_int("mcl_potions:potion_plus")
if potency > 0 then if potency > 0 then
local sym_potency = mcl_util.to_roman(potency+1) orig_desc = orig_desc .. " " .. mcl_util.to_roman(potency+1)
orig_desc = orig_desc.. " ".. sym_potency
end end
if plus > 0 then if plus > 0 then
local sym_plus = " " orig_desc = orig_desc .. " "
local i = plus for i = 1, plus do
while i>0 do orig_desc = orig_desc .. "+"
i = i - 1
sym_plus = sym_plus.. "+"
end end
orig_desc = orig_desc.. sym_plus
end end
end end
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack) local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)

View File

@ -3,9 +3,7 @@
-- Custom text (_tt_help) -- Custom text (_tt_help)
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if def._tt_help then return def and def._tt_help or nil
return def._tt_help
end
end) end)