From 573269afab774756530d57393e5884be58c40a54 Mon Sep 17 00:00:00 2001 From: kno10 Date: Sat, 31 Aug 2024 10:18:12 +0200 Subject: [PATCH] Bug fix in tooltips for unknown items (#4610) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4610 Reviewed-by: Mikita Wiśniewski Co-authored-by: kno10 Co-committed-by: kno10 --- mods/HELP/tt/init.lua | 32 +++++++------------------------- mods/HELP/tt/snippets.lua | 4 +--- 2 files changed, 8 insertions(+), 28 deletions(-) diff --git a/mods/HELP/tt/init.lua b/mods/HELP/tt/init.lua index 8cc893d47..eba65c22a 100644 --- a/mods/HELP/tt/init.lua +++ b/mods/HELP/tt/init.lua @@ -20,23 +20,12 @@ dofile(minetest.get_modpath(minetest.get_current_modname()).."/snippets.lua") -- Apply item description updates local function apply_snippets(desc, itemstring, toolcaps, itemstack) - local first = true -- Apply snippets for s=1, #tt.registered_snippets do 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 first then - first = false - end - desc = desc .. "\n" - if snippet_color then - desc = desc .. minetest.colorize(snippet_color, str) - else - desc = desc .. str - end + if snippet_color == nil then snippet_color = tt.COLOR_DEFAULT end + desc = desc .. "\n" .. (snippet_color and minetest.colorize(snippet_color, str) or str) end end return desc @@ -67,10 +56,7 @@ function tt.reload_itemstack_description(itemstack) if def and def._mcl_generate_description then def._mcl_generate_description(itemstack) elseif should_change(itemstring, def) then - local toolcaps - if def.tool_capabilities then - toolcaps = itemstack:get_tool_capabilities() - end + local toolcaps = def.tool_capabilities and itemstack:get_tool_capabilities() local orig_desc = def._tt_original_description or def.description if meta:get_string("name") ~= "" then 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 plus = meta:get_int("mcl_potions:potion_plus") if potency > 0 then - local sym_potency = mcl_util.to_roman(potency+1) - orig_desc = orig_desc.. " ".. sym_potency + orig_desc = orig_desc .. " " .. mcl_util.to_roman(potency+1) end if plus > 0 then - local sym_plus = " " - local i = plus - while i>0 do - i = i - 1 - sym_plus = sym_plus.. "+" + orig_desc = orig_desc .. " " + for i = 1, plus do + orig_desc = orig_desc .. "+" end - orig_desc = orig_desc.. sym_plus end end local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack) diff --git a/mods/HELP/tt/snippets.lua b/mods/HELP/tt/snippets.lua index 694b22513..69956385e 100644 --- a/mods/HELP/tt/snippets.lua +++ b/mods/HELP/tt/snippets.lua @@ -3,9 +3,7 @@ -- Custom text (_tt_help) tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] - if def._tt_help then - return def._tt_help - end + return def and def._tt_help or nil end)