Fix ArrayIndexOutOfBoundsException for worlds lower than -64
* Fix ArrayIndexOutOfBoundsException for worlds lower than -64
`chunkSize` is Java section count while `sectionCount` is the Bedrock section count
* Send biomes for air sections while also staying within limits
.-.
* Move protocol version check to variable
@@ -309,32 +309,31 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
}
}
- // At this point we're dealing with Bedrock chunk sections
+ // As of 1.17.10, Bedrock hardcodes to always read 32 biome sections
+ // As of 1.18, this hardcode was lowered to 25
+ boolean isNewVersion = session.getUpstream().getProtocolVersion() >= Bedrock_v475.V475_CODEC.getProtocolVersion();
+ int biomeCount = isNewVersion ? 25 : 32;
int dimensionOffset = (overworld ? MINIMUM_ACCEPTED_HEIGHT_OVERWORLD : MINIMUM_ACCEPTED_HEIGHT) >> 4;
- for (int i = 0; i < chunkSize; i++) {
+ for (int i = 0; i < biomeCount; i++) {
int biomeYOffset = dimensionOffset + i;
if (biomeYOffset < yOffset) {
- // Ignore this biome section since it goes above or below the height of the Java world
+ // Ignore this biome section since it goes below the height of the Java world
byteBuf.writeBytes(ChunkUtils.EMPTY_BIOME_DATA);
continue;
}
- BiomeTranslator.toNewBedrockBiome(session, javaBiomes[i + (dimensionOffset - yOffset)]).writeToNetwork(byteBuf);
- }
-
- // As of 1.17.10, Bedrock hardcodes to always read 32 biome sections
- // As of 1.18, this hardcode was lowered to 25
- if (session.getUpstream().getProtocolVersion() >= Bedrock_v475.V475_CODEC.getProtocolVersion()) {
- int remainingEmptyBiomes = 25 - chunkSize;
- for (int i = 0; i < remainingEmptyBiomes; i++) {
+ if (biomeYOffset >= (chunkSize + yOffset)) {
+ // This biome section goes above the height of the Java world
+ if (isNewVersion) {
// A header that says to carry on the biome data from the previous chunk
// This notably fixes biomes in the End
byteBuf.writeByte((127 << 1) | 1);
- }
} else {
- int remainingEmptyBiomes = 32 - chunkSize;
- for (int i = 0; i < remainingEmptyBiomes; i++) {
byteBuf.writeBytes(ChunkUtils.EMPTY_BIOME_DATA);
}
+ continue;
+ }
+
+ BiomeTranslator.toNewBedrockBiome(session, javaBiomes[i + (dimensionOffset - yOffset)]).writeToNetwork(byteBuf);
}
byteBuf.writeByte(0); // Border blocks - Edu edition only
