Add ClientSettingsPacket and PluginMessagePacket.
Improve Packet string representation.
This commit is contained in:
1 parent
3269a022a8
commit
e9f095de42
13 files changed
+291
-65
No files matched your search
@@ -1,10 +1,10 @@
|
||||
from minecraft.networking.packets import (
|
||||
Packet, PacketBuffer, KeepAlivePacket as AbstractKeepAlivePacket
|
||||
Packet, PacketBuffer, AbstractKeepAlivePacket, AbstractPluginMessagePacket
|
||||
)
|
||||
|
||||
from minecraft.networking.types import (
|
||||
Integer, UnsignedByte, Byte, Boolean, UUID, Short, Position,
|
||||
VarInt, Double, Float, String
|
||||
VarInt, Double, Float, String, Enum,
|
||||
)
|
||||
|
||||
from .combat_event_packet import CombatEventPacket
|
||||
@@ -32,6 +32,7 @@ def get_packets(context):
|
||||
SpawnObjectPacket,
|
||||
BlockChangePacket,
|
||||
MultiBlockChangePacket,
|
||||
PluginMessagePacket,
|
||||
}
|
||||
if context.protocol_version <= 47:
|
||||
packets |= {
|
||||
@@ -81,6 +82,11 @@ class ChatMessagePacket(Packet):
|
||||
{'json_data': String},
|
||||
{'position': Byte}]
|
||||
|
||||
class Position(Enum):
|
||||
CHAT = 0 # A player-initiated chat message.
|
||||
SYSTEM = 1 # The result of running a command.
|
||||
GAME_INFO = 2 # Displayed above the hotbar in vanilla clients.
|
||||
|
||||
|
||||
class DisconnectPacket(Packet):
|
||||
@staticmethod
|
||||
@@ -265,3 +271,12 @@ class MultiBlockChangePacket(Packet):
|
||||
|
||||
def write(self, socket, compression_threshold=None):
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
class PluginMessagePacket(AbstractPluginMessagePacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x18 if context.protocol_version >= 332 else \
|
||||
0x19 if context.protocol_version >= 318 else \
|
||||
0x18 if context.protocol_version >= 70 else \
|
||||
0x3F
|
||||
@@ -1,11 +1,11 @@
|
||||
from minecraft.networking.packets import Packet
|
||||
|
||||
from minecraft.networking.types import (
|
||||
Double, Float, Byte, VarInt
|
||||
Double, Float, Byte, VarInt, BitFieldEnum
|
||||
)
|
||||
|
||||
|
||||
class PlayerPositionAndLookPacket(Packet):
|
||||
class PlayerPositionAndLookPacket(Packet, BitFieldEnum):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x2F if context.protocol_version >= 336 else \
|
||||
@@ -25,6 +25,9 @@ class PlayerPositionAndLookPacket(Packet):
|
||||
{'teleport_id': VarInt} if context.protocol_version >= 107 else {},
|
||||
])
|
||||
|
||||
field_enum = classmethod(
|
||||
lambda cls, field: cls if field == 'flags' else None)
|
||||
|
||||
FLAG_REL_X = 0x01
|
||||
FLAG_REL_Y = 0x02
|
||||
FLAG_REL_Z = 0x04
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from minecraft.networking.packets import Packet
|
||||
|
||||
from minecraft.networking.types import (
|
||||
VarInt, UUID, Byte, Double, Integer, UnsignedByte, Short
|
||||
VarInt, UUID, Byte, Double, Integer, UnsignedByte, Short, Enum
|
||||
)
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ class SpawnObjectPacket(Packet):
|
||||
|
||||
packet_name = 'spawn object'
|
||||
|
||||
class EntityType:
|
||||
class EntityType(Enum):
|
||||
BOAT = 1
|
||||
ITEM_STACK = 2
|
||||
AREA_EFFECT_CLOUD = 3
|
||||
@@ -42,19 +42,12 @@ class SpawnObjectPacket(Packet):
|
||||
SPECTRAL_ARROW = 91
|
||||
DRAGON_FIREBALL = 93
|
||||
|
||||
@classmethod
|
||||
def get_type_by_id(cls, type_id):
|
||||
by_id = {id: entity for (entity, id) in
|
||||
cls.__dict__.items() if entity.isupper()}
|
||||
|
||||
return by_id[type_id]
|
||||
|
||||
def read(self, file_object):
|
||||
self.entity_id = VarInt.read(file_object)
|
||||
if self._context.protocol_version >= 49:
|
||||
self.objectUUID = UUID.read(file_object)
|
||||
type_id = Byte.read(file_object)
|
||||
self.type = SpawnObjectPacket.EntityType.get_type_by_id(type_id)
|
||||
self.type = SpawnObjectPacket.EntityType.name_from_value(type_id)
|
||||
|
||||
if self._context.protocol_version >= 100:
|
||||
self.x = Double.read(file_object)
|
||||
|
||||
Reference in new issue
Block a user