mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2025-01-22 07:31:29 +01:00
Extract Hand enum classes to minecraft.networking.types.
This commit is contained in:
parent
ae0a3b3989
commit
38fa39a236
@ -3,7 +3,7 @@ from minecraft.networking.packets import (
|
||||
)
|
||||
|
||||
from minecraft.networking.types import (
|
||||
Double, Float, Boolean, VarInt, String, Enum
|
||||
Double, Float, Boolean, VarInt, String, Enum, RelativeHand
|
||||
)
|
||||
|
||||
from .client_settings_packet import ClientSettingsPacket
|
||||
@ -91,7 +91,7 @@ class TeleportConfirmPacket(Packet):
|
||||
{'teleport_id': VarInt}]
|
||||
|
||||
|
||||
class AnimationPacket(Packet, Enum):
|
||||
class AnimationPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x1D if context.protocol_version >= 345 else \
|
||||
@ -105,10 +105,11 @@ class AnimationPacket(Packet, Enum):
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'hand': VarInt} if context.protocol_version >= 107 else {}])
|
||||
field_enum = classmethod(
|
||||
lambda cls, field: cls if field == 'hand' else None)
|
||||
lambda cls, field: RelativeHand if field == 'hand' else None)
|
||||
|
||||
HAND_MAIN = 0
|
||||
HAND_OFF = 1
|
||||
# These fields are retained for backward compatibility.
|
||||
HAND_MAIN = RelativeHand.MAIN
|
||||
HAND_OFF = RelativeHand.OFF
|
||||
|
||||
|
||||
class ClientStatusPacket(Packet, Enum):
|
||||
|
@ -1,6 +1,7 @@
|
||||
from minecraft.networking.packets import Packet
|
||||
from minecraft.networking.types import (
|
||||
String, Byte, VarInt, Boolean, UnsignedByte, Enum, BitFieldEnum
|
||||
String, Byte, VarInt, Boolean, UnsignedByte, Enum, BitFieldEnum,
|
||||
AbsoluteHand
|
||||
)
|
||||
|
||||
|
||||
@ -27,7 +28,7 @@ class ClientSettingsPacket(Packet):
|
||||
lambda cls, field: {
|
||||
'chat_mode': cls.ChatMode,
|
||||
'displayed_skin_parts': cls.SkinParts,
|
||||
'main_hand': cls.Hand,
|
||||
'main_hand': AbsoluteHand,
|
||||
}.get(field))
|
||||
|
||||
class ChatMode(Enum):
|
||||
@ -47,6 +48,5 @@ class ClientSettingsPacket(Packet):
|
||||
ALL = 0x7F
|
||||
NONE = 0x00
|
||||
|
||||
class Hand(Enum):
|
||||
LEFT = 0
|
||||
RIGHT = 1
|
||||
# This class alias is retained for backward compatibility.
|
||||
Hand = AbsoluteHand
|
||||
|
@ -293,3 +293,15 @@ class BitFieldEnum(Enum):
|
||||
ret_value |= cls_value
|
||||
if ret_value == value:
|
||||
return '|'.join(reversed(ret_names)) if ret_names else '0'
|
||||
|
||||
|
||||
# Designation of one of a player's hands, in absolute terms.
|
||||
class AbsoluteHand(Enum):
|
||||
LEFT = 0
|
||||
RIGHT = 1
|
||||
|
||||
|
||||
# Designation of one a player's hands, relative to a choice of main/off hand.
|
||||
class RelativeHand(Enum):
|
||||
MAIN = 0
|
||||
OFF = 1
|
||||
|
@ -1,6 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from minecraft.networking import packets
|
||||
from minecraft.networking import types
|
||||
from minecraft.networking.packets import clientbound
|
||||
from minecraft.networking.packets import serverbound
|
||||
|
||||
@ -77,3 +78,16 @@ class LegacyPacketNamesTest(unittest.TestCase):
|
||||
serverbound.play.AnimationPacket)
|
||||
self.assertEqual(packets.state_playing_serverbound,
|
||||
serverbound.play.get_packets)
|
||||
|
||||
|
||||
class ClassMemberAliasesTest(unittest.TestCase):
|
||||
def test_alias_values(self):
|
||||
self.assertEqual(serverbound.play.AnimationPacket.HAND_MAIN,
|
||||
types.RelativeHand.MAIN)
|
||||
self.assertEqual(serverbound.play.AnimationPacket.HAND_OFF,
|
||||
types.RelativeHand.OFF)
|
||||
|
||||
self.assertEqual(serverbound.play.ClientSettingsPacket.Hand.LEFT,
|
||||
types.AbsoluteHand.LEFT)
|
||||
self.assertEqual(serverbound.play.ClientSettingsPacket.Hand.RIGHT,
|
||||
types.AbsoluteHand.RIGHT)
|
||||
|
Loading…
Reference in New Issue
Block a user