Skip to content

Instantly share code, notes, and snippets.

@aadnk
Created January 14, 2013 12:38
Show Gist options
  • Save aadnk/4529785 to your computer and use it in GitHub Desktop.
Save aadnk/4529785 to your computer and use it in GitHub Desktop.
Generate the experience tables on Minecraft Wiki
package com.comphenix.testing;
class Test {
private static int[] xpRequiredForNextLevel;
private static int[] xpTotalToReachLevel;
public static void main(String[] args) {
initLookupTables(50);
for (int i = 1; i < 41; i++) {
System.out.println(xpTotalToReachLevel[i] + "," + xpRequiredForNextLevel[i - 1]);
}
}
// Based on desht excellent ExperienceManager
// https://github.com/desht/dhutils/blob/master/Lib/src/main/java/me/desht/dhutils/ExperienceManager.java
private static void initLookupTables(int maxLevel) {
xpRequiredForNextLevel = new int[maxLevel];
xpTotalToReachLevel = new int[maxLevel];
xpTotalToReachLevel[0] = 0;
// Valid for MC 1.3 and later
int incr = 17;
for (int i = 1; i < xpTotalToReachLevel.length; i++) {
xpRequiredForNextLevel[i - 1] = incr;
xpTotalToReachLevel[i] = xpTotalToReachLevel[i - 1] + incr;
if (i >= 30) {
incr += 7;
} else if (i >= 16) {
incr += 3;
}
}
xpRequiredForNextLevel[xpRequiredForNextLevel.length - 1] = incr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment