2017-08-08 15:07:33 +02:00
|
|
|
from minecraft.networking.packets import (
|
2017-08-24 03:14:53 +02:00
|
|
|
Packet, AbstractKeepAlivePacket, AbstractPluginMessagePacket
|
2017-08-08 15:07:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
from minecraft.networking.types import (
|
2017-08-24 03:14:53 +02:00
|
|
|
Double, Float, Boolean, VarInt, String, Enum
|
2017-08-08 15:07:33 +02:00
|
|
|
)
|
|
|
|
|
2017-08-24 03:14:53 +02:00
|
|
|
from .client_settings_packet import ClientSettingsPacket
|
|
|
|
|
2017-08-08 15:07:33 +02:00
|
|
|
|
|
|
|
# Formerly known as state_playing_serverbound.
|
|
|
|
def get_packets(context):
|
|
|
|
packets = {
|
|
|
|
KeepAlivePacket,
|
|
|
|
ChatPacket,
|
|
|
|
PositionAndLookPacket,
|
|
|
|
AnimationPacket,
|
|
|
|
ClientStatusPacket,
|
2017-08-24 03:14:53 +02:00
|
|
|
ClientSettingsPacket,
|
|
|
|
PluginMessagePacket,
|
2017-08-08 15:07:33 +02:00
|
|
|
}
|
|
|
|
if context.protocol_version >= 107:
|
|
|
|
packets |= {
|
|
|
|
TeleportConfirmPacket,
|
|
|
|
}
|
|
|
|
return packets
|
|
|
|
|
|
|
|
|
|
|
|
class KeepAlivePacket(AbstractKeepAlivePacket):
|
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x0B if context.protocol_version >= 336 else \
|
|
|
|
0x0C if context.protocol_version >= 318 else \
|
|
|
|
0x0B if context.protocol_version >= 107 else \
|
|
|
|
0x00
|
|
|
|
|
|
|
|
|
|
|
|
class ChatPacket(Packet):
|
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x02 if context.protocol_version >= 336 else \
|
|
|
|
0x03 if context.protocol_version >= 318 else \
|
|
|
|
0x02 if context.protocol_version >= 107 else \
|
|
|
|
0x01
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_max_length(context):
|
|
|
|
return 256 if context.protocol_version >= 306 else \
|
|
|
|
100
|
|
|
|
|
|
|
|
@property
|
|
|
|
def max_length(self):
|
|
|
|
if self.context is not None:
|
|
|
|
return self.get_max_length(self.context)
|
|
|
|
|
|
|
|
packet_name = "chat"
|
|
|
|
definition = [
|
|
|
|
{'message': String}]
|
|
|
|
|
|
|
|
|
|
|
|
class PositionAndLookPacket(Packet):
|
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x0E if context.protocol_version >= 336 else \
|
|
|
|
0x0F if context.protocol_version >= 332 else \
|
|
|
|
0x0E if context.protocol_version >= 318 else \
|
|
|
|
0x0D if context.protocol_version >= 107 else \
|
|
|
|
0x06
|
|
|
|
|
|
|
|
packet_name = "position and look"
|
|
|
|
definition = [
|
|
|
|
{'x': Double},
|
|
|
|
{'feet_y': Double},
|
|
|
|
{'z': Double},
|
|
|
|
{'yaw': Float},
|
|
|
|
{'pitch': Float},
|
|
|
|
{'on_ground': Boolean}]
|
|
|
|
|
|
|
|
|
|
|
|
class TeleportConfirmPacket(Packet):
|
|
|
|
# Note: added between protocol versions 47 and 107.
|
|
|
|
id = 0x00
|
|
|
|
packet_name = "teleport confirm"
|
|
|
|
definition = [
|
|
|
|
{'teleport_id': VarInt}]
|
|
|
|
|
|
|
|
|
2017-08-24 03:14:53 +02:00
|
|
|
class AnimationPacket(Packet, Enum):
|
2017-08-08 15:07:33 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x1D if context.protocol_version >= 332 else \
|
|
|
|
0x1C if context.protocol_version >= 318 else \
|
|
|
|
0x1A if context.protocol_version >= 107 else \
|
|
|
|
0x0A
|
|
|
|
|
|
|
|
packet_name = "animation"
|
|
|
|
get_definition = staticmethod(lambda context: [
|
|
|
|
{'hand': VarInt} if context.protocol_version >= 107 else {}])
|
2017-08-24 03:14:53 +02:00
|
|
|
field_enum = classmethod(
|
|
|
|
lambda cls, field: cls if field == 'hand' else None)
|
|
|
|
|
2017-08-08 15:07:33 +02:00
|
|
|
HAND_MAIN = 0
|
|
|
|
HAND_OFF = 1
|
|
|
|
|
|
|
|
|
2017-08-24 03:14:53 +02:00
|
|
|
class ClientStatusPacket(Packet, Enum):
|
2017-08-08 15:07:33 +02:00
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x03 if context.protocol_version >= 336 else \
|
|
|
|
0x04 if context.protocol_version >= 318 else \
|
|
|
|
0x03 if context.protocol_version >= 80 else \
|
|
|
|
0x02 if context.protocol_version >= 67 else \
|
|
|
|
0x17 if context.protocol_version >= 49 else \
|
|
|
|
0x16
|
|
|
|
|
|
|
|
packet_name = "client status"
|
|
|
|
get_definition = staticmethod(lambda context: [
|
|
|
|
{'action_id': VarInt}])
|
2017-08-24 03:14:53 +02:00
|
|
|
field_enum = classmethod(
|
|
|
|
lambda cls, field: cls if field == 'action_id' else None)
|
2017-08-08 15:07:33 +02:00
|
|
|
|
|
|
|
RESPAWN = 0
|
|
|
|
REQUEST_STATS = 1
|
|
|
|
# Note: Open Inventory (id 2) was removed in protocol version 319
|
|
|
|
OPEN_INVENTORY = 2
|
2017-08-24 03:14:53 +02:00
|
|
|
|
|
|
|
|
|
|
|
class PluginMessagePacket(AbstractPluginMessagePacket):
|
|
|
|
@staticmethod
|
|
|
|
def get_id(context):
|
|
|
|
return 0x09 if context.protocol_version >= 336 else \
|
|
|
|
0x0A if context.protocol_version >= 317 else \
|
|
|
|
0x09 if context.protocol_version >= 94 else \
|
|
|
|
0x17
|