From 209ddbb97296a0e9c0c5243b58c6c42f039b9244 Mon Sep 17 00:00:00 2001 From: Sollace Date: Sat, 13 Feb 2021 19:24:25 +0200 Subject: [PATCH] Fixed page count not being computed correctly when first joining a world --- .../unicopia/ability/AbilityDispatcher.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java index 398adf2b..65a243b5 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/AbilityDispatcher.java @@ -30,7 +30,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { @Nullable private Race prevRace; - private long maxPage; + private long maxPage = -1; public AbilityDispatcher(Pony player) { this.player = player; @@ -39,6 +39,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { public void clear(AbilitySlot slot) { Stat stat = getStat(slot); + if (stat.canSwitchStates()) { stat.setActiveAbility(null); } @@ -61,9 +62,12 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable { } public long getMaxPage() { - if (prevRace != player.getSpecies()) { + if (maxPage < 0 || prevRace != player.getSpecies()) { prevRace = player.getSpecies(); - maxPage = Math.max(0, stats.values().stream().mapToLong(Stat::getMaxPage).reduce(0, Math::max) - 1); + maxPage = 0; + for (AbilitySlot slot : AbilitySlot.values()) { + maxPage = Math.max(maxPage, getStat(slot).getMaxPage() - 1); + } } return maxPage; }