Skip to content

Instantly share code, notes, and snippets.

@Edouard127
Created February 1, 2025 01:36
Show Gist options
  • Save Edouard127/9e59a869da505377fe9c79661f1fd43d to your computer and use it in GitHub Desktop.
Save Edouard127/9e59a869da505377fe9c79661f1fd43d to your computer and use it in GitHub Desktop.
val palette = it.getLongArray("BlockStates")
val bits = palette.size.logCap(2)
val maxEntryValue = (1 shl bits) - 1L
for (y in 0 until ySizeAbs) {
for (z in 0 until zSizeAbs) {
for (x in 0 until xSizeAbs) {
val index = (y * xSizeAbs * zSizeAbs) + z * xSizeAbs + x
val startOffset = index * bits
val startArrIndex = startOffset / 64
val endArrIndex = ((index + 1) * bits - 1) / 64
val startBitOffset = startOffset % 64
val stateId =
if (startArrIndex == endArrIndex) palette[startArrIndex] ushr startBitOffset and maxEntryValue
else (palette[startArrIndex] ushr startBitOffset or palette[endArrIndex] shl (64 - startBitOffset)) and maxEntryValue
newBlocks.add(NbtCompound().apply {
putIntList("pos", x, y, z)
putInt("state", stateId.toInt())
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment