diff --git a/minecraft/networking/types/basic.py b/minecraft/networking/types/basic.py index 114e931..84481ed 100644 --- a/minecraft/networking/types/basic.py +++ b/minecraft/networking/types/basic.py @@ -122,12 +122,13 @@ class Angle(Type): @staticmethod def read(file_object): # Linearly transform angle in steps of 1/256 into steps of 1/360 - return 360 * UnsignedByte.read(file_object) / 255 + return 360 * UnsignedByte.read(file_object) / 256 @staticmethod def send(value, socket): # Normalize angle between 0 and 255 and convert to int. - UnsignedByte.send(round(255 * (value / 360)), socket) + + UnsignedByte.send(round(256 * ((value % 360) / 360)), socket) class VarInt(Type): diff --git a/tests/test_packets.py b/tests/test_packets.py index a50f631..045cda8 100644 --- a/tests/test_packets.py +++ b/tests/test_packets.py @@ -236,9 +236,9 @@ class TestReadWritePackets(unittest.TestCase): if context.protocol_version < 49: del packet2.velocity self._test_read_write_packet(packet, context, - yaw=360/255, pitch=360/255) + yaw=360/256, pitch=360/256) self._test_read_write_packet(packet2, context, - yaw=360/255, pitch=360/255) + yaw=360/256, pitch=360/256) def test_sound_effect_packet(self): for protocol_version in TEST_VERSIONS: diff --git a/tests/test_serialization.py b/tests/test_serialization.py index 8cc4547..4e58092 100644 --- a/tests/test_serialization.py +++ b/tests/test_serialization.py @@ -25,7 +25,7 @@ TEST_DATA = { UnsignedLong: [0, 400], Integer: [-1000, 1000], FixedPointInteger: [float(-13098.3435), float(-0.83), float(1000)], - Angle: [0, 360.0, 90, 47.12947238973, 214.588235], + Angle: [0, 360.0, 720, 47.12947238973, -108.7], VarInt: [1, 250, 50000, 10000000], Long: [50000000], Float: [21.000301], @@ -60,10 +60,10 @@ class SerializationTest(unittest.TestCase): self.assertAlmostEqual( test_data, deserialized, delta=1.0/32.0) elif data_type is Angle: - self.assertAlmostEqual(test_data, deserialized, - delta=360/255) + self.assertAlmostEqual(test_data % 360, deserialized, + delta=360/256) elif data_type is Float or data_type is Double: - self.assertAlmostEquals(test_data, deserialized, 3) + self.assertAlmostEqual(test_data, deserialized, 3) else: self.assertEqual(test_data, deserialized)