mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Keep reference to the framed packet for debugging/transformation purpose
This commit is contained in:
parent
e96334e315
commit
168672e002
@ -8,10 +8,11 @@ import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.entity.pathfinding.PFBlock;
|
||||
import net.minestom.server.instance.block.Block;
|
||||
import net.minestom.server.instance.block.BlockHandler;
|
||||
import net.minestom.server.network.packet.FramedPacket;
|
||||
import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.utils.ArrayUtils;
|
||||
import net.minestom.server.utils.PacketUtils;
|
||||
import net.minestom.server.utils.chunk.ChunkUtils;
|
||||
@ -19,7 +20,6 @@ import net.minestom.server.world.biomes.Biome;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -40,8 +40,8 @@ public class DynamicChunk extends Chunk {
|
||||
|
||||
private volatile long lastChangeTime;
|
||||
|
||||
private ByteBuffer cachedChunkBuffer;
|
||||
private ByteBuffer cachedLightBuffer;
|
||||
private FramedPacket cachedChunkBuffer;
|
||||
private FramedPacket cachedLightBuffer;
|
||||
private long cachedPacketTime;
|
||||
|
||||
public DynamicChunk(@NotNull Instance instance, @Nullable Biome[] biomes, int chunkX, int chunkZ) {
|
||||
@ -132,8 +132,8 @@ public class DynamicChunk extends Chunk {
|
||||
final PlayerConnection connection = player.getPlayerConnection();
|
||||
if (connection instanceof PlayerSocketConnection) {
|
||||
final long lastChange = getLastChangeTime();
|
||||
ByteBuffer chunkPacket = cachedChunkBuffer;
|
||||
ByteBuffer lightPacket = cachedLightBuffer;
|
||||
var chunkPacket = cachedChunkBuffer;
|
||||
var lightPacket = cachedLightBuffer;
|
||||
if (lastChange > cachedPacketTime || (chunkPacket == null || lightPacket == null)) {
|
||||
chunkPacket = PacketUtils.allocateTrimmedPacket(createChunkPacket());
|
||||
lightPacket = PacketUtils.allocateTrimmedPacket(createLightPacket());
|
||||
|
@ -197,9 +197,11 @@ public final class PacketUtils {
|
||||
return createFramedPacket(PACKET_BUFFER.get(), packet, compression);
|
||||
}
|
||||
|
||||
public static ByteBuffer allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
||||
@ApiStatus.Internal
|
||||
public static FramedPacket allocateTrimmedPacket(@NotNull ServerPacket packet) {
|
||||
final var temp = PacketUtils.createFramedPacket(packet);
|
||||
return ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
|
||||
final var buffer= ByteBuffer.allocateDirect(temp.position()).put(temp.flip()).asReadOnlyBuffer();
|
||||
return new FramedPacket(packet.getId(), buffer, packet);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
|
Loading…
Reference in New Issue
Block a user