Uncache biome data on world change, process multi block change

This commit is contained in:
KennyTV 2020-11-05 17:44:26 +01:00
parent 88a1a42625
commit 424e855d72
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 49 additions and 2 deletions

View File

@ -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() {

View File

@ -10,11 +10,21 @@ import java.util.Map;
public class BiomeStorage extends StoredObject {
private final Map<Long, int[]> 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);
}