From 990700c3f3a50af54299b5792cdbe01bf592f401 Mon Sep 17 00:00:00 2001 From: B1n_ry Date: Wed, 22 Nov 2023 14:09:02 +0100 Subject: [PATCH] Possibly improved XP calculation --- gradle.properties | 2 +- .../b1n_ry/yigd/components/ExpComponent.java | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/gradle.properties b/gradle.properties index 76d915a5..ca14b489 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.parallel=true loader_version=0.14.24 # Mod Properties - mod_version = 2.0.0-beta.3 + mod_version = 2.0.0-beta.4 maven_group = com.b1n_ry.yigd archives_base_name = youre-in-grave-danger diff --git a/src/main/java/com/b1n_ry/yigd/components/ExpComponent.java b/src/main/java/com/b1n_ry/yigd/components/ExpComponent.java index b2745b92..e0044adf 100644 --- a/src/main/java/com/b1n_ry/yigd/components/ExpComponent.java +++ b/src/main/java/com/b1n_ry/yigd/components/ExpComponent.java @@ -29,23 +29,28 @@ public int getXpDropAmount(ServerPlayerEntity player) { if (config.expConfig.dropBehaviour == ExpDropBehaviour.VANILLA) { return Math.min(7 * player.experienceLevel, 100); } else if (config.expConfig.dropBehaviour == ExpDropBehaviour.PERCENTAGE) { - int currentLevel = player.experienceLevel; - int totalExperience; - if (currentLevel >= 32) { - totalExperience = (int) (4.5 * Math.pow(currentLevel, 2) - 162.5 * currentLevel + 2220); - } else if (currentLevel >= 17) { - totalExperience = (int) (2.5 * Math.pow(currentLevel, 2) - 40.5 * currentLevel + 360); - } else { - totalExperience = (int) (Math.pow(currentLevel, 2) + 6 * currentLevel); - } - totalExperience += player.experienceProgress; + double totalExperience = this.getTotalExperience(player); - return (int) ((config.expConfig.dropPercentage / 100f) * (float) totalExperience); + return (int) ((config.expConfig.dropPercentage / 100f) * totalExperience); } return 0; } + private double getTotalExperience(ServerPlayerEntity player) { + int currentLevel = player.experienceLevel; + double totalExperience; + if (currentLevel >= 32) { + totalExperience = 4.5 * Math.pow(currentLevel, 2) - 162.5 * currentLevel + 2220; + } else if (currentLevel >= 17) { + totalExperience = 2.5 * Math.pow(currentLevel, 2) - 40.5 * currentLevel + 360; + } else { + totalExperience = Math.pow(currentLevel, 2) + 6 * currentLevel; + } + totalExperience += player.experienceProgress; + return totalExperience; + } + public int getXpLevel() { int totalXp = this.storedXp;