Decode forgotten chunk coordinates correctly
This commit is contained in:
1 parent
30e98d7e06
commit
05941f500a
2 files changed
+41
-3
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import struct
|
||||
import unittest
|
||||
from io import BytesIO
|
||||
|
||||
from minecraft.networking.modern import ForgetChunkPacket
|
||||
|
||||
|
||||
class TestForgetChunkPacket(unittest.TestCase):
|
||||
def test_unpacks_signed_chunk_coordinates_in_x_low_z_high_order(self):
|
||||
x, z = -9, -18
|
||||
packed = ((z & 0xFFFFFFFF) << 32) | (x & 0xFFFFFFFF)
|
||||
if packed >= 1 << 63:
|
||||
packed -= 1 << 64
|
||||
|
||||
packet = ForgetChunkPacket()
|
||||
packet.read(BytesIO(struct.pack('>q', packed)))
|
||||
|
||||
self.assertEqual((packet.x, packet.z), (x, z))
|
||||
|
||||
def test_unpacks_asymmetric_positive_and_negative_coordinates(self):
|
||||
x, z = 12, -37
|
||||
packed = ((z & 0xFFFFFFFF) << 32) | (x & 0xFFFFFFFF)
|
||||
if packed >= 1 << 63:
|
||||
packed -= 1 << 64
|
||||
|
||||
packet = ForgetChunkPacket()
|
||||
packet.read(BytesIO(struct.pack('>q', packed)))
|
||||
|
||||
self.assertEqual((packet.x, packet.z), (x, z))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user