34 lines
948 B
Python
34 lines
948 B
Python
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()
|