Implement type 'Angle', packet 'EntityLookPacket' and fix Packet Types

Remarks: I chose to implement an angle between 0-360 degrees as opposed to -180 - 180. linear transformation, the maths was far simpler converting an UnsignedByte into positive values instead of a Byte into negative and positive
This commit is contained in:
Zachy committed 2019-05-15 13:51:31 +01:00
1 parent d7b560a9f4
commit 7361f761f5
3 files changed
+42 -8

No files matched your search

@@ -5,6 +5,7 @@ from minecraft.networking.packets import (
from minecraft.networking.types import (
Integer, FixedPointInteger, UnsignedByte, Byte, Boolean, UUID, Short,
VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode,
Angle
)
from .combat_event_packet import CombatEventPacket
@@ -40,6 +41,7 @@ def get_packets(context):
RespawnPacket,
PluginMessagePacket,
PlayerListHeaderAndFooterPacket,
EntityLookPacket
}
if context.protocol_version <= 47:
packets |= {
@@ -178,8 +180,8 @@ class SpawnPlayerPacket(Packet):
else {'y': FixedPointInteger},
{'z': Double} if context.protocol_version >= 100
else {'z': FixedPointInteger},
{'yaw': Float},
{'pitch': Float},
{'yaw': Angle},
{'pitch': Angle},
# TODO: read entity metadata
{'current_item': Short} if context.protocol_version <= 49 else {}
])
@@ -296,3 +298,22 @@ class PlayerListHeaderAndFooterPacket(Packet):
definition = [
{'header': String},
{'footer': String}]
class EntityLookPacket(Packet):
@staticmethod
def get_id(context):
return 0x2A if context.protocol_version >= 389 else \
0x29 if context.protocol_version >= 345 else \
0x28 if context.protocol_version >= 318 else \
0x27 if context.protocol_version >= 94 else \
0x28 if context.protocol_version >= 70 else \
0x16
packet_name = 'entity look'
definition = [
{'entity_id': VarInt},
{'yaw': Angle},
{'pitch': Angle},
{'on_ground': Boolean}
]
@@ -2,7 +2,7 @@ from minecraft.networking.packets import Packet
from minecraft.networking.types.utility import descriptor
from minecraft.networking.types import (
VarInt, UUID, Byte, Double, Integer, UnsignedByte, Short, Enum, Vector,
VarInt, UUID, Byte, Double, Integer, Angle, Short, Enum, Vector,
PositionAndLook, attribute_alias, multi_attribute_alias,
)
@@ -103,7 +103,7 @@ class SpawnObjectPacket(Packet):
for attr in 'x', 'y', 'z':
setattr(self, attr, xyz_type.read(file_object))
for attr in 'pitch', 'yaw':
setattr(self, attr, UnsignedByte.read(file_object))
setattr(self, attr, Angle.read(file_object))
self.data = Integer.read(file_object)
if self.context.protocol_version >= 49 or self.data > 0:
@@ -125,7 +125,7 @@ class SpawnObjectPacket(Packet):
for coord in self.x, self.y, self.z:
xyz_type.send(coord, packet_buffer)
for coord in self.pitch, self.yaw:
UnsignedByte.send(coord, packet_buffer)
Angle.send(coord, packet_buffer)
Integer.send(self.data, packet_buffer)
if self.context.protocol_version >= 49 or self.data > 0: