3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 09:00:09 +01:00

Uncache biome data on world change, process multi block change

Dieser Commit ist enthalten in:
KennyTV 2020-11-05 17:44:26 +01:00
Ursprung 88a1a42625
Commit 424e855d72
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
2 geänderte Dateien mit 49 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -19,7 +19,7 @@ public class WorldPackets {
blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION); blockRewriter.registerBlockAction(ClientboundPackets1_16_2.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE); 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); blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16_2.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerOutgoing(ClientboundPackets1_16_2.UPDATE_LIGHT, new PacketRemapper() { protocol.registerOutgoing(ClientboundPackets1_16_2.UPDATE_LIGHT, new PacketRemapper() {
@ -55,7 +55,7 @@ public class WorldPackets {
chunk.setBiomeData(biomes); chunk.setBiomeData(biomes);
} else { } else {
Via.getPlatform().getLogger().warning("Biome data not found for chunk at " + chunk.getX() + ", " + chunk.getZ()); 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() { protocol.registerOutgoing(ClientboundPackets1_16_2.UNLOAD_CHUNK, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {

Datei anzeigen

@ -10,11 +10,21 @@ import java.util.Map;
public class BiomeStorage extends StoredObject { public class BiomeStorage extends StoredObject {
private final Map<Long, int[]> chunkBiomes = new HashMap<>(); private final Map<Long, int[]> chunkBiomes = new HashMap<>();
private String world;
public BiomeStorage(UserConnection user) { public BiomeStorage(UserConnection user) {
super(user); super(user);
} }
@Nullable
public String getWorld() {
return world;
}
public void setWorld(String world) {
this.world = world;
}
@Nullable @Nullable
public int[] getBiomes(int x, int z) { public int[] getBiomes(int x, int z) {
return chunkBiomes.get(getChunkSectionIndex(x, z)); return chunkBiomes.get(getChunkSectionIndex(x, z));
@ -28,6 +38,10 @@ public class BiomeStorage extends StoredObject {
chunkBiomes.remove(getChunkSectionIndex(x, z)); chunkBiomes.remove(getChunkSectionIndex(x, z));
} }
public void clearBiomes() {
chunkBiomes.clear();
}
private long getChunkSectionIndex(int x, int z) { private long getChunkSectionIndex(int x, int z) {
return ((x & 0x3FFFFFFL) << 38) | (z & 0x3FFFFFFL); return ((x & 0x3FFFFFFL) << 38) | (z & 0x3FFFFFFL);
} }