Improve metadata and auxiliary methods of existing packets.
* Add multi-attribute aliases to some packets, for user convenience. * Add support for writing PlayerListItemPacket. * Add 'fields' attributes to manually-read/written packet classes, implementing 'field_string' where appropriate to allow enable the default __repr__ implementation. * Modify data constructors where appropriate so that __repr__ implementations match their constructor protocols. * Improve comments on type aliases within packet classes. * Add/modify tests to cover the new functionality.
This commit is contained in:
1 parent
234e57716c
commit
e3d2b1a368
14 files changed
+389
-158
No files matched your search
@@ -4,7 +4,8 @@ from minecraft.networking.packets import (
|
||||
|
||||
from minecraft.networking.types import (
|
||||
Integer, FixedPointInteger, Angle, UnsignedByte, Byte, Boolean, UUID,
|
||||
Short, VarInt, Double, Float, String, Enum, Difficulty, Dimension, GameMode
|
||||
Short, VarInt, Double, Float, String, Enum, Difficulty, Dimension,
|
||||
GameMode, Vector, Direction, PositionAndLook, multi_attribute_alias,
|
||||
)
|
||||
|
||||
from .combat_event_packet import CombatEventPacket
|
||||
@@ -91,13 +92,9 @@ class JoinGamePacket(Packet):
|
||||
{'reduced_debug_info': Boolean},
|
||||
])
|
||||
|
||||
# JoinGamePacket.Difficulty is an alias for Difficulty
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
Difficulty = Difficulty
|
||||
|
||||
# JoinGamePacket.Gamemode is an alias for Gamemode
|
||||
GameMode = GameMode
|
||||
|
||||
# JoinGamePacket.Dimension is an alias for Dimension
|
||||
Dimension = Dimension
|
||||
|
||||
|
||||
@@ -115,7 +112,7 @@ class ServerDifficultyPacket(Packet):
|
||||
{'is_locked': Boolean} if context.protocol_version >= 464 else {},
|
||||
])
|
||||
|
||||
# ServerDifficultyPacket.Difficulty is an alias for Difficulty
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
Difficulty = Difficulty
|
||||
|
||||
|
||||
@@ -181,10 +178,22 @@ class SpawnPlayerPacket(Packet):
|
||||
else {'z': FixedPointInteger},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
{'current_item': Short} if context.protocol_version <= 49 else {},
|
||||
# TODO: read entity metadata
|
||||
{'current_item': Short} if context.protocol_version <= 49 else {}
|
||||
])
|
||||
|
||||
# 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 EntityVelocityPacket(Packet):
|
||||
@staticmethod
|
||||
@@ -258,13 +267,9 @@ class RespawnPacket(Packet):
|
||||
{'level_type': String},
|
||||
])
|
||||
|
||||
# RespawnPacket.Difficulty is an alias for Difficulty.
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
Difficulty = Difficulty
|
||||
|
||||
# RespawnPacket.Dimension is an alias for Dimension.
|
||||
Dimension = Dimension
|
||||
|
||||
# RespawnPacket.Gamemode is an alias for Gamemode.
|
||||
GameMode = GameMode
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user