try to fix a visual bug when adjusting max level in config
This commit is contained in:
@@ -81,11 +81,12 @@ public class StatsScreen extends Screen {
|
|||||||
if (mc.player != null) {
|
if (mc.player != null) {
|
||||||
mc.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
mc.player.getCapability(PlayerStatsProvider.PLAYER_STATS).ifPresent(stats -> {
|
||||||
int level = stats.getAscendLevel();
|
int level = stats.getAscendLevel();
|
||||||
|
int maxLevel = stats.getMaxAscendLevel();
|
||||||
int xp = stats.getAscendXP();
|
int xp = stats.getAscendXP();
|
||||||
int xpNext = stats.getXPToNextAscendLevel();
|
int xpNext = stats.getXPToNextAscendLevel();
|
||||||
int unspent = stats.getUnspentPoints();
|
int unspent = stats.getUnspentPoints();
|
||||||
gui.drawString(font, Component.translatable("ascend.stats.level", level, 20), leftPos + 10, topPos + 28, 0xFFE27D);
|
gui.drawString(font, Component.translatable("ascend.stats.level", level, maxLevel), leftPos + 10, topPos + 28, 0xFFE27D);
|
||||||
if (level < 20) {
|
if (level < maxLevel) {
|
||||||
gui.drawString(font, Component.translatable("ascend.stats.xp", xp, xpNext), leftPos + 10, topPos + 40, 0xB4B4C8);
|
gui.drawString(font, Component.translatable("ascend.stats.xp", xp, xpNext), leftPos + 10, topPos + 40, 0xB4B4C8);
|
||||||
} else {
|
} else {
|
||||||
gui.drawString(font, Component.translatable("ascend.stats.xp_max"), leftPos + 10, topPos + 40, 0xB4B4C8);
|
gui.drawString(font, Component.translatable("ascend.stats.xp_max"), leftPos + 10, topPos + 40, 0xB4B4C8);
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ public class PlayerStats {
|
|||||||
private int ascendLevel = 1;
|
private int ascendLevel = 1;
|
||||||
private int ascendXP = 0;
|
private int ascendXP = 0;
|
||||||
private int unspentPoints = getPointsPerLevel();
|
private int unspentPoints = getPointsPerLevel();
|
||||||
|
private int maxAscendLevel = getConfiguredMaxAscendLevel();
|
||||||
|
private int maxAttributePoints = getConfiguredMaxAttributePoints();
|
||||||
public PlayerStats() {
|
public PlayerStats() {
|
||||||
for (String attr : ATTRIBUTE_KEYS) {
|
for (String attr : ATTRIBUTE_KEYS) {
|
||||||
attributes.put(attr, 0);
|
attributes.put(attr, 0);
|
||||||
@@ -86,6 +88,14 @@ public class PlayerStats {
|
|||||||
return attributes.getOrDefault(attribute, 0);
|
return attributes.getOrDefault(attribute, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMaxAscendLevel() {
|
||||||
|
return maxAscendLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxAttributePoints() {
|
||||||
|
return maxAttributePoints;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAttributeLevel(String attribute, int level) {
|
public void setAttributeLevel(String attribute, int level) {
|
||||||
if (!attributes.containsKey(attribute)) return;
|
if (!attributes.containsKey(attribute)) return;
|
||||||
int clamped = Math.max(0, Math.min(level, getMaxAttributePoints()));
|
int clamped = Math.max(0, Math.min(level, getMaxAttributePoints()));
|
||||||
@@ -145,6 +155,8 @@ public class PlayerStats {
|
|||||||
tag.putInt("AscendLevel", ascendLevel);
|
tag.putInt("AscendLevel", ascendLevel);
|
||||||
tag.putInt("AscendXP", ascendXP);
|
tag.putInt("AscendXP", ascendXP);
|
||||||
tag.putInt("UnspentPoints", unspentPoints);
|
tag.putInt("UnspentPoints", unspentPoints);
|
||||||
|
tag.putInt("MaxAscendLevel", getMaxAscendLevel());
|
||||||
|
tag.putInt("MaxAttributePoints", getMaxAttributePoints());
|
||||||
tag.putInt("Knowledge", knowledge);
|
tag.putInt("Knowledge", knowledge);
|
||||||
tag.putBoolean("HasUsedMoonseye", hasUsedMoonseye);
|
tag.putBoolean("HasUsedMoonseye", hasUsedMoonseye);
|
||||||
CompoundTag attrTag = new CompoundTag();
|
CompoundTag attrTag = new CompoundTag();
|
||||||
@@ -156,6 +168,12 @@ public class PlayerStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void deserializeNBT(CompoundTag tag) {
|
public void deserializeNBT(CompoundTag tag) {
|
||||||
|
maxAscendLevel = tag.contains("MaxAscendLevel")
|
||||||
|
? Math.max(1, tag.getInt("MaxAscendLevel"))
|
||||||
|
: getConfiguredMaxAscendLevel();
|
||||||
|
maxAttributePoints = tag.contains("MaxAttributePoints")
|
||||||
|
? Math.max(1, tag.getInt("MaxAttributePoints"))
|
||||||
|
: getConfiguredMaxAttributePoints();
|
||||||
ascendLevel = tag.contains("AscendLevel") ? tag.getInt("AscendLevel") : 1;
|
ascendLevel = tag.contains("AscendLevel") ? tag.getInt("AscendLevel") : 1;
|
||||||
ascendLevel = Math.max(1, Math.min(ascendLevel, getMaxAscendLevel()));
|
ascendLevel = Math.max(1, Math.min(ascendLevel, getMaxAscendLevel()));
|
||||||
ascendXP = tag.contains("AscendXP") ? tag.getInt("AscendXP") : 0;
|
ascendXP = tag.contains("AscendXP") ? tag.getInt("AscendXP") : 0;
|
||||||
@@ -187,11 +205,11 @@ public class PlayerStats {
|
|||||||
return AscendConfig.COMMON.pointsPerLevel.get();
|
return AscendConfig.COMMON.pointsPerLevel.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMaxAscendLevel() {
|
private static int getConfiguredMaxAscendLevel() {
|
||||||
return AscendConfig.COMMON.maxAscendLevel.get();
|
return AscendConfig.COMMON.maxAscendLevel.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getMaxAttributePoints() {
|
private static int getConfiguredMaxAttributePoints() {
|
||||||
return AscendConfig.COMMON.maxAttributePoints.get();
|
return AscendConfig.COMMON.maxAttributePoints.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user