1
0
Fork 0

Added new potion tooltip handling

-potion tooltips are now utilizing the power of the new API
-potion names change based on metadata
-nothing triggers loading the new tooltips beyond the names for now
This commit is contained in:
the-real-herowl 2023-10-27 05:08:23 +02:00
parent 9383b903ef
commit ef2ce7e0d7
4 changed files with 64 additions and 2 deletions

View File

@ -1,4 +1,4 @@
name = mcl_tt
author = Wuzzy
description = Add MCL2 tooltips
depends = tt, mcl_enchanting, mcl_colors
depends = tt, mcl_enchanting, mcl_colors, mcl_util

View File

@ -121,3 +121,49 @@ tt.register_snippet(function(itemstring, _, itemstack)
return S("Durability: @1", S("@1 uses", remaining_use .."/".. use))
end
end)
-- Potions info
tt.register_snippet(function(itemstring, _, itemstack)
if not itemstack then return end
local def = itemstack:get_definition()
if def.groups._mcl_potion ~= 1 then return end
local s = ""
local meta = itemstack:get_meta()
local potency = meta:get_int("mcl_potions:potion_potent")
local plus = meta:get_int("mcl_potions:potion_plus")
if def._dynamic_tt then s = s.. def._dynamic_tt(potency+1).. "\n" end
local effects = def._effect_list
local effect
local dur
local timestamp
local ef_level
local roman_lvl
local factor
local ef_tt
for name, details in pairs(effects) do
effect = mcl_potions.registered_effects[name]
if details.dur_variable then
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
if potency > 0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end
timestamp = math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))
if details.uses_level then
ef_level = details.level + details.level_scaling * (potency)
else
ef_level = details.level
end
if ef_level > 1 then roman_lvl = " ".. mcl_util.to_roman(ef_level)
else roman_lvl = "" end
s = s.. effect.description.. roman_lvl.. " (".. timestamp.. ")\n"
if effect.uses_factor then factor = effect.level_to_factor(ef_level) end
if effect.get_tt then ef_tt = effect.get_tt(factor) else ef_tt = "" end
if ef_tt ~= "" then s = s.. ef_tt.. "\n" end
end
return s:trim()
end)

View File

@ -74,6 +74,22 @@ function tt.reload_itemstack_description(itemstack)
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"))
elseif def.groups._mcl_potion == 1 then
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
end
if plus > 0 then
local sym_plus = " "
local i = plus
while i>0 do
i = i - 1
sym_plus = sym_plus.. "+"
end
orig_desc = orig_desc.. sym_plus
end
end
local desc = apply_snippets(orig_desc, itemstring, toolcaps or def.tool_capabilities, itemstack)
if desc == def.description and meta:get_string("description") == "" then return end

View File

@ -1,4 +1,4 @@
name = tt
author = Wuzzy
description = Support for custom tooltip extensions for items
depends = mcl_colors
depends = mcl_colors, mcl_util