From 4faedc78949c1059508dc941c79f5d693fb437eb Mon Sep 17 00:00:00 2001 From: creeper123123321 <7974274+creeper123123321@users.noreply.github.com> Date: Fri, 2 Apr 2021 15:24:11 -0300 Subject: [PATCH] try to fix block click --- .../creeper123123321/viaaas/protocol/Util.kt | 8 ++++---- .../protocol/id47toid5/Protocol1_8To1_7_6.kt | 2 +- .../protocol/id47toid5/packets/WorldPackets.kt | 18 ++++++++---------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/Util.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/Util.kt index e041843..eafa611 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/Util.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/Util.kt @@ -31,14 +31,14 @@ val xyzUBytePos = ValueReader { packetWrapper: PacketWrapper -> Position(x, y, z) } val xyzUBytePosWriter: ValueWriter = ValueWriter { packetWrapper: PacketWrapper, pos: Position -> - packetWrapper.write(Type.INT, pos.x.toInt()) + packetWrapper.write(Type.INT, pos.x) packetWrapper.write(Type.UNSIGNED_BYTE, pos.y.toShort()) - packetWrapper.write(Type.INT, pos.z.toInt()) + packetWrapper.write(Type.INT, pos.z) } val xyzShortPosWriter: ValueWriter = ValueWriter { packetWrapper: PacketWrapper, pos: Position -> - packetWrapper.write(Type.INT, pos.x.toInt()) + packetWrapper.write(Type.INT, pos.x) packetWrapper.write(Type.SHORT, pos.y.toShort()) - packetWrapper.write(Type.INT, pos.z.toInt()) + packetWrapper.write(Type.INT, pos.z) } val xyzShortPos: ValueReader = ValueReader { packetWrapper: PacketWrapper -> val x = packetWrapper.read(Type.INT) diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/Protocol1_8To1_7_6.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/Protocol1_8To1_7_6.kt index e9f4b94..c163edc 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/Protocol1_8To1_7_6.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/Protocol1_8To1_7_6.kt @@ -61,7 +61,7 @@ object Protocol1_8To1_7_6 : SimpleProtocol() { userConnection.put(MapStorage(userConnection)) } - fun isPlayerInsideBlock(x: Long, y: Long, z: Long, direction: Byte): Boolean { + fun isPlayerInsideBlock(x: Long, y: Long, z: Long, direction: Short): Boolean { //switch (direction) { // case 0: { // y--; diff --git a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt index 0ac39ed..0159aa4 100644 --- a/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt +++ b/src/main/kotlin/com/github/creeper123123321/viaaas/protocol/id47toid5/packets/WorldPackets.kt @@ -220,18 +220,16 @@ fun Protocol1_8To1_7_6.registerWorldPackets() { //Player Block Placement this.registerIncoming(State.PLAY, 0x08, 0x08, object : PacketRemapper() { override fun registerMap() { + map(TypeRemapper(Type.POSITION), xyzUBytePosWriter) + map(Type.UNSIGNED_BYTE) + map(Type.ITEM, Types1_7_6_10.COMPRESSED_NBT_ITEM) handler { packetWrapper -> - val pos: Position = packetWrapper.read(Type.POSITION) //Position - val x: Int = pos.x - val y: Short = pos.y.toShort() - val z: Int = pos.z + val x: Int = packetWrapper.get(Type.INT, 0) + val y: Short = packetWrapper.get(Type.UNSIGNED_BYTE, 0) + val z: Int = packetWrapper.get(Type.INT, 1) // https://github.com/ViaVersion/ViaVersion/pull/1379 - packetWrapper.write(Type.INT, x) - packetWrapper.write(Type.UNSIGNED_BYTE, y) - packetWrapper.write(Type.INT, z) - val direction = packetWrapper.passthrough(Type.BYTE) //Direction - val item = packetWrapper.read(Type.ITEM) - packetWrapper.write(Types1_7_6_10.COMPRESSED_NBT_ITEM, item) + val direction = packetWrapper.get(Type.UNSIGNED_BYTE, 0) //Direction + val item = packetWrapper.get(Types1_7_6_10.COMPRESSED_NBT_ITEM, 0) if (isPlayerInsideBlock( x.toLong(), y.toLong(),