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
parent e0ed82e456
commit 4d258731eb
2 changed files with 48 additions and 27 deletions

View File

@ -126,6 +126,7 @@ 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
if effects then
local effect local effect
local dur local dur
local timestamp local timestamp
@ -153,8 +154,9 @@ tt.register_snippet(function(itemstring, _, itemstack)
else roman_lvl = "" end else roman_lvl = "" end
s = s.. effect.description.. roman_lvl.. " (".. timestamp.. ")\n" s = s.. effect.description.. roman_lvl.. " (".. timestamp.. ")\n"
if effect.uses_factor then factor = effect.level_to_factor(ef_level) end 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 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 if ef_tt ~= "" then s = s.. ef_tt.. "\n" end
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"))