mirror of https://github.com/LOOHP/Limbo.git
fix: Fix chunk updates not being sent properly
This commit is contained in:
parent
342404f586
commit
01d2a3e528
|
|
@ -52,11 +52,13 @@ public class PlayerInteractManager {
|
||||||
|
|
||||||
private Set<Entity> entities;
|
private Set<Entity> entities;
|
||||||
private Map<ChunkPosition, Chunk> currentViewing;
|
private Map<ChunkPosition, Chunk> currentViewing;
|
||||||
|
private final Map<ChunkPosition, Chunk> chunkUpdates;
|
||||||
|
|
||||||
public PlayerInteractManager() {
|
public PlayerInteractManager() {
|
||||||
this.player = null;
|
this.player = null;
|
||||||
this.entities = new HashSet<>();
|
this.entities = new HashSet<>();
|
||||||
this.currentViewing = new HashMap<>();
|
this.currentViewing = new HashMap<>();
|
||||||
|
this.chunkUpdates = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setPlayer(Player player) {
|
protected void setPlayer(Player player) {
|
||||||
|
|
@ -126,20 +128,24 @@ public class PlayerInteractManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// blocks cannot be broken, so don't send chunks to the client
|
// add chunk candidates for updating
|
||||||
|
chunkUpdates.clear();
|
||||||
|
chunkUpdates.putAll(chunksInRange);
|
||||||
|
|
||||||
|
// blocks cannot be broken, so once we've sent all of them, don't update them anymore
|
||||||
if (getPlayer().getGamemode() == GameMode.ADVENTURE) {
|
if (getPlayer().getGamemode() == GameMode.ADVENTURE) {
|
||||||
for (ChunkPosition chunkPos : chunksInRange.keySet()) {
|
for (ChunkPosition chunkPos : currentViewing.keySet()) {
|
||||||
currentViewing.remove(chunkPos);
|
chunkUpdates.remove(chunkPos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we don't have any chunk updates, don't send any packets
|
// if we don't have any chunk updates, don't send any packets
|
||||||
if (chunksInRange.isEmpty()) return;
|
if (chunkUpdates.isEmpty()) return;
|
||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
ClientboundChunkBatchStartPacket chunkBatchStartPacket = new ClientboundChunkBatchStartPacket();
|
ClientboundChunkBatchStartPacket chunkBatchStartPacket = new ClientboundChunkBatchStartPacket();
|
||||||
player.clientConnection.sendPacket(chunkBatchStartPacket);
|
player.clientConnection.sendPacket(chunkBatchStartPacket);
|
||||||
for (Entry<ChunkPosition, Chunk> entry : chunksInRange.entrySet()) {
|
for (Entry<ChunkPosition, Chunk> entry : chunkUpdates.entrySet()) {
|
||||||
ChunkPosition chunkPos = entry.getKey();
|
ChunkPosition chunkPos = entry.getKey();
|
||||||
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||||
if (chunk == null) {
|
if (chunk == null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue