Created
February 1, 2025 01:36
-
-
Save Edouard127/9e59a869da505377fe9c79661f1fd43d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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