Created
April 19, 2022 21:08
-
-
Save SupremeMortal/5e09c8b0eb6b3a30439b317b875bc29c to your computer and use it in GitHub Desktop.
Bedrock's new block palette ordering
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class HashedPaletteComparator implements Comparator<String> { | |
public static final HashedPaletteComparator INSTANCE = new HashedPaletteComparator(); | |
private static final long FNV1_64_INIT = 0xcbf29ce484222325L; | |
private static final long FNV1_PRIME_64 = 1099511628211L; | |
@Override | |
public int compare(String o1, String o2) { | |
byte[] bytes1 = o1.getBytes(StandardCharsets.UTF_8); | |
byte[] bytes2 = o2.getBytes(StandardCharsets.UTF_8); | |
long hash1 = fnv164(bytes1); | |
long hash2 = fnv164(bytes2); | |
return Long.compareUnsigned(hash1, hash2); | |
} | |
public static long fnv164(byte[] data) { | |
long hash = FNV1_64_INIT; | |
for (byte datum : data) { | |
hash *= FNV1_PRIME_64; | |
hash ^= (datum & 0xff); | |
} | |
return hash; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment