Use new 1.18 chunk encoding features

This commit is contained in:
Camotoy 2021-11-23 11:21:54 -05:00
parent daea2618c5
commit e7ecda64f0
No known key found for this signature in database
GPG Key ID: 7EEFB66FE798081F
1 changed files with 14 additions and 3 deletions

View File

@ -43,6 +43,7 @@ import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.v475.Bedrock_v475;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufOutputStream;
@ -325,9 +326,19 @@ public class JavaLevelChunkWithLightTranslator extends PacketTranslator<Clientbo
}
// As of 1.17.10, Bedrock hardcodes to always read 32 biome sections
int remainingEmptyBiomes = 32 - sectionCount;
for (int i = 0; i < remainingEmptyBiomes; i++) {
byteBuf.writeBytes(ChunkUtils.EMPTY_BIOME_DATA);
// As of 1.18, this hardcode was lowered to 25
if (session.getUpstream().getProtocolVersion() >= Bedrock_v475.V475_CODEC.getProtocolVersion()) {
int remainingEmptyBiomes = 25 - sectionCount;
for (int i = 0; i < remainingEmptyBiomes; i++) {
// 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 - sectionCount;
for (int i = 0; i < remainingEmptyBiomes; i++) {
byteBuf.writeBytes(ChunkUtils.EMPTY_BIOME_DATA);
}
}
byteBuf.writeByte(0); // Border blocks - Edu edition only