From f9ca87cfc418fc500af83f2319904c50e7f7dc3f Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Thu, 24 Jun 2021 20:42:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B5=20Nibble?= =?UTF-8?q?Array?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../protocol/packets/play/server/ChunkDataPacket.java | 4 ++-- .../main/java/mc/protocol/utils/Bit13LongArray.java | 10 +++++----- .../src/main/java/mc/protocol/utils/HalfByteArray.java | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/protocol/src/main/java/mc/protocol/packets/play/server/ChunkDataPacket.java b/protocol/src/main/java/mc/protocol/packets/play/server/ChunkDataPacket.java index 70ec3a9..ca75325 100644 --- a/protocol/src/main/java/mc/protocol/packets/play/server/ChunkDataPacket.java +++ b/protocol/src/main/java/mc/protocol/packets/play/server/ChunkDataPacket.java @@ -160,8 +160,8 @@ public class ChunkDataPacket implements ServerSidePacket { // // - int dataArraySize = _16_16_16 * BITS_PER_BLOCK; - data.writeVarInt(dataArraySize / Long.SIZE); + int dataArraySize = _16_16_16 * BITS_PER_BLOCK / Long.SIZE; + data.writeVarInt(dataArraySize); // // diff --git a/protocol/src/main/java/mc/protocol/utils/Bit13LongArray.java b/protocol/src/main/java/mc/protocol/utils/Bit13LongArray.java index f3041cb..b8add1d 100644 --- a/protocol/src/main/java/mc/protocol/utils/Bit13LongArray.java +++ b/protocol/src/main/java/mc/protocol/utils/Bit13LongArray.java @@ -11,8 +11,8 @@ public class Bit13LongArray implements NibbleArray { private int nibbleIndex = 0; private int lastWriteIndex = 0; - public Bit13LongArray(int capacity) { - this.buffer = ByteBuffer.allocate(capacity); + public Bit13LongArray(int longCapacity) { + this.buffer = ByteBuffer.allocate(longCapacity * Long.SIZE); } @Override @@ -28,7 +28,7 @@ public class Bit13LongArray implements NibbleArray { //@formetter:on if (tailValueIndex != lastWriteIndex) { - buffer.asLongBuffer().put(longValue); + buffer.putLong(longValue); lastWriteIndex++; longValue = 0L; } @@ -37,7 +37,7 @@ public class Bit13LongArray implements NibbleArray { nibbleIndex++; if (headValueIndex != tailValueIndex) { - buffer.asLongBuffer().put(longValue); + buffer.putLong(longValue); lastWriteIndex++; longValue = value >> (Long.SIZE - offsetValue); } @@ -45,6 +45,6 @@ public class Bit13LongArray implements NibbleArray { @Override public ByteBuffer byteBuffer() { - return this.buffer.rewind(); + return this.buffer.putLong(longValue).rewind(); } } diff --git a/protocol/src/main/java/mc/protocol/utils/HalfByteArray.java b/protocol/src/main/java/mc/protocol/utils/HalfByteArray.java index ad0192e..d227757 100644 --- a/protocol/src/main/java/mc/protocol/utils/HalfByteArray.java +++ b/protocol/src/main/java/mc/protocol/utils/HalfByteArray.java @@ -19,9 +19,9 @@ public class HalfByteArray implements NibbleArray { } if (halfValue == null) { - halfValue = (byte) (value << BITS); + halfValue = (byte) (value); } else { - buffer.put((byte) (halfValue | value)); + buffer.put((byte) (halfValue | value << BITS)); halfValue = null; } } @@ -30,7 +30,6 @@ public class HalfByteArray implements NibbleArray { public ByteBuffer byteBuffer() { if (halfValue != null) { buffer.put(halfValue); - halfValue = null; } return this.buffer.rewind();