Skip to content

Commit

Permalink
Remove obsolete chunk writing code
Browse files Browse the repository at this point in the history
  • Loading branch information
Camotoy committed May 30, 2022
1 parent 7a0a679 commit e43a143
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import com.nukkitx.nbt.NbtUtils;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.packet.LevelChunkPacket;
import com.nukkitx.protocol.bedrock.v503.Bedrock_v503;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.ByteBufOutputStream;
Expand All @@ -52,6 +51,7 @@
import it.unimi.dsi.fastutil.ints.IntLists;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import org.geysermc.geyser.entity.type.ItemFrameEntity;
import org.geysermc.geyser.level.BedrockDimension;
import org.geysermc.geyser.level.block.BlockStateValues;
import org.geysermc.geyser.level.chunk.BlockStorage;
import org.geysermc.geyser.level.chunk.GeyserChunkSection;
Expand All @@ -60,7 +60,6 @@
import org.geysermc.geyser.level.chunk.bitarray.SingletonBitArray;
import org.geysermc.geyser.registry.BlockRegistries;
import org.geysermc.geyser.session.GeyserSession;
import org.geysermc.geyser.level.BedrockDimension;
import org.geysermc.geyser.translator.level.BiomeTranslator;
import org.geysermc.geyser.translator.level.block.entity.BedrockOnlyBlockEntity;
import org.geysermc.geyser.translator.level.block.entity.BlockEntityTranslator;
Expand All @@ -76,7 +75,8 @@
import java.util.List;
import java.util.Map;

import static org.geysermc.geyser.util.ChunkUtils.*;
import static org.geysermc.geyser.util.ChunkUtils.SERIALIZED_CHUNK_DATA;
import static org.geysermc.geyser.util.ChunkUtils.indexYZXtoXZY;

@Translator(packet = ClientboundLevelChunkWithLightPacket.class)
public class JavaLevelChunkWithLightTranslator extends PacketTranslator<ClientboundLevelChunkWithLightPacket> {
Expand Down Expand Up @@ -312,10 +312,8 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
}
}

// As of 1.18.0, Bedrock hardcodes to always read 25 biome sections
// As of 1.18.30, the hardcode may now be tied to the dimension definition
boolean isNewVersion = session.getUpstream().getProtocolVersion() >= Bedrock_v503.V503_CODEC.getProtocolVersion();
int biomeCount = isNewVersion ? bedrockDimension.height() >> 4 : 25;
// As of 1.18.30, the amount of biomes read is dependent on how high Bedrock thinks the dimension is
int biomeCount = bedrockDimension.height() >> 4;
int dimensionOffset = bedrockDimension.minY() >> 4;
for (int i = 0; i < biomeCount; i++) {
int biomeYOffset = dimensionOffset + i;
Expand All @@ -326,13 +324,8 @@ public void translate(GeyserSession session, ClientboundLevelChunkWithLightPacke
}
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 {
byteBuf.writeBytes(ChunkUtils.EMPTY_BIOME_DATA);
}
// The byte written here is a header that says to carry on the biome data from the previous chunk
byteBuf.writeByte((127 << 1) | 1);
continue;
}

Expand Down

0 comments on commit e43a143

Please sign in to comment.