mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Add PacketUtils#allocateTrimmedPacket
This commit is contained in:
parent
a2afcdd3a0
commit
58487f4455
@ -135,10 +135,8 @@ public class DynamicChunk extends Chunk {
|
||||
ByteBuffer chunkPacket = cachedChunkBuffer;
|
||||
ByteBuffer lightPacket = cachedLightBuffer;
|
||||
if (lastChange > cachedPacketTime || (chunkPacket == null || lightPacket == null)) {
|
||||
final var tempChunk = PacketUtils.createFramedPacket(createChunkPacket());
|
||||
chunkPacket = ByteBuffer.allocate(tempChunk.position()).put(tempChunk.flip());
|
||||
final var tempLight = PacketUtils.createFramedPacket(createLightPacket());
|
||||
lightPacket = ByteBuffer.allocate(tempLight.position()).put(tempLight.flip());
|
||||
chunkPacket = PacketUtils.allocateTrimmedPacket(createChunkPacket());
|
||||
lightPacket = PacketUtils.allocateTrimmedPacket(createLightPacket());
|
||||
this.cachedChunkBuffer = chunkPacket;
|
||||
this.cachedLightBuffer = lightPacket;
|
||||
this.cachedPacketTime = lastChange;
|
||||
|
@ -180,4 +180,9 @@ public final class PacketUtils {
|
||||
public static ByteBuffer createFramedPacket(@NotNull ServerPacket packet) {
|
||||
return createFramedPacket(BUFFER.get().clear(), packet);
|
||||
}
|
||||
|
||||
public static ByteBuffer allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
||||
final var temp = PacketUtils.createFramedPacket(packet);
|
||||
return ByteBuffer.allocate(temp.position()).put(temp.flip());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user