diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java index 01be93aac..31d8936fc 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/packets/WorldPackets.java @@ -19,7 +19,7 @@ public class WorldPackets { blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE); - blockRewriter.registerMultiBlockChange(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE); + blockRewriter.registerVarLongMultiBlockChange(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE); blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING); protocol.registerOutgoing(ClientboundPackets1_16_2.UPDATE_LIGHT, new PacketRemapper() { @@ -55,7 +55,7 @@ public class WorldPackets { chunk.setBiomeData(biomes); } else { Via.getPlatform().getLogger().warning("Biome data not found for chunk at " + chunk.getX() + ", " + chunk.getZ()); - chunk.setBiomeData(new int[0]); + chunk.setBiomeData(new int[1024]); } } @@ -71,6 +71,39 @@ public class WorldPackets { } }); + + protocol.registerOutgoing(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() { + @Override + public void registerMap() { + map(Type.INT); + map(Type.BOOLEAN); + map(Type.UNSIGNED_BYTE); + map(Type.BYTE); + map(Type.STRING_ARRAY); + map(Type.NBT); + map(Type.NBT); + handler(wrapper -> { + String world = wrapper.passthrough(Type.STRING); + wrapper.user().get(BiomeStorage.class).setWorld(world); + }); + } + }); + protocol.registerOutgoing(ClientboundPackets1_16_2.RESPAWN, new PacketRemapper() { + @Override + public void registerMap() { + handler(wrapper -> { + wrapper.passthrough(Type.NBT); + String world = wrapper.passthrough(Type.STRING); + BiomeStorage biomeStorage = wrapper.user().get(BiomeStorage.class); + if (!world.equals(biomeStorage.getWorld())) { + biomeStorage.clearBiomes(); + } + + biomeStorage.setWorld(world); + }); + } + }); + protocol.registerOutgoing(ClientboundPackets1_16_2.UNLOAD_CHUNK, new PacketRemapper() { @Override public void registerMap() { diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/storage/BiomeStorage.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/storage/BiomeStorage.java index 2ce38a8c4..869b8080a 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/storage/BiomeStorage.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_17to1_16_4/storage/BiomeStorage.java @@ -10,11 +10,21 @@ import java.util.Map; public class BiomeStorage extends StoredObject { private final Map chunkBiomes = new HashMap<>(); + private String world; public BiomeStorage(UserConnection user) { super(user); } + @Nullable + public String getWorld() { + return world; + } + + public void setWorld(String world) { + this.world = world; + } + @Nullable public int[] getBiomes(int x, int z) { return chunkBiomes.get(getChunkSectionIndex(x, z)); @@ -28,6 +38,10 @@ public class BiomeStorage extends StoredObject { chunkBiomes.remove(getChunkSectionIndex(x, z)); } + public void clearBiomes() { + chunkBiomes.clear(); + } + private long getChunkSectionIndex(int x, int z) { return ((x & 0x3FFFFFFL) << 38) | (z & 0x3FFFFFFL); }