diff --git a/minecraft/networking/packets/clientbound/play/__init__.py b/minecraft/networking/packets/clientbound/play/__init__.py index 7d31b44..5e1137e 100644 --- a/minecraft/networking/packets/clientbound/play/__init__.py +++ b/minecraft/networking/packets/clientbound/play/__init__.py @@ -15,6 +15,7 @@ from .spawn_object_packet import SpawnObjectPacket from .block_change_packet import BlockChangePacket, MultiBlockChangePacket from .explosion_packet import ExplosionPacket from .sound_effect_packet import SoundEffectPacket +from . face_player_packet import FacePlayerPacket # Formerly known as state_playing_clientbound. @@ -48,6 +49,10 @@ def get_packets(context): packets |= { SoundEffectPacket, } + if context.protocol_version >= 352: + packets |= { + FacePlayerPacket + } return packets diff --git a/minecraft/networking/packets/clientbound/play/face_player_packet.py b/minecraft/networking/packets/clientbound/play/face_player_packet.py new file mode 100644 index 0000000..f2796ac --- /dev/null +++ b/minecraft/networking/packets/clientbound/play/face_player_packet.py @@ -0,0 +1,60 @@ +from minecraft.networking.types import ( + VarInt, Double, Boolean, FeetEyes +) + +from minecraft.networking.packets import Packet + + +class FacePlayerPacket(Packet): + @staticmethod + def get_id(context): + return 0x34 if context.protocol_version >= 471 else \ + 0x32 if context.protocol_version >= 451 else \ + 0x31 if context.protocol_version >= 389 else \ + 0x30 + + packet_name = 'face player' + + def read(self, file_object): + if self.context.protocol_version >= 353: + self.feet_or_eyes = VarInt.read(file_object) + self.x = Double.read(file_object) + self.y = Double.read(file_object) + self.z = Double.read(file_object) + is_entity = Boolean.read(file_object) + if is_entity: + # If the entity given by entity ID cannot be found, + # this packet should be treated as if is_entity was false. + self.entity_id = VarInt.read(file_object) + self.entity_feet_or_eyes = VarInt.read(file_object) + + else: # Protocol version 352 + is_entity = Boolean.read(file_object) + self.entity_id = VarInt.read(file_object) if is_entity else None + if not is_entity: + self.x = Double.read(file_object) + self.y = Double.read(file_object) + self.z = Double.read(file_object) + + def write_fields(self, packet_buffer): + if self.context.protocol_version >= 353: + VarInt.send(self.feet_or_eyes, packet_buffer) + Double.send(self.x, packet_buffer) + Double.send(self.y, packet_buffer) + Double.send(self.z, packet_buffer) + if self.entity_id: + VarInt.send(self.entity_id, packet_buffer) + VarInt.send(self.entity_feet_or_eyes, packet_buffer) + + else: # Protocol version 352 + if self.entity_id: + Boolean.send(True, packet_buffer) + VarInt.send(self.entity_id, packet_buffer) + else: + Boolean.send(False, packet_buffer) + Double.send(self.x, packet_buffer) + Double.send(self.y, packet_buffer) + Double.send(self.z, packet_buffer) + + # FacePlayerPacket.FeetEyes is an alias for FeetEyes + FeetEyes = FeetEyes \ No newline at end of file diff --git a/minecraft/networking/types/enum.py b/minecraft/networking/types/enum.py index 8d43374..c50b5ff 100644 --- a/minecraft/networking/types/enum.py +++ b/minecraft/networking/types/enum.py @@ -12,7 +12,7 @@ from .utility import Vector __all__ = ( 'Enum', 'BitFieldEnum', 'AbsoluteHand', 'RelativeHand', 'BlockFace', - 'Difficulty', 'Dimension', 'GameMode' + 'Difficulty', 'Dimension', 'GameMode', 'FeetEyes' ) @@ -106,3 +106,10 @@ class GameMode(Enum): CREATIVE = 1 ADVENTURE = 2 SPECTATOR = 3 + + +# Designation of an entity's head or eyes. +# Used in the Face Player Packet +class FeetEyes(Enum): + FEET = 0 + EYES = 1