Fixed empty chunk when connecting during its generation

This commit is contained in:
themode 2020-11-20 17:13:00 +01:00
parent da4216a51f
commit 7a1a43279a
2 changed files with 12 additions and 12 deletions

View File

@ -17,6 +17,7 @@ import net.minestom.server.network.packet.server.play.ChunkDataPacket;
import net.minestom.server.network.packet.server.play.UpdateLightPacket; import net.minestom.server.network.packet.server.play.UpdateLightPacket;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
import net.minestom.server.utils.MathUtils; import net.minestom.server.utils.MathUtils;
import net.minestom.server.utils.PacketUtils;
import net.minestom.server.utils.Position; import net.minestom.server.utils.Position;
import net.minestom.server.utils.binary.BinaryReader; import net.minestom.server.utils.binary.BinaryReader;
import net.minestom.server.utils.chunk.ChunkCallback; import net.minestom.server.utils.chunk.ChunkCallback;
@ -512,13 +513,7 @@ public abstract class Chunk implements Viewable, DataContainer {
* Sends a full {@link ChunkDataPacket} to all chunk viewers. * Sends a full {@link ChunkDataPacket} to all chunk viewers.
*/ */
public synchronized void sendChunkUpdate() { public synchronized void sendChunkUpdate() {
final Set<Player> chunkViewers = getViewers(); PacketUtils.sendGroupedPacket(getViewers(), getFreshFullDataPacket());
if (!chunkViewers.isEmpty()) {
chunkViewers.forEach(player -> {
final PlayerConnection playerConnection = player.getPlayerConnection();
playerConnection.sendPacket(getFreshFullDataPacket());
});
}
} }
/** /**

View File

@ -127,12 +127,17 @@ public class ChunkBatch implements InstanceBatch {
chunkPopulator.populateChunk(this, chunk); chunkPopulator.populateChunk(this, chunk);
} }
} }
}
// Refresh chunk for viewers
this.chunk.sendChunkUpdate();
this.instance.refreshLastBlockChangeTime();
// Safe callback // Safe callback
instance.scheduleNextTick(inst -> { instance.scheduleNextTick(inst -> {
OptionalCallback.execute(callback, chunk); OptionalCallback.execute(callback, chunk);
}); });
}
}); });
} }