Skip to content

Instantly share code, notes, and snippets.

@jacc
Created June 27, 2021 20:29
Show Gist options
  • Save jacc/7ecc831d70081516422792c370078e4c to your computer and use it in GitHub Desktop.
Save jacc/7ecc831d70081516422792c370078e4c to your computer and use it in GitHub Desktop.
Function to convert Hypixel network experience to a level in JS/TS
// Code adapted from https://github.com/HypixelDev/PublicAPI/blob/master/Java/src/main/java/net/hypixel/api/util/ILeveling.java
const BASE = 10_000
const GROWTH = 2_500
console.log(BASE + GROWTH)
const REVERSE_PQ_PREFIX = -(BASE - 0.5 * GROWTH) / GROWTH;
const REVERSE_CONST = REVERSE_PQ_PREFIX * REVERSE_PQ_PREFIX;
const GROWTH_DIVIDES_2 = 2 / GROWTH;
function calculate(exp) {
return exp < 0 ? 1 : Math.floor(1 + REVERSE_PQ_PREFIX + Math.sqrt(REVERSE_CONST + GROWTH_DIVIDES_2 * exp));
}
console.log(calculate("5094162"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment