forked from BLOCKFANTASY/LOOHP-Limbo
fix: don't spam empty chunk packets
This commit is contained in:
parent
a0c68a8b87
commit
f236a9b01e
|
|
@ -30,6 +30,7 @@ import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityDestroy;
|
|||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutEntityMetadata;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutSpawnEntity;
|
||||
import com.loohp.limbo.network.protocol.packets.PacketPlayOutUnloadChunk;
|
||||
import com.loohp.limbo.utils.GameMode;
|
||||
import com.loohp.limbo.world.ChunkPosition;
|
||||
import com.loohp.limbo.world.World;
|
||||
import net.querz.mca.Chunk;
|
||||
|
|
@ -71,7 +72,7 @@ public class PlayerInteractManager {
|
|||
}
|
||||
|
||||
public void update() throws IOException {
|
||||
if (player.clientConnection.getClientState() != ClientConnection.ClientState.PLAY) {
|
||||
if (player.clientConnection.getClientState() != ClientConnection.ClientState.PLAY && !player.clientConnection.isReady()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -118,20 +119,28 @@ public class PlayerInteractManager {
|
|||
}
|
||||
}
|
||||
|
||||
for (Entry<ChunkPosition, Chunk> entry : currentViewing.entrySet()) {
|
||||
ChunkPosition chunkPos = entry.getKey();
|
||||
for (ChunkPosition chunkPos : currentViewing.keySet()) {
|
||||
if (!chunksInRange.containsKey(chunkPos)) {
|
||||
PacketPlayOutUnloadChunk packet = new PacketPlayOutUnloadChunk(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||
player.clientConnection.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
// blocks cannot be broken, so don't send chunks to the client
|
||||
if (getPlayer().getGamemode() == GameMode.ADVENTURE) {
|
||||
for (ChunkPosition chunkPos : chunksInRange.keySet()) {
|
||||
currentViewing.remove(chunkPos);
|
||||
}
|
||||
}
|
||||
|
||||
// if we don't have any chunk updates, don't send any packets
|
||||
if (chunksInRange.isEmpty()) return;
|
||||
|
||||
int counter = 0;
|
||||
ClientboundChunkBatchStartPacket chunkBatchStartPacket = new ClientboundChunkBatchStartPacket();
|
||||
player.clientConnection.sendPacket(chunkBatchStartPacket);
|
||||
for (Entry<ChunkPosition, Chunk> entry : chunksInRange.entrySet()) {
|
||||
ChunkPosition chunkPos = entry.getKey();
|
||||
if (!currentViewing.containsKey(chunkPos)) {
|
||||
Chunk chunk = chunkPos.getWorld().getChunkAt(chunkPos.getChunkX(), chunkPos.getChunkZ());
|
||||
if (chunk == null) {
|
||||
ClientboundLevelChunkWithLightPacket chunkdata = new ClientboundLevelChunkWithLightPacket(chunkPos.getChunkX(), chunkPos.getChunkZ(), entry.getValue(), world.getEnvironment(), Collections.emptyList(), Collections.emptyList());
|
||||
|
|
@ -152,7 +161,6 @@ public class PlayerInteractManager {
|
|||
player.clientConnection.sendPacket(chunkdata);
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
ClientboundChunkBatchFinishedPacket chunkBatchFinishedPacket = new ClientboundChunkBatchFinishedPacket(counter);
|
||||
player.clientConnection.sendPacket(chunkBatchFinishedPacket);
|
||||
|
|
|
|||
Loading…
Reference in New Issue