Skip to content

Commit

Permalink
fix: 🐛 Fix hero medallion to properly work out how much total experie…
Browse files Browse the repository at this point in the history
…nce player actually has based on level and progress and no longer rely on totalExperience that doesn't seem to be properly updated by mc
  • Loading branch information
P3pp3rF1y committed Dec 26, 2023
1 parent b9ceaa8 commit 19a1664
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
org.gradle.jvmargs=-Xmx2048m
minecraft_version=1.20.1
forge_version=47.1.5
mod_version=2.0.36
mod_version=2.0.37
jei_mc_version=1.20.1-forge
jei_version=15.1.0.19
curios_version=5.2.0-beta.3+1.20.1
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/reliquary/items/HeroMedallionItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void inventoryTick(ItemStack stack, Level world, Entity entity, int itemS
}

private void drainExperienceLevel(ItemStack stack, Player player) {
int experiencePoints = player.isCreative() ? 100 : player.totalExperience - XpHelper.getExperienceForLevel(Math.max(getStopAtXpLevel(stack), player.experienceLevel - 1));
int experiencePoints = player.isCreative() ? 100 : XpHelper.getTotalPlayerExperience(player) - XpHelper.getExperienceForLevel(Math.max(getStopAtXpLevel(stack), player.experienceLevel - 1));
if (experiencePoints > 0) {
if (!player.isCreative()) {
decreasePlayerExperience(player, experiencePoints);
Expand All @@ -104,7 +104,7 @@ private void drainExperienceLevel(ItemStack stack, Player player) {
}

private void decreasePlayerExperience(Player player, int pointsToRemove) {
player.totalExperience -= pointsToRemove;
player.totalExperience = XpHelper.getTotalPlayerExperience(player) - pointsToRemove;
int newLevel = XpHelper.getLevelForExperience(player.totalExperience);
player.experienceLevel = newLevel;
player.experienceProgress = (float) (player.totalExperience - XpHelper.getExperienceForLevel(newLevel)) / player.getXpNeededForNextLevel();
Expand Down Expand Up @@ -153,7 +153,7 @@ private void drainExperience(ItemStack stack, Player player, Level level, int xp
spawnXpOnGround(stack, level, hitPos, xpLevels);
} else {
xpLevels += Math.round(player.experienceProgress);
int maxPoints = XpHelper.getExperienceForLevel(player.experienceLevel + xpLevels) - player.totalExperience;
int maxPoints = XpHelper.getExperienceForLevel(player.experienceLevel + xpLevels) - XpHelper.getTotalPlayerExperience(player);
int pointsToAdd = player.isCreative() ? maxPoints : Math.min(maxPoints, getExperience(stack));
increasePlayerExperience(player, pointsToAdd);
if (!player.isCreative()) {
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/reliquary/util/XpHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package reliquary.util;

import net.minecraft.world.entity.player.Player;

public class XpHelper {
private XpHelper() {}

Expand Down Expand Up @@ -52,4 +54,8 @@ public static int durabilityToXp(int durability) {
public static int xpToDurability(int xp) {
return xp * 2;
}

public static int getTotalPlayerExperience(Player player) {
return getExperienceForLevel(player.experienceLevel) + ((int) player.experienceProgress * player.getXpNeededForNextLevel());
}
}

0 comments on commit 19a1664

Please sign in to comment.