From fe1c8ca7581bc094b402815bff10dd0367b58429 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Fri, 23 Oct 2020 23:16:46 +0200 Subject: [PATCH] Hard-cap XP at 2^31-1 --- mods/HUD/mcl_experience/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/HUD/mcl_experience/init.lua b/mods/HUD/mcl_experience/init.lua index f0560ab7b..c70bcee12 100644 --- a/mods/HUD/mcl_experience/init.lua +++ b/mods/HUD/mcl_experience/init.lua @@ -2,6 +2,7 @@ local S = minetest.get_translator("mcl_experience") mcl_experience = {} local pool = {} local registered_nodes +local max_xp = 2^31-1 local gravity = {x = 0, y = -((tonumber(minetest.settings:get("movement_gravity"))) or 9.81), z = 0} local size_min, size_max = 20, 59 -- percents @@ -235,7 +236,7 @@ function mcl_experience.add_experience(player, experience) local temp_pool = pool[name] local old_bar, old_xp, old_level = temp_pool.bar, temp_pool.xp, temp_pool.level - temp_pool.xp = math.max(temp_pool.xp + experience, 0) + temp_pool.xp = math.min(math.max(temp_pool.xp + experience, 0), max_xp) temp_pool.level = mcl_experience.xp_to_level(temp_pool.xp) temp_pool.bar, temp_pool.xp_next_level = mcl_experience.xp_to_bar(temp_pool.xp, temp_pool.level) if old_level ~= temp_pool.level then