Ensure enough bits in bedrockData for paletteIDs

Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
Joshua Castle 2023-05-14 01:09:07 -07:00
parent e4b12577b5
commit 764a65272a
No known key found for this signature in database
GPG key ID: F674F38216C35D5D

View file

@ -199,6 +199,7 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
bedrockOnlyBlockEntityIds.clear();
// Iterate through palette and convert state IDs to Bedrock, doing some additional checks as we go
int extendedCollisionsInPalette = 0;
for (int i = 0; i < javaPalette.size(); i++) {
int javaId = javaPalette.idToState(i);
bedrockPalette.add(session.getBlockMappings().getBedrockBlockId(javaId));
@ -211,9 +212,10 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
airPaletteId = i;
}
if (!session.getBlockMappings().getExtendedCollisionBoxes().isEmpty() && !extendedCollision) {
if (!session.getBlockMappings().getExtendedCollisionBoxes().isEmpty()) {
if (session.getBlockMappings().getExtendedCollisionBoxes().get(javaId) != null) {
extendedCollision = true;
extendedCollisionsInPalette++;
}
}
@ -238,7 +240,9 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
}
}
BitArray bedrockData = BitArrayVersion.forBitsCeil(javaData.getBitsPerEntry()).createArray(BlockStorage.SIZE);
// We need to ensure we use enough bits to represent extended collision blocks in the palette
int bedrockDataBits = Integer.SIZE - Integer.numberOfLeadingZeros(javaPalette.size() + extendedCollisionsInPalette);
BitArray bedrockData = BitArrayVersion.forBitsCeil(bedrockDataBits).createArray(BlockStorage.SIZE);
BlockStorage layer0 = new BlockStorage(bedrockData, bedrockPalette);
BlockStorage[] layers;