Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SpawnMobPacket, Entity & Vehicle Movement Relevant Packets #140

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
109 changes: 105 additions & 4 deletions minecraft/networking/packets/clientbound/play/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

from minecraft.networking.types import (
Integer, FixedPointInteger, Angle, UnsignedByte, Byte, Boolean, UUID,
Short, VarInt, Double, Float, String, Enum, Difficulty, Dimension,
GameMode, Vector, Direction, PositionAndLook, multi_attribute_alias,
Short, VarInt, Double, Float, String, Position, Enum, Difficulty,
Dimension, GameMode, Vector, Direction, PositionAndLook,
multi_attribute_alias,
)

from .combat_event_packet import CombatEventPacket
Expand All @@ -17,6 +18,8 @@
from .explosion_packet import ExplosionPacket
from .sound_effect_packet import SoundEffectPacket
from .face_player_packet import FacePlayerPacket
from .destroy_entities_packet import DestroyEntitiesPacket
from .spawn_mob_packet import SpawnMobPacket


# Formerly known as state_playing_clientbound.
Expand All @@ -41,7 +44,12 @@ def get_packets(context):
RespawnPacket,
PluginMessagePacket,
PlayerListHeaderAndFooterPacket,
EntityLookPacket
EntityLookPacket,
EntityPacket,
DestroyEntitiesPacket,
SpawnMobPacket,
BlockActionPacket,
EntityHeadLookPacket,
}
if context.protocol_version <= 47:
packets |= {
Expand All @@ -50,10 +58,11 @@ def get_packets(context):
if context.protocol_version >= 94:
packets |= {
SoundEffectPacket,
VehicleMovePacket,
}
if context.protocol_version >= 352:
packets |= {
FacePlayerPacket
FacePlayerPacket,
}
return packets

Expand Down Expand Up @@ -321,3 +330,95 @@ def get_id(context):
{'pitch': Angle},
{'on_ground': Boolean}
]


class EntityPacket(Packet):
@staticmethod
def get_id(context):
return 0x2B if context.protocol_version >= 471 else \
0x27 if context.protocol_version >= 389 else \
0x26 if context.protocol_version >= 345 else \
0x25 if context.protocol_version >= 332 else \
0x29 if context.protocol_version >= 318 else \
0x28 if context.protocol_version >= 94 else \
0x29 if context.protocol_version >= 70 else \
0x14

packet_name = "entity"
definition = [{"entity_id": VarInt}]


class VehicleMovePacket(Packet):
@staticmethod
def get_id(context):
return 0x2C if context.protocol_version >= 471 else \
0x2B if context.protocol_version >= 389 else \
0x2A if context.protocol_version >= 345 else \
0x29 if context.protocol_version >= 332 else \
0x2A if context.protocol_version >= 318 else \
0x29 # Note: Packet added in protocol version 94

packet_name = "vehicle move clientbound"
definition = [
{'x': Double},
{'y': Double},
{'z': Double},
{'yaw': Float},
{'pitch': Float},
]

# Access the 'x', 'y', 'z' fields as a Vector tuple.
position = multi_attribute_alias(Vector, 'x', 'y', 'z')

# Access the 'yaw', 'pitch' fields as a Direction tuple.
look = multi_attribute_alias(Direction, 'yaw', 'pitch')

# Access the 'x', 'y', 'z', 'yaw', 'pitch' fields as a PositionAndLook.
# NOTE: modifying the object retrieved from this property will not change
# the packet; it can only be changed by attribute or property assignment.
position_and_look = multi_attribute_alias(
PositionAndLook, 'x', 'y', 'z', 'yaw', 'pitch')


class BlockActionPacket(Packet):
@staticmethod
def get_id(context):
return 0x0A if context.protocol_version >= 332 else \
0x0B if context.protocol_version >= 318 else \
0x0A if context.protocol_version >= 70 else \
0x25 if context.protocol_version >= 69 else \
0x24

packet_name = "block action"
get_definition = staticmethod(lambda context: [
{'location': Position},
{'block_type': VarInt} if context.protocol_version == 347 else {},
{'action_id': UnsignedByte}, # TODO Interpret action_id and
{'action_param': UnsignedByte}, # action_param fields.
{'block_type': VarInt} if context.protocol_version != 347 else {},
])


class EntityHeadLookPacket(Packet):
@staticmethod
def get_id(context):
return 0x3B if context.protocol_version >= 471 else \
0x39 if context.protocol_version >= 461 else \
0x3A if context.protocol_version >= 451 else \
0x39 if context.protocol_version >= 389 else \
0x38 if context.protocol_version >= 352 else \
0x37 if context.protocol_version >= 345 else \
0x36 if context.protocol_version >= 336 else \
0x35 if context.protocol_version >= 332 else \
0x36 if context.protocol_version >= 318 else \
0x34 if context.protocol_version >= 70 else \
0x19

packet_name = 'entity head look'

fields = 'entity_id', 'head_yaw'

definition = [
{'entity_id': VarInt},
{'head_yaw': Angle},
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from minecraft.networking.packets import Packet

from minecraft.networking.types import VarInt


class DestroyEntitiesPacket(Packet):
@staticmethod
def get_id(context):
return 0x37 if context.protocol_version >= 471 else \
0x35 if context.protocol_version >= 461 else \
0x36 if context.protocol_version >= 451 else \
0x35 if context.protocol_version >= 389 else \
0x34 if context.protocol_version >= 352 else \
0x33 if context.protocol_version >= 345 else \
0x32 if context.protocol_version >= 336 else \
0x31 if context.protocol_version >= 332 else \
0x32 if context.protocol_version >= 318 else \
0x30 if context.protocol_version >= 70 else \
0x13

packet_name = 'destroy entities'

fields = 'entity_ids',

def read(self, file_object):
self.entity_ids = [VarInt.read(file_object)
for i in range(VarInt.read(file_object))]

def write_fields(self, packet_buffer):
count = len(self.entity_ids)
VarInt.send(count, packet_buffer)
for entity_id in self.entity_ids:
VarInt.send(entity_id, packet_buffer)
Loading