Skip to content

Commit

Permalink
Fix: EntityPositionDeltaPacket.delta_{x,y,z} use wrong format
Browse files Browse the repository at this point in the history
  • Loading branch information
joodicator committed Aug 31, 2020
1 parent eae6e5c commit cf93923
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions minecraft/networking/packets/clientbound/play/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ def get_definition(context):
]

# The following transforms are retained for backward compatibility;
# they represent the delta values as fixed-point integers with 5 bits
# they represent the delta values as fixed-point integers with 12 bits
# of fractional part, regardless of the protocol version.
delta_x = attribute_transform('delta_x_float', lambda x: int(x * 32),
lambda x: x / 32)
delta_y = attribute_transform('delta_y_float', lambda y: int(y * 32),
lambda y: y / 32)
delta_z = attribute_transform('delta_z_float', lambda z: int(z * 32),
lambda z: z / 32)
delta_x = attribute_transform(
'delta_x_float', lambda x: int(x * 4096), lambda x: x / 4096)
delta_y = attribute_transform(
'delta_y_float', lambda y: int(y * 4096), lambda y: y / 4096)
delta_z = attribute_transform(
'delta_z_float', lambda z: int(z * 4096), lambda z: z / 4096)


class TimeUpdatePacket(Packet):
Expand Down
14 changes: 7 additions & 7 deletions tests/test_backward_compatible.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,12 @@ def test_join_game_packet(self):

def test_entity_position_delta_packet(self):
packet = clientbound.play.EntityPositionDeltaPacket()
packet.delta_x = -128
packet.delta_x = -32768
packet.delta_y = 33
packet.delta_z = 127
self.assertEqual(packet.delta_x_float, -4.0)
self.assertEqual(packet.delta_y_float, 1.03125)
self.assertEqual(packet.delta_z_float, 3.96875)
self.assertEqual(packet.delta_x, -128)
packet.delta_z = 32767
self.assertEqual(packet.delta_x_float, -8.0)
self.assertEqual(packet.delta_y_float, 0.008056640625)
self.assertEqual(packet.delta_z_float, 7.999755859375)
self.assertEqual(packet.delta_x, -32768)
self.assertEqual(packet.delta_y, 33)
self.assertEqual(packet.delta_z, 127)
self.assertEqual(packet.delta_z, 32767)

0 comments on commit cf93923

Please sign in to comment.