From 9928ea7a4647694245c0baf3613f269681ee9815 Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 13 Mar 2023 23:04:49 +0100 Subject: [PATCH] fix: double implementation for position type --- aiocraft/mc/types.py | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/aiocraft/mc/types.py b/aiocraft/mc/types.py index 34608bd..3e4fb52 100644 --- a/aiocraft/mc/types.py +++ b/aiocraft/mc/types.py @@ -216,20 +216,32 @@ class PositionType(Type): pytype : type = tuple MAX_SIZE : int = 8 - # TODO THIS IS FOR 1.12.2!!! Make a generic version-less? - def write(self, data:tuple, buffer:io.BytesIO, ctx:Context): - packed = ((0x3FFFFFF & data[0]) << 38) \ - | ((0xFFF & data[1]) << 26) \ - | (0x3FFFFFF & data[2]) - UnsignedLong.write(packed, buffer, ctx=ctx) + if ctx._proto <= 441: + packed = ((0x3FFFFFF & data[0]) << 38) \ + | ((0xFFF & data[1]) << 26) \ + | (0x3FFFFFF & data[2]) + UnsignedLong.write(packed, buffer, ctx=ctx) + else: + packed = ((0x3FFFFFF & data[0]) << 38) \ + | ((0xFFF & data[2]) << 12) \ + | (0x3FFFFFF & data[1]) + UnsignedLong.write(packed, buffer, ctx=ctx) + pass def read(self, buffer:io.BytesIO, ctx:Context) -> tuple: - packed = UnsignedLong.read(buffer, ctx) - x = twos_comp(packed >> 38, 26) - y = (packed >> 26) & 0xFFF - z = twos_comp(packed & 0x3FFFFFF, 26) - return (x, y, z) + if ctx._proto <= 441: + packed = UnsignedLong.read(buffer, ctx) + x = twos_comp(packed >> 38, 26) + y = (packed >> 26) & 0xFFF + z = twos_comp(packed & 0x3FFFFFF, 26) + return (x, y, z) + else: + packed = UnsignedLong.read(buffer, ctx) + x = twos_comp(packed >> 38, 26) + z = twos_comp((packed >> 12) & 0x3FFFFFF, 26) + y = packed & 0xFFF + return (x, y, z) Position = PositionType()