Improved potion descriptions

* added support for effect descriptions
* added descriptions for some effects
* fixed a crash
This commit is contained in:
the-real-herowl 2024-01-07 22:54:10 +01:00 committed by the-real-herowl
parent 9251cc1583
commit 3a81ce7733
2 changed files with 48 additions and 27 deletions

View File

@ -126,35 +126,37 @@ tt.register_snippet(function(itemstring, _, itemstack)
local plus = meta:get_int("mcl_potions:potion_plus") local plus = meta:get_int("mcl_potions:potion_plus")
if def._dynamic_tt then s = s.. def._dynamic_tt(potency+1).. "\n" end if def._dynamic_tt then s = s.. def._dynamic_tt(potency+1).. "\n" end
local effects = def._effect_list local effects = def._effect_list
local effect if effects then
local dur local effect
local timestamp local dur
local ef_level local timestamp
local roman_lvl local ef_level
local factor local roman_lvl
local ef_tt local factor
for name, details in pairs(effects) do local ef_tt
effect = mcl_potions.registered_effects[name] for name, details in pairs(effects) do
if details.dur_variable then effect = mcl_potions.registered_effects[name]
dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus) if details.dur_variable then
if potency > 0 and details.uses_level then dur = details.dur * math.pow(mcl_potions.PLUS_FACTOR, plus)
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency) if potency > 0 and details.uses_level then
dur = dur / math.pow(mcl_potions.POTENT_FACTOR, potency)
end
else
dur = details.dur
end end
else timestamp = math.floor(dur/60)..string.format(":%02d",math.floor(dur % 60))
dur = details.dur 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 = minetest.colorize("grey", effect.get_tt(factor)) else ef_tt = "" end
if ef_tt ~= "" then s = s.. ef_tt.. "\n" end
end 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 end
return s:trim() return s:trim()
end) end)

View File

@ -165,6 +165,9 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "poison", name = "poison",
description = S("Poison"), description = S("Poison"),
get_tt = function(factor)
return S("-1 HP / @1 s", factor)
end,
res_condition = function(object) res_condition = function(object)
local entity = object:get_luaentity() local entity = object:get_luaentity()
return (entity and (entity.harmed_by_heal or string.find(entity.name, "spider"))) return (entity and (entity.harmed_by_heal or string.find(entity.name, "spider")))
@ -184,6 +187,9 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "regeneration", name = "regeneration",
description = S("Regeneration"), description = S("Regeneration"),
get_tt = function(factor)
return S("+1 HP / @1 s", factor)
end,
res_condition = function(object) res_condition = function(object)
local entity = object:get_luaentity() local entity = object:get_luaentity()
return (entity and entity.harmed_by_heal) return (entity and entity.harmed_by_heal)
@ -238,6 +244,10 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "leaping", name = "leaping",
description = S("Leaping"), description = S("Leaping"),
get_tt = function(factor)
if factor > 0 then return S("+@1% jumping power", math.floor(factor*100)) end
return S("-@1% jumping power", math.floor(-factor*100))
end,
res_condition = function(object) res_condition = function(object)
return (not object:is_player()) return (not object:is_player())
end, end,
@ -256,6 +266,9 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "swiftness", name = "swiftness",
description = S("Swiftness"), description = S("Swiftness"),
get_tt = function(factor)
return S("+@1% running speed", math.floor(factor*100))
end,
res_condition = function(object) res_condition = function(object)
return (not object:is_player()) return (not object:is_player())
end, end,
@ -274,6 +287,9 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "slowness", name = "slowness",
description = S("Slowness"), description = S("Slowness"),
get_tt = function(factor)
return S("-@1% running speed", math.floor(factor*100))
end,
res_condition = function(object) res_condition = function(object)
return (not object:is_player()) return (not object:is_player())
end, end,
@ -331,6 +347,9 @@ mcl_potions.register_effect({
mcl_potions.register_effect({ mcl_potions.register_effect({
name = "withering", name = "withering",
description = S("Withering"), description = S("Withering"),
get_tt = function(factor)
return S("-1 HP / @1 s, can kill", factor)
end,
res_condition = function(object) res_condition = function(object)
local entity = object:get_luaentity() local entity = object:get_luaentity()
return (entity and string.find(entity.name, "wither")) return (entity and string.find(entity.name, "wither"))