mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 17:37:42 +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 chunkPacket = cachedChunkBuffer;
|
||||||
ByteBuffer lightPacket = cachedLightBuffer;
|
ByteBuffer lightPacket = cachedLightBuffer;
|
||||||
if (lastChange > cachedPacketTime || (chunkPacket == null || lightPacket == null)) {
|
if (lastChange > cachedPacketTime || (chunkPacket == null || lightPacket == null)) {
|
||||||
final var tempChunk = PacketUtils.createFramedPacket(createChunkPacket());
|
chunkPacket = PacketUtils.allocateTrimmedPacket(createChunkPacket());
|
||||||
chunkPacket = ByteBuffer.allocate(tempChunk.position()).put(tempChunk.flip());
|
lightPacket = PacketUtils.allocateTrimmedPacket(createLightPacket());
|
||||||
final var tempLight = PacketUtils.createFramedPacket(createLightPacket());
|
|
||||||
lightPacket = ByteBuffer.allocate(tempLight.position()).put(tempLight.flip());
|
|
||||||
this.cachedChunkBuffer = chunkPacket;
|
this.cachedChunkBuffer = chunkPacket;
|
||||||
this.cachedLightBuffer = lightPacket;
|
this.cachedLightBuffer = lightPacket;
|
||||||
this.cachedPacketTime = lastChange;
|
this.cachedPacketTime = lastChange;
|
||||||
|
@ -180,4 +180,9 @@ public final class PacketUtils {
|
|||||||
public static ByteBuffer createFramedPacket(@NotNull ServerPacket packet) {
|
public static ByteBuffer createFramedPacket(@NotNull ServerPacket packet) {
|
||||||
return createFramedPacket(BUFFER.get().clear(), 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