From d5278488e5d48e4d77ceabaf8c026f2c2d4ad552 Mon Sep 17 00:00:00 2001 From: Bixilon Date: Thu, 9 Jul 2020 17:52:54 +0200 Subject: [PATCH] remove high and low bit set functions --- .../protocol/packets/clientbound/play/PacketMapData.java | 8 ++++---- src/main/java/de/bixilon/minosoft/util/BitByte.java | 8 -------- src/main/java/de/bixilon/minosoft/util/ChunkUtil.java | 8 ++++---- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java index 373e8cbc2..509959191 100644 --- a/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java +++ b/src/main/java/de/bixilon/minosoft/protocol/packets/clientbound/play/PacketMapData.java @@ -60,8 +60,8 @@ public class PacketMapData implements ClientboundPacket { length--; // minus the dataData for (int i = 0; i < length / 3; i++) { // loop over all sets ( 1 set: 3 bytes) byte data = buffer.readByte(); - byte type = BitByte.getLow4Bits(data); - MapPlayerDirection direction = MapPlayerDirection.byId(BitByte.getHigh4Bits(data)); + byte type = (byte) (data & 0xF); + MapPlayerDirection direction = MapPlayerDirection.byId(data >>> 4); byte x = buffer.readByte(); byte z = buffer.readByte(); pins.add(new MapPinSet(MapPinType.byId(type), direction, x, z)); @@ -89,9 +89,9 @@ public class PacketMapData implements ClientboundPacket { byte x = buffer.readByte(); byte z = buffer.readByte(); if (buffer.getVersion().getVersionNumber() >= ProtocolVersion.VERSION_1_12_2.getVersionNumber()) { - pins.add(new MapPinSet(MapPinType.byId(BitByte.getHigh4Bits(directionAndType)), MapPlayerDirection.byId(BitByte.getLow4Bits(directionAndType)), x, z)); + pins.add(new MapPinSet(MapPinType.byId(directionAndType >>> 4), MapPlayerDirection.byId(directionAndType & 0xF), x, z)); } else { - pins.add(new MapPinSet(MapPinType.byId(BitByte.getLow4Bits(directionAndType)), MapPlayerDirection.byId(BitByte.getHigh4Bits(directionAndType)), x, z)); + pins.add(new MapPinSet(MapPinType.byId(directionAndType & 0xF), MapPlayerDirection.byId(directionAndType >>> 4), x, z)); } } short columns = BitByte.byteToUShort(buffer.readByte()); diff --git a/src/main/java/de/bixilon/minosoft/util/BitByte.java b/src/main/java/de/bixilon/minosoft/util/BitByte.java index b5b612890..dd6b97207 100644 --- a/src/main/java/de/bixilon/minosoft/util/BitByte.java +++ b/src/main/java/de/bixilon/minosoft/util/BitByte.java @@ -34,14 +34,6 @@ public class BitByte { return bitSet; } - public static byte getLow4Bits(byte input) { - return (byte) (input & 0xF); - } - - public static byte getHigh4Bits(byte input) { - return (byte) ((input) >>> 4 & 0xF); - } - public static byte getBitCount(short input) { byte ret = 0; for (int i = 0; i < Short.BYTES * 8; i++) { // bytes to bits diff --git a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java index 7cc266735..a851882f2 100644 --- a/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java +++ b/src/main/java/de/bixilon/minosoft/util/ChunkUtil.java @@ -63,16 +63,16 @@ public class ChunkUtil { // get block meta and shift and add (merge) id if needed if (arrayPos % 2 == 0) { // high bits - singleMeta = BitByte.getLow4Bits(meta[arrayPos / 2]); + singleMeta = (byte) (meta[arrayPos / 2] & 0xF); if (BitByte.isBitSet(addBitMask, c)) { - singeBlockId = (short) ((singeBlockId << 4) | BitByte.getHigh4Bits(addBlockTypes[arrayPos / 2])); + singeBlockId = (short) ((singeBlockId << 4) | (addBlockTypes[arrayPos / 2] >>> 4)); } } else { // low 4 bits - singleMeta = BitByte.getHigh4Bits(meta[arrayPos / 2]); + singleMeta = (byte) (meta[arrayPos / 2] >>> 4); if (BitByte.isBitSet(addBitMask, c)) { - singeBlockId = (short) ((singeBlockId << 4) | BitByte.getLow4Bits(addBlockTypes[arrayPos / 2])); + singeBlockId = (short) ((singeBlockId << 4) | (addBlockTypes[arrayPos / 2] & 0xF)); } }