Extract Hand enum classes to minecraft.networking.types.
This commit is contained in:
1 parent
ae0a3b3989
commit
38fa39a236
4 files changed
+37
-10
No files matched your search
@@ -3,7 +3,7 @@ from minecraft.networking.packets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from minecraft.networking.types 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
|
from .client_settings_packet import ClientSettingsPacket
|
||||||
@@ -91,7 +91,7 @@ class TeleportConfirmPacket(Packet):
|
|||||||
{'teleport_id': VarInt}]
|
{'teleport_id': VarInt}]
|
||||||
|
|
||||||
|
|
||||||
class AnimationPacket(Packet, Enum):
|
class AnimationPacket(Packet):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_id(context):
|
def get_id(context):
|
||||||
return 0x1D if context.protocol_version >= 345 else \
|
return 0x1D if context.protocol_version >= 345 else \
|
||||||
@@ -105,10 +105,11 @@ class AnimationPacket(Packet, Enum):
|
|||||||
get_definition = staticmethod(lambda context: [
|
get_definition = staticmethod(lambda context: [
|
||||||
{'hand': VarInt} if context.protocol_version >= 107 else {}])
|
{'hand': VarInt} if context.protocol_version >= 107 else {}])
|
||||||
field_enum = classmethod(
|
field_enum = classmethod(
|
||||||
lambda cls, field: cls if field == 'hand' else None)
|
lambda cls, field: RelativeHand if field == 'hand' else None)
|
||||||
|
|
||||||
HAND_MAIN = 0
|
# These fields are retained for backward compatibility.
|
||||||
HAND_OFF = 1
|
HAND_MAIN = RelativeHand.MAIN
|
||||||
|
HAND_OFF = RelativeHand.OFF
|
||||||
|
|
||||||
|
|
||||||
class ClientStatusPacket(Packet, Enum):
|
class ClientStatusPacket(Packet, Enum):
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from minecraft.networking.packets import Packet
|
from minecraft.networking.packets import Packet
|
||||||
from minecraft.networking.types import (
|
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: {
|
lambda cls, field: {
|
||||||
'chat_mode': cls.ChatMode,
|
'chat_mode': cls.ChatMode,
|
||||||
'displayed_skin_parts': cls.SkinParts,
|
'displayed_skin_parts': cls.SkinParts,
|
||||||
'main_hand': cls.Hand,
|
'main_hand': AbsoluteHand,
|
||||||
}.get(field))
|
}.get(field))
|
||||||
|
|
||||||
class ChatMode(Enum):
|
class ChatMode(Enum):
|
||||||
@@ -47,6 +48,5 @@ class ClientSettingsPacket(Packet):
|
|||||||
ALL = 0x7F
|
ALL = 0x7F
|
||||||
NONE = 0x00
|
NONE = 0x00
|
||||||
|
|
||||||
class Hand(Enum):
|
# This class alias is retained for backward compatibility.
|
||||||
LEFT = 0
|
Hand = AbsoluteHand
|
||||||
RIGHT = 1
|
|
||||||
@@ -293,3 +293,15 @@ class BitFieldEnum(Enum):
|
|||||||
ret_value |= cls_value
|
ret_value |= cls_value
|
||||||
if ret_value == value:
|
if ret_value == value:
|
||||||
return '|'.join(reversed(ret_names)) if ret_names else '0'
|
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
|
import unittest
|
||||||
|
|
||||||
from minecraft.networking import packets
|
from minecraft.networking import packets
|
||||||
|
from minecraft.networking import types
|
||||||
from minecraft.networking.packets import clientbound
|
from minecraft.networking.packets import clientbound
|
||||||
from minecraft.networking.packets import serverbound
|
from minecraft.networking.packets import serverbound
|
||||||
|
|
||||||
@@ -77,3 +78,16 @@ class LegacyPacketNamesTest(unittest.TestCase):
|
|||||||
serverbound.play.AnimationPacket)
|
serverbound.play.AnimationPacket)
|
||||||
self.assertEqual(packets.state_playing_serverbound,
|
self.assertEqual(packets.state_playing_serverbound,
|
||||||
serverbound.play.get_packets)
|
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)
|
||||||
Reference in new issue
Block a user