Fix: non-monotonic protocol versions are not correctly handled
After 1.16.3, Mojang started publishing snapshot, pre-release and release
candidate versions of Minecraft with protocol version numbers of the form
`(1 << 30) | n' where 'n' is a small non-negative integer increasing with each
such version; the release versions continued to use the old format. For
example, these are the last 8 published Minecraft versions as of this commit:
release 1.16.3 uses protocol version 753
pre-release 1.16.4-pre1 uses protocol version 1073741825 == (1 << 30) | 1
pre-release 1.16.4-pre2 uses protocol version 1073741826 == (1 << 30) | 2
release candidate 1.16.4-rc1 uses protocol version 1073741827 == (1 << 30) | 3
release 1.16.4 uses protocol version 754
snapshot 20w45a uses protocol version 1073741829 == (1 << 30) | 5
snapshot 20w46a uses protocol version 1073741830 == (1 << 30) | 6
snapshot 20w48a uses protocol version 1073741831 == (1 << 30) | 7
This means that protocol versions no longer increase monotonically with respect
to publication history, a property that was assumed to hold in much of
pyCraft's code relating to support of multiple protocol versions. This commit
rectifies the issue by replacing any comparison of protocol versions by their
numerical value with a comparison based on their publication time.
Newly defined is the dictionary `minecraft.PROTOCOL_VERSION_INDICES', which
maps each known protocol version to its index in the protocol chronology. As
such, the bound method `minecraft.PROTOCOL_VERSION_INDICES.get` can be used as
a key function for the built-in `sorted`, `min` and `max` functions to collate
protocol versions chronologically.
Two utility functions are provided for direct comparison of protocol versions:
`minecraft.utility.protocol_earlier` and
`minecraft.utility.protocol_earlier_eq`.
Additionally, four methods are added to the `ConnectionContext` type to ease
the most common cases where the protocol of a given context must be compared to
a given version number:
`minecraft.connection.ConnectionContext.protocol_earlier`,
`minecraft.connection.ConnectionContext.protocol_earlier_eq`,
`minecraft.connection.ConnectionContext.protocol_later` and
`minecraft.connection.ConnectionContext.protocol_later_eq`.
This commit is contained in:
1 parent
4052136d30
commit
969419da3f
29 files changed
+1241
-983
No files matched your search
@@ -1,8 +1,8 @@
|
||||
'''
|
||||
NOTE: The packet classes in __all_legacy_packets__ exported by this
|
||||
module are included only for backward compatibility, and should not
|
||||
be used in new code, as (1) they do not include all packets present
|
||||
in pyCraft, and (2) some are named oddly, for historical reasons.
|
||||
NOTE: The packet classes exported by this module are included only for backward
|
||||
compatibility, and should not be used in new code, as (1) they do not include
|
||||
all packets present in pyCraft, and (2) some are named oddly, for historical
|
||||
reasons.
|
||||
|
||||
Use the packet classes under packets.clientbound.* and
|
||||
packets.serverbound.* instead.
|
||||
@@ -60,26 +60,3 @@ from .serverbound.play import PositionAndLookPacket
|
||||
from .serverbound.play import TeleportConfirmPacket
|
||||
from .serverbound.play import AnimationPacket as AnimationPacketServerbound
|
||||
from .serverbound.play import get_packets as state_playing_serverbound
|
||||
|
||||
__all_legacy_packets__ = (
|
||||
state_handshake_clientbound, HandShakePacket,
|
||||
state_handshake_serverbound, ResponsePacket,
|
||||
PingPacketResponse, state_status_clientbound,
|
||||
RequestPacket, PingPacket, state_status_serverbound,
|
||||
DisconnectPacket, EncryptionRequestPacket, LoginSuccessPacket,
|
||||
SetCompressionPacket, state_login_clientbound,
|
||||
LoginStartPacket, EncryptionResponsePacket,
|
||||
state_login_serverbound, KeepAlivePacketClientbound,
|
||||
KeepAlivePacketServerbound, JoinGamePacket, ChatMessagePacket,
|
||||
PlayerPositionAndLookPacket, DisconnectPacketPlayState,
|
||||
SetCompressionPacketPlayState, PlayerListItemPacket,
|
||||
MapPacket, state_playing_clientbound, ChatPacket,
|
||||
PositionAndLookPacket, TeleportConfirmPacket,
|
||||
AnimationPacketServerbound, state_playing_serverbound,
|
||||
KeepAlivePacket,
|
||||
)
|
||||
|
||||
__all_other__ = (
|
||||
Packet, PacketBuffer, PacketListener,
|
||||
AbstractKeepAlivePacket, AbstractPluginMessagePacket,
|
||||
)
|
||||
@@ -13,7 +13,7 @@ def get_packets(context):
|
||||
LoginSuccessPacket,
|
||||
SetCompressionPacket,
|
||||
}
|
||||
if context.protocol_version >= 385:
|
||||
if context.protocol_later_eq(385):
|
||||
packets |= {
|
||||
PluginRequestPacket,
|
||||
}
|
||||
@@ -23,8 +23,8 @@ def get_packets(context):
|
||||
class DisconnectPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x00 if context.protocol_version >= 391 else \
|
||||
0x01 if context.protocol_version >= 385 else \
|
||||
return 0x00 if context.protocol_later_eq(391) else \
|
||||
0x01 if context.protocol_later_eq(385) else \
|
||||
0x00
|
||||
|
||||
packet_name = "disconnect"
|
||||
@@ -35,8 +35,8 @@ class DisconnectPacket(Packet):
|
||||
class EncryptionRequestPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x01 if context.protocol_version >= 391 else \
|
||||
0x02 if context.protocol_version >= 385 else \
|
||||
return 0x01 if context.protocol_later_eq(391) else \
|
||||
0x02 if context.protocol_later_eq(385) else \
|
||||
0x01
|
||||
|
||||
packet_name = "encryption request"
|
||||
@@ -49,13 +49,13 @@ class EncryptionRequestPacket(Packet):
|
||||
class LoginSuccessPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x02 if context.protocol_version >= 391 else \
|
||||
0x03 if context.protocol_version >= 385 else \
|
||||
return 0x02 if context.protocol_later_eq(391) else \
|
||||
0x03 if context.protocol_later_eq(385) else \
|
||||
0x02
|
||||
|
||||
packet_name = "login success"
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'UUID': UUID if context.protocol_version >= 707 else String},
|
||||
{'UUID': UUID if context.protocol_later_eq(707) else String},
|
||||
{'Username': String}
|
||||
])
|
||||
|
||||
@@ -63,8 +63,8 @@ class LoginSuccessPacket(Packet):
|
||||
class SetCompressionPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x03 if context.protocol_version >= 391 else \
|
||||
0x04 if context.protocol_version >= 385 else \
|
||||
return 0x03 if context.protocol_later_eq(391) else \
|
||||
0x04 if context.protocol_later_eq(385) else \
|
||||
0x03
|
||||
|
||||
packet_name = "set compression"
|
||||
@@ -89,7 +89,7 @@ class PluginRequestPacket(Packet):
|
||||
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x04 if context.protocol_version >= 391 else \
|
||||
return 0x04 if context.protocol_later_eq(391) else \
|
||||
0x00
|
||||
|
||||
packet_name = 'login plugin request'
|
||||
|
||||
@@ -46,15 +46,15 @@ def get_packets(context):
|
||||
PlayerListHeaderAndFooterPacket,
|
||||
EntityLookPacket
|
||||
}
|
||||
if context.protocol_version <= 47:
|
||||
if context.protocol_earlier_eq(47):
|
||||
packets |= {
|
||||
SetCompressionPacket,
|
||||
}
|
||||
if context.protocol_version >= 94:
|
||||
if context.protocol_later_eq(94):
|
||||
packets |= {
|
||||
SoundEffectPacket,
|
||||
}
|
||||
if context.protocol_version >= 352:
|
||||
if context.protocol_later_eq(352):
|
||||
packets |= {
|
||||
FacePlayerPacket
|
||||
}
|
||||
@@ -64,32 +64,32 @@ def get_packets(context):
|
||||
class KeepAlivePacket(AbstractKeepAlivePacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x1F if context.protocol_version >= 741 else \
|
||||
0x20 if context.protocol_version >= 721 else \
|
||||
0x21 if context.protocol_version >= 550 else \
|
||||
0x20 if context.protocol_version >= 471 else \
|
||||
0x21 if context.protocol_version >= 389 else \
|
||||
0x20 if context.protocol_version >= 345 else \
|
||||
0x1F if context.protocol_version >= 332 else \
|
||||
0x20 if context.protocol_version >= 318 else \
|
||||
0x1F if context.protocol_version >= 107 else \
|
||||
return 0x1F if context.protocol_later_eq(741) else \
|
||||
0x20 if context.protocol_later_eq(721) else \
|
||||
0x21 if context.protocol_later_eq(550) else \
|
||||
0x20 if context.protocol_later_eq(471) else \
|
||||
0x21 if context.protocol_later_eq(389) else \
|
||||
0x20 if context.protocol_later_eq(345) else \
|
||||
0x1F if context.protocol_later_eq(332) else \
|
||||
0x20 if context.protocol_later_eq(318) else \
|
||||
0x1F if context.protocol_later_eq(107) else \
|
||||
0x00
|
||||
|
||||
|
||||
class ServerDifficultyPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x0D if context.protocol_version >= 721 else \
|
||||
0x0E if context.protocol_version >= 550 else \
|
||||
0x0D if context.protocol_version >= 332 else \
|
||||
0x0E if context.protocol_version >= 318 else \
|
||||
0x0D if context.protocol_version >= 70 else \
|
||||
return 0x0D if context.protocol_later_eq(721) else \
|
||||
0x0E if context.protocol_later_eq(550) else \
|
||||
0x0D if context.protocol_later_eq(332) else \
|
||||
0x0E if context.protocol_later_eq(318) else \
|
||||
0x0D if context.protocol_later_eq(70) else \
|
||||
0x41
|
||||
|
||||
packet_name = 'server difficulty'
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'difficulty': UnsignedByte},
|
||||
{'is_locked': Boolean} if context.protocol_version >= 464 else {},
|
||||
{'is_locked': Boolean} if context.protocol_later_eq(464) else {},
|
||||
])
|
||||
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
@@ -99,19 +99,19 @@ class ServerDifficultyPacket(Packet):
|
||||
class ChatMessagePacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x0E if context.protocol_version >= 721 else \
|
||||
0x0F if context.protocol_version >= 550 else \
|
||||
0x0E if context.protocol_version >= 343 else \
|
||||
0x0F if context.protocol_version >= 332 else \
|
||||
0x10 if context.protocol_version >= 317 else \
|
||||
0x0F if context.protocol_version >= 107 else \
|
||||
return 0x0E if context.protocol_later_eq(721) else \
|
||||
0x0F if context.protocol_later_eq(550) else \
|
||||
0x0E if context.protocol_later_eq(343) else \
|
||||
0x0F if context.protocol_later_eq(332) else \
|
||||
0x10 if context.protocol_later_eq(317) else \
|
||||
0x0F if context.protocol_later_eq(107) else \
|
||||
0x02
|
||||
|
||||
packet_name = "chat message"
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'json_data': String},
|
||||
{'position': Byte},
|
||||
{'sender': UUID} if context.protocol_version >= 718 else {},
|
||||
{'sender': UUID} if context.protocol_later_eq(718) else {},
|
||||
])
|
||||
|
||||
class Position(Enum):
|
||||
@@ -123,14 +123,14 @@ class ChatMessagePacket(Packet):
|
||||
class DisconnectPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x19 if context.protocol_version >= 741 else \
|
||||
0x1A if context.protocol_version >= 721 else \
|
||||
0x1B if context.protocol_version >= 550 else \
|
||||
0x1A if context.protocol_version >= 471 else \
|
||||
0x1B if context.protocol_version >= 345 else \
|
||||
0x1A if context.protocol_version >= 332 else \
|
||||
0x1B if context.protocol_version >= 318 else \
|
||||
0x1A if context.protocol_version >= 107 else \
|
||||
return 0x19 if context.protocol_later_eq(741) else \
|
||||
0x1A if context.protocol_later_eq(721) else \
|
||||
0x1B if context.protocol_later_eq(550) else \
|
||||
0x1A if context.protocol_later_eq(471) else \
|
||||
0x1B if context.protocol_later_eq(345) else \
|
||||
0x1A if context.protocol_later_eq(332) else \
|
||||
0x1B if context.protocol_later_eq(318) else \
|
||||
0x1A if context.protocol_later_eq(107) else \
|
||||
0x40
|
||||
|
||||
packet_name = "disconnect"
|
||||
@@ -150,23 +150,23 @@ class SetCompressionPacket(Packet):
|
||||
class SpawnPlayerPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x04 if context.protocol_version >= 721 else \
|
||||
0x05 if context.protocol_version >= 67 else \
|
||||
return 0x04 if context.protocol_later_eq(721) else \
|
||||
0x05 if context.protocol_later_eq(67) else \
|
||||
0x0C
|
||||
|
||||
packet_name = 'spawn player'
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'entity_id': VarInt},
|
||||
{'player_UUID': UUID},
|
||||
{'x': Double} if context.protocol_version >= 100
|
||||
{'x': Double} if context.protocol_later_eq(100)
|
||||
else {'x': FixedPoint(Integer)},
|
||||
{'y': Double} if context.protocol_version >= 100
|
||||
{'y': Double} if context.protocol_later_eq(100)
|
||||
else {'y': FixedPoint(Integer)},
|
||||
{'z': Double} if context.protocol_version >= 100
|
||||
{'z': Double} if context.protocol_later_eq(100)
|
||||
else {'z': FixedPoint(Integer)},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
{'current_item': Short} if context.protocol_version <= 49 else {},
|
||||
{'current_item': Short} if context.protocol_earlier_eq(49) else {},
|
||||
# TODO: read entity metadata (protocol < 550)
|
||||
])
|
||||
|
||||
@@ -186,20 +186,20 @@ class SpawnPlayerPacket(Packet):
|
||||
class EntityVelocityPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x46 if context.protocol_version >= 721 else \
|
||||
0x47 if context.protocol_version >= 707 else \
|
||||
0x46 if context.protocol_version >= 550 else \
|
||||
0x45 if context.protocol_version >= 471 else \
|
||||
0x41 if context.protocol_version >= 461 else \
|
||||
0x42 if context.protocol_version >= 451 else \
|
||||
0x41 if context.protocol_version >= 389 else \
|
||||
0x40 if context.protocol_version >= 352 else \
|
||||
0x3F if context.protocol_version >= 345 else \
|
||||
0x3E if context.protocol_version >= 336 else \
|
||||
0x3D if context.protocol_version >= 332 else \
|
||||
0x3B if context.protocol_version >= 86 else \
|
||||
0x3C if context.protocol_version >= 77 else \
|
||||
0x3B if context.protocol_version >= 67 else \
|
||||
return 0x46 if context.protocol_later_eq(721) else \
|
||||
0x47 if context.protocol_later_eq(707) else \
|
||||
0x46 if context.protocol_later_eq(550) else \
|
||||
0x45 if context.protocol_later_eq(471) else \
|
||||
0x41 if context.protocol_later_eq(461) else \
|
||||
0x42 if context.protocol_later_eq(451) else \
|
||||
0x41 if context.protocol_later_eq(389) else \
|
||||
0x40 if context.protocol_later_eq(352) else \
|
||||
0x3F if context.protocol_later_eq(345) else \
|
||||
0x3E if context.protocol_later_eq(336) else \
|
||||
0x3D if context.protocol_later_eq(332) else \
|
||||
0x3B if context.protocol_later_eq(86) else \
|
||||
0x3C if context.protocol_later_eq(77) else \
|
||||
0x3B if context.protocol_later_eq(67) else \
|
||||
0x12
|
||||
|
||||
packet_name = 'entity velocity'
|
||||
@@ -214,14 +214,14 @@ class EntityVelocityPacket(Packet):
|
||||
class EntityPositionDeltaPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x27 if context.protocol_version >= 741 else \
|
||||
0x28 if context.protocol_version >= 721 else \
|
||||
0x29 if context.protocol_version >= 550 else \
|
||||
0x28 if context.protocol_version >= 389 else \
|
||||
0x27 if context.protocol_version >= 345 else \
|
||||
0x26 if context.protocol_version >= 318 else \
|
||||
0x25 if context.protocol_version >= 94 else \
|
||||
0x26 if context.protocol_version >= 70 else \
|
||||
return 0x27 if context.protocol_later_eq(741) else \
|
||||
0x28 if context.protocol_later_eq(721) else \
|
||||
0x29 if context.protocol_later_eq(550) else \
|
||||
0x28 if context.protocol_later_eq(389) else \
|
||||
0x27 if context.protocol_later_eq(345) else \
|
||||
0x26 if context.protocol_later_eq(318) else \
|
||||
0x25 if context.protocol_later_eq(94) else \
|
||||
0x26 if context.protocol_later_eq(70) else \
|
||||
0x15
|
||||
|
||||
packet_name = "entity position delta"
|
||||
@@ -229,7 +229,7 @@ class EntityPositionDeltaPacket(Packet):
|
||||
@staticmethod
|
||||
def get_definition(context):
|
||||
delta_type = FixedPoint(Short, 12) \
|
||||
if context.protocol_version >= 106 else \
|
||||
if context.protocol_later_eq(106) else \
|
||||
FixedPoint(Byte)
|
||||
return [
|
||||
{'entity_id': VarInt},
|
||||
@@ -253,18 +253,18 @@ class EntityPositionDeltaPacket(Packet):
|
||||
class TimeUpdatePacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x4E if context.protocol_version >= 721 else \
|
||||
0x4F if context.protocol_version >= 550 else \
|
||||
0x4E if context.protocol_version >= 471 else \
|
||||
0x4A if context.protocol_version >= 461 else \
|
||||
0x4B if context.protocol_version >= 451 else \
|
||||
0x4A if context.protocol_version >= 389 else \
|
||||
0x49 if context.protocol_version >= 352 else \
|
||||
0x48 if context.protocol_version >= 345 else \
|
||||
0x47 if context.protocol_version >= 336 else \
|
||||
0x46 if context.protocol_version >= 318 else \
|
||||
0x44 if context.protocol_version >= 94 else \
|
||||
0x43 if context.protocol_version >= 70 else \
|
||||
return 0x4E if context.protocol_later_eq(721) else \
|
||||
0x4F if context.protocol_later_eq(550) else \
|
||||
0x4E if context.protocol_later_eq(471) else \
|
||||
0x4A if context.protocol_later_eq(461) else \
|
||||
0x4B if context.protocol_later_eq(451) else \
|
||||
0x4A if context.protocol_later_eq(389) else \
|
||||
0x49 if context.protocol_later_eq(352) else \
|
||||
0x48 if context.protocol_later_eq(345) else \
|
||||
0x47 if context.protocol_later_eq(336) else \
|
||||
0x46 if context.protocol_later_eq(318) else \
|
||||
0x44 if context.protocol_later_eq(94) else \
|
||||
0x43 if context.protocol_later_eq(70) else \
|
||||
0x03
|
||||
|
||||
packet_name = "time update"
|
||||
@@ -277,20 +277,20 @@ class TimeUpdatePacket(Packet):
|
||||
class UpdateHealthPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x49 if context.protocol_version >= 721 else \
|
||||
0x4A if context.protocol_version >= 707 else \
|
||||
0x49 if context.protocol_version >= 550 else \
|
||||
0x48 if context.protocol_version >= 471 else \
|
||||
0x44 if context.protocol_version >= 461 else \
|
||||
0x45 if context.protocol_version >= 451 else \
|
||||
0x44 if context.protocol_version >= 389 else \
|
||||
0x43 if context.protocol_version >= 352 else \
|
||||
0x42 if context.protocol_version >= 345 else \
|
||||
0x41 if context.protocol_version >= 336 else \
|
||||
0x40 if context.protocol_version >= 318 else \
|
||||
0x3E if context.protocol_version >= 86 else \
|
||||
0x3F if context.protocol_version >= 77 else \
|
||||
0x3E if context.protocol_version >= 67 else \
|
||||
return 0x49 if context.protocol_later_eq(721) else \
|
||||
0x4A if context.protocol_later_eq(707) else \
|
||||
0x49 if context.protocol_later_eq(550) else \
|
||||
0x48 if context.protocol_later_eq(471) else \
|
||||
0x44 if context.protocol_later_eq(461) else \
|
||||
0x45 if context.protocol_later_eq(451) else \
|
||||
0x44 if context.protocol_later_eq(389) else \
|
||||
0x43 if context.protocol_later_eq(352) else \
|
||||
0x42 if context.protocol_later_eq(345) else \
|
||||
0x41 if context.protocol_later_eq(336) else \
|
||||
0x40 if context.protocol_later_eq(318) else \
|
||||
0x3E if context.protocol_later_eq(86) else \
|
||||
0x3F if context.protocol_later_eq(77) else \
|
||||
0x3E if context.protocol_later_eq(67) else \
|
||||
0x06
|
||||
|
||||
packet_name = 'update health'
|
||||
@@ -304,31 +304,31 @@ class UpdateHealthPacket(Packet):
|
||||
class PluginMessagePacket(AbstractPluginMessagePacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x17 if context.protocol_version >= 741 else \
|
||||
0x18 if context.protocol_version >= 721 else \
|
||||
0x19 if context.protocol_version >= 550 else \
|
||||
0x18 if context.protocol_version >= 471 else \
|
||||
0x19 if context.protocol_version >= 345 else \
|
||||
0x18 if context.protocol_version >= 332 else \
|
||||
0x19 if context.protocol_version >= 318 else \
|
||||
0x18 if context.protocol_version >= 70 else \
|
||||
return 0x17 if context.protocol_later_eq(741) else \
|
||||
0x18 if context.protocol_later_eq(721) else \
|
||||
0x19 if context.protocol_later_eq(550) else \
|
||||
0x18 if context.protocol_later_eq(471) else \
|
||||
0x19 if context.protocol_later_eq(345) else \
|
||||
0x18 if context.protocol_later_eq(332) else \
|
||||
0x19 if context.protocol_later_eq(318) else \
|
||||
0x18 if context.protocol_later_eq(70) else \
|
||||
0x3F
|
||||
|
||||
|
||||
class PlayerListHeaderAndFooterPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x53 if context.protocol_version >= 721 else \
|
||||
0x54 if context.protocol_version >= 550 else \
|
||||
0x53 if context.protocol_version >= 471 else \
|
||||
0x5F if context.protocol_version >= 461 else \
|
||||
0x50 if context.protocol_version >= 451 else \
|
||||
0x4F if context.protocol_version >= 441 else \
|
||||
0x4E if context.protocol_version >= 393 else \
|
||||
0x4A if context.protocol_version >= 338 else \
|
||||
0x49 if context.protocol_version >= 335 else \
|
||||
0x47 if context.protocol_version >= 110 else \
|
||||
0x48 if context.protocol_version >= 107 else \
|
||||
return 0x53 if context.protocol_later_eq(721) else \
|
||||
0x54 if context.protocol_later_eq(550) else \
|
||||
0x53 if context.protocol_later_eq(471) else \
|
||||
0x5F if context.protocol_later_eq(461) else \
|
||||
0x50 if context.protocol_later_eq(451) else \
|
||||
0x4F if context.protocol_later_eq(441) else \
|
||||
0x4E if context.protocol_later_eq(393) else \
|
||||
0x4A if context.protocol_later_eq(338) else \
|
||||
0x49 if context.protocol_later_eq(335) else \
|
||||
0x47 if context.protocol_later_eq(110) else \
|
||||
0x48 if context.protocol_later_eq(107) else \
|
||||
0x47
|
||||
|
||||
packet_name = 'player list header and footer'
|
||||
@@ -340,14 +340,14 @@ class PlayerListHeaderAndFooterPacket(Packet):
|
||||
class EntityLookPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x29 if context.protocol_version >= 741 else \
|
||||
0x2A if context.protocol_version >= 721 else \
|
||||
0x2B if context.protocol_version >= 550 else \
|
||||
0x2A if context.protocol_version >= 389 else \
|
||||
0x29 if context.protocol_version >= 345 else \
|
||||
0x28 if context.protocol_version >= 318 else \
|
||||
0x27 if context.protocol_version >= 94 else \
|
||||
0x28 if context.protocol_version >= 70 else \
|
||||
return 0x29 if context.protocol_later_eq(741) else \
|
||||
0x2A if context.protocol_later_eq(721) else \
|
||||
0x2B if context.protocol_later_eq(550) else \
|
||||
0x2A if context.protocol_later_eq(389) else \
|
||||
0x29 if context.protocol_later_eq(345) else \
|
||||
0x28 if context.protocol_later_eq(318) else \
|
||||
0x27 if context.protocol_later_eq(94) else \
|
||||
0x28 if context.protocol_later_eq(70) else \
|
||||
0x16
|
||||
|
||||
packet_name = 'entity look'
|
||||
|
||||
@@ -9,12 +9,12 @@ from minecraft.networking.types import (
|
||||
class BlockChangePacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x0B if context.protocol_version >= 721 else \
|
||||
0x0C if context.protocol_version >= 550 else \
|
||||
0x0B if context.protocol_version >= 332 else \
|
||||
0x0C if context.protocol_version >= 318 else \
|
||||
0x0B if context.protocol_version >= 67 else \
|
||||
0x24 if context.protocol_version >= 62 else \
|
||||
return 0x0B if context.protocol_later_eq(721) else \
|
||||
0x0C if context.protocol_later_eq(550) else \
|
||||
0x0B if context.protocol_later_eq(332) else \
|
||||
0x0C if context.protocol_later_eq(318) else \
|
||||
0x0B if context.protocol_later_eq(67) else \
|
||||
0x24 if context.protocol_later_eq(62) else \
|
||||
0x23
|
||||
|
||||
packet_name = 'block change'
|
||||
@@ -23,7 +23,7 @@ class BlockChangePacket(Packet):
|
||||
{'block_state_id': VarInt}]
|
||||
block_state_id = 0
|
||||
|
||||
# For protocols < 347: an accessor for (block_state_id >> 4).
|
||||
# For protocols before 347: an accessor for (block_state_id >> 4).
|
||||
@property
|
||||
def blockId(self):
|
||||
return self.block_state_id >> 4
|
||||
@@ -32,7 +32,7 @@ class BlockChangePacket(Packet):
|
||||
def blockId(self, block_id):
|
||||
self.block_state_id = (self.block_state_id & 0xF) | (block_id << 4)
|
||||
|
||||
# For protocols < 347: an accessor for (block_state_id & 0xF).
|
||||
# For protocols before 347: an accessor for (block_state_id & 0xF).
|
||||
@property
|
||||
def blockMeta(self):
|
||||
return self.block_state_id & 0xF
|
||||
@@ -48,13 +48,13 @@ class BlockChangePacket(Packet):
|
||||
class MultiBlockChangePacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x3B if context.protocol_version >= 741 else \
|
||||
0x0F if context.protocol_version >= 721 else \
|
||||
0x10 if context.protocol_version >= 550 else \
|
||||
0x0F if context.protocol_version >= 343 else \
|
||||
0x10 if context.protocol_version >= 332 else \
|
||||
0x11 if context.protocol_version >= 318 else \
|
||||
0x10 if context.protocol_version >= 67 else \
|
||||
return 0x3B if context.protocol_later_eq(741) else \
|
||||
0x0F if context.protocol_later_eq(721) else \
|
||||
0x10 if context.protocol_later_eq(550) else \
|
||||
0x0F if context.protocol_later_eq(343) else \
|
||||
0x10 if context.protocol_later_eq(332) else \
|
||||
0x11 if context.protocol_later_eq(318) else \
|
||||
0x10 if context.protocol_later_eq(67) else \
|
||||
0x22
|
||||
|
||||
packet_name = 'multi block change'
|
||||
@@ -87,7 +87,7 @@ class MultiBlockChangePacket(Packet):
|
||||
# Access the 'x', 'y', 'z' fields as a Vector of ints.
|
||||
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
|
||||
|
||||
# For protocols < 347: an accessor for (block_state_id >> 4).
|
||||
# For protocols before 347: an accessor for (block_state_id >> 4).
|
||||
@property
|
||||
def blockId(self):
|
||||
return self.block_state_id >> 4
|
||||
@@ -96,7 +96,7 @@ class MultiBlockChangePacket(Packet):
|
||||
def blockId(self, block_id):
|
||||
self.block_state_id = self.block_state_id & 0xF | block_id << 4
|
||||
|
||||
# For protocols < 347: an accessor for (block_state_id & 0xF).
|
||||
# For protocols before 347: an accessor for (block_state_id & 0xF).
|
||||
@property
|
||||
def blockMeta(self):
|
||||
return self.block_state_id & 0xF
|
||||
@@ -111,7 +111,7 @@ class MultiBlockChangePacket(Packet):
|
||||
@classmethod
|
||||
def read_with_context(cls, file_object, context):
|
||||
record = cls()
|
||||
if context.protocol_version >= 741:
|
||||
if context.protocol_later_eq(741):
|
||||
value = VarLong.read(file_object)
|
||||
record.block_state_id = value >> 12
|
||||
record.x = (value >> 8) & 0xF
|
||||
@@ -127,7 +127,7 @@ class MultiBlockChangePacket(Packet):
|
||||
|
||||
@classmethod
|
||||
def send_with_context(self, record, socket, context):
|
||||
if context.protocol_version >= 741:
|
||||
if context.protocol_later_eq(741):
|
||||
value = record.block_state_id << 12 | \
|
||||
(record.x & 0xF) << 8 | \
|
||||
(record.z & 0xF) << 4 | \
|
||||
@@ -141,9 +141,9 @@ class MultiBlockChangePacket(Packet):
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'chunk_section_pos': MultiBlockChangePacket.ChunkSectionPos},
|
||||
{'invert_trust_edges': Boolean}
|
||||
if context.protocol_version >= 748 else {}, # Provisional field name.
|
||||
if context.protocol_later_eq(748) else {}, # Provisional field name.
|
||||
{'records': PrefixedArray(VarInt, MultiBlockChangePacket.Record)},
|
||||
] if context.protocol_version >= 741 else [
|
||||
] if context.protocol_later_eq(741) else [
|
||||
{'chunk_x': Integer},
|
||||
{'chunk_z': Integer},
|
||||
{'records': PrefixedArray(VarInt, MultiBlockChangePacket.Record)},
|
||||
|
||||
@@ -8,19 +8,19 @@ from minecraft.networking.types import (
|
||||
class CombatEventPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x31 if context.protocol_version >= 741 else \
|
||||
0x32 if context.protocol_version >= 721 else \
|
||||
0x33 if context.protocol_version >= 550 else \
|
||||
0x32 if context.protocol_version >= 471 else \
|
||||
0x30 if context.protocol_version >= 451 else \
|
||||
0x2F if context.protocol_version >= 389 else \
|
||||
0x2E if context.protocol_version >= 345 else \
|
||||
0x2D if context.protocol_version >= 336 else \
|
||||
0x2C if context.protocol_version >= 332 else \
|
||||
0x2D if context.protocol_version >= 318 else \
|
||||
0x2C if context.protocol_version >= 86 else \
|
||||
0x2D if context.protocol_version >= 80 else \
|
||||
0x2C if context.protocol_version >= 67 else \
|
||||
return 0x31 if context.protocol_later_eq(741) else \
|
||||
0x32 if context.protocol_later_eq(721) else \
|
||||
0x33 if context.protocol_later_eq(550) else \
|
||||
0x32 if context.protocol_later_eq(471) else \
|
||||
0x30 if context.protocol_later_eq(451) else \
|
||||
0x2F if context.protocol_later_eq(389) else \
|
||||
0x2E if context.protocol_later_eq(345) else \
|
||||
0x2D if context.protocol_later_eq(336) else \
|
||||
0x2C if context.protocol_later_eq(332) else \
|
||||
0x2D if context.protocol_later_eq(318) else \
|
||||
0x2C if context.protocol_later_eq(86) else \
|
||||
0x2D if context.protocol_later_eq(80) else \
|
||||
0x2C if context.protocol_later_eq(67) else \
|
||||
0x42
|
||||
|
||||
packet_name = 'combat event'
|
||||
|
||||
@@ -7,16 +7,16 @@ from minecraft.networking.packets import Packet
|
||||
class ExplosionPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x1B if context.protocol_version >= 741 else \
|
||||
0x1C if context.protocol_version >= 721 else \
|
||||
0x1D if context.protocol_version >= 550 else \
|
||||
0x1C if context.protocol_version >= 471 else \
|
||||
0x1E if context.protocol_version >= 389 else \
|
||||
0x1D if context.protocol_version >= 345 else \
|
||||
0x1C if context.protocol_version >= 332 else \
|
||||
0x1D if context.protocol_version >= 318 else \
|
||||
0x1C if context.protocol_version >= 80 else \
|
||||
0x1B if context.protocol_version >= 67 else \
|
||||
return 0x1B if context.protocol_later_eq(741) else \
|
||||
0x1C if context.protocol_later_eq(721) else \
|
||||
0x1D if context.protocol_later_eq(550) else \
|
||||
0x1C if context.protocol_later_eq(471) else \
|
||||
0x1E if context.protocol_later_eq(389) else \
|
||||
0x1D if context.protocol_later_eq(345) else \
|
||||
0x1C if context.protocol_later_eq(332) else \
|
||||
0x1D if context.protocol_later_eq(318) else \
|
||||
0x1C if context.protocol_later_eq(80) else \
|
||||
0x1B if context.protocol_later_eq(67) else \
|
||||
0x27
|
||||
|
||||
packet_name = 'explosion'
|
||||
|
||||
@@ -8,12 +8,12 @@ from minecraft.networking.packets import Packet
|
||||
class FacePlayerPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x33 if context.protocol_version >= 741 else \
|
||||
0x34 if context.protocol_version >= 721 else \
|
||||
0x35 if context.protocol_version >= 550 else \
|
||||
0x34 if context.protocol_version >= 471 else \
|
||||
0x32 if context.protocol_version >= 451 else \
|
||||
0x31 if context.protocol_version >= 389 else \
|
||||
return 0x33 if context.protocol_later_eq(741) else \
|
||||
0x34 if context.protocol_later_eq(721) else \
|
||||
0x35 if context.protocol_later_eq(550) else \
|
||||
0x34 if context.protocol_later_eq(471) else \
|
||||
0x32 if context.protocol_later_eq(451) else \
|
||||
0x31 if context.protocol_later_eq(389) else \
|
||||
0x30
|
||||
|
||||
packet_name = 'face player'
|
||||
@@ -21,14 +21,14 @@ class FacePlayerPacket(Packet):
|
||||
@property
|
||||
def fields(self):
|
||||
return ('origin', 'x', 'y', 'z', 'entity_id', 'entity_origin') \
|
||||
if self.context.protocol_version >= 353 else \
|
||||
if self.context.protocol_later_eq(353) else \
|
||||
('entity_id', 'x', 'y', 'z')
|
||||
|
||||
# Access the 'x', 'y', 'z' fields as a Vector tuple.
|
||||
target = multi_attribute_alias(Vector, 'x', 'y', 'z')
|
||||
|
||||
def read(self, file_object):
|
||||
if self.context.protocol_version >= 353:
|
||||
if self.context.protocol_later_eq(353):
|
||||
self.origin = VarInt.read(file_object)
|
||||
self.x = Double.read(file_object)
|
||||
self.y = Double.read(file_object)
|
||||
@@ -51,7 +51,7 @@ class FacePlayerPacket(Packet):
|
||||
self.z = Double.read(file_object)
|
||||
|
||||
def write_fields(self, packet_buffer):
|
||||
if self.context.protocol_version >= 353:
|
||||
if self.context.protocol_later_eq(353):
|
||||
VarInt.send(self.origin, packet_buffer)
|
||||
Double.send(self.x, packet_buffer)
|
||||
Double.send(self.y, packet_buffer)
|
||||
|
||||
@@ -48,9 +48,9 @@ class AbstractDimensionPacket(Packet):
|
||||
'''
|
||||
def field_string(self, field):
|
||||
# pylint: disable=no-member
|
||||
if self.context.protocol_version >= 748 and field == 'dimension':
|
||||
if self.context.protocol_later_eq(748) and field == 'dimension':
|
||||
return nbt_to_snbt(self.dimension)
|
||||
elif self.context.protocol_version < 718 and field == 'dimension':
|
||||
elif self.context.protocol_earlier(718) and field == 'dimension':
|
||||
return Dimension.name_from_value(self.dimension)
|
||||
return super(AbstractDimensionPacket, self).field_string(field)
|
||||
|
||||
@@ -58,43 +58,43 @@ class AbstractDimensionPacket(Packet):
|
||||
class JoinGamePacket(AbstractDimensionPacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x24 if context.protocol_version >= 741 else \
|
||||
0x25 if context.protocol_version >= 721 else \
|
||||
0x26 if context.protocol_version >= 550 else \
|
||||
0x25 if context.protocol_version >= 389 else \
|
||||
0x24 if context.protocol_version >= 345 else \
|
||||
0x23 if context.protocol_version >= 332 else \
|
||||
0x24 if context.protocol_version >= 318 else \
|
||||
0x23 if context.protocol_version >= 107 else \
|
||||
return 0x24 if context.protocol_later_eq(741) else \
|
||||
0x25 if context.protocol_later_eq(721) else \
|
||||
0x26 if context.protocol_later_eq(550) else \
|
||||
0x25 if context.protocol_later_eq(389) else \
|
||||
0x24 if context.protocol_later_eq(345) else \
|
||||
0x23 if context.protocol_later_eq(332) else \
|
||||
0x24 if context.protocol_later_eq(318) else \
|
||||
0x23 if context.protocol_later_eq(107) else \
|
||||
0x01
|
||||
|
||||
packet_name = "join game"
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'entity_id': Integer},
|
||||
{'is_hardcore': Boolean} if context.protocol_version >= 738 else {},
|
||||
{'is_hardcore': Boolean} if context.protocol_later_eq(738) else {},
|
||||
{'game_mode': UnsignedByte},
|
||||
{'previous_game_mode': UnsignedByte}
|
||||
if context.protocol_version >= 730 else {},
|
||||
if context.protocol_later_eq(730) else {},
|
||||
{'world_names': PrefixedArray(VarInt, String)}
|
||||
if context.protocol_version >= 722 else {},
|
||||
if context.protocol_later_eq(722) else {},
|
||||
{'dimension_codec': NBT}
|
||||
if context.protocol_version >= 718 else {},
|
||||
if context.protocol_later_eq(718) else {},
|
||||
{'dimension':
|
||||
NBT if context.protocol_version >= 748 else
|
||||
String if context.protocol_version >= 718 else
|
||||
Integer if context.protocol_version >= 108 else
|
||||
NBT if context.protocol_later_eq(748) else
|
||||
String if context.protocol_later_eq(718) else
|
||||
Integer if context.protocol_later_eq(108) else
|
||||
Byte},
|
||||
{'world_name': String} if context.protocol_version >= 722 else {},
|
||||
{'hashed_seed': Long} if context.protocol_version >= 552 else {},
|
||||
{'difficulty': UnsignedByte} if context.protocol_version < 464 else {},
|
||||
{'world_name': String} if context.protocol_later_eq(722) else {},
|
||||
{'hashed_seed': Long} if context.protocol_later_eq(552) else {},
|
||||
{'difficulty': UnsignedByte} if context.protocol_earlier(464) else {},
|
||||
{'max_players':
|
||||
VarInt if context.protocol_version >= 749 else UnsignedByte},
|
||||
{'level_type': String} if context.protocol_version < 716 else {},
|
||||
{'render_distance': VarInt} if context.protocol_version >= 468 else {},
|
||||
VarInt if context.protocol_later_eq(749) else UnsignedByte},
|
||||
{'level_type': String} if context.protocol_earlier(716) else {},
|
||||
{'render_distance': VarInt} if context.protocol_later_eq(468) else {},
|
||||
{'reduced_debug_info': Boolean},
|
||||
{'respawn_screen': Boolean} if context.protocol_version >= 571 else {},
|
||||
{'is_debug': Boolean} if context.protocol_version >= 716 else {},
|
||||
{'is_flat': Boolean} if context.protocol_version >= 716 else {},
|
||||
{'respawn_screen': Boolean} if context.protocol_later_eq(571) else {},
|
||||
{'is_debug': Boolean} if context.protocol_later_eq(716) else {},
|
||||
{'is_flat': Boolean} if context.protocol_later_eq(716) else {},
|
||||
])
|
||||
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
@@ -105,7 +105,7 @@ class JoinGamePacket(AbstractDimensionPacket):
|
||||
# Can be set or deleted when 'context' is undefined.
|
||||
@property
|
||||
def game_mode(self):
|
||||
if self.context.protocol_version >= 738:
|
||||
if self.context.protocol_later_eq(738):
|
||||
return self._game_mode_738
|
||||
else:
|
||||
return self._game_mode_0
|
||||
@@ -124,7 +124,7 @@ class JoinGamePacket(AbstractDimensionPacket):
|
||||
# Can be set or deleted when 'context' is undefined.
|
||||
@property
|
||||
def is_hardcore(self):
|
||||
if self.context.protocol_version >= 738:
|
||||
if self.context.protocol_later_eq(738):
|
||||
return self._is_hardcore
|
||||
else:
|
||||
return bool(self._game_mode_0 & GameMode.HARDCORE)
|
||||
@@ -148,7 +148,7 @@ class JoinGamePacket(AbstractDimensionPacket):
|
||||
# version-independently. Can be set or deleted when 'context' is undefined.
|
||||
@property
|
||||
def pure_game_mode(self):
|
||||
if self.context.protocol_version >= 738:
|
||||
if self.context.protocol_later_eq(738):
|
||||
return self._game_mode_738
|
||||
else:
|
||||
return self._game_mode_0 & ~GameMode.HARDCORE
|
||||
@@ -170,37 +170,37 @@ class JoinGamePacket(AbstractDimensionPacket):
|
||||
class RespawnPacket(AbstractDimensionPacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x39 if context.protocol_version >= 741 else \
|
||||
0x3A if context.protocol_version >= 721 else \
|
||||
0x3B if context.protocol_version >= 550 else \
|
||||
0x3A if context.protocol_version >= 471 else \
|
||||
0x38 if context.protocol_version >= 461 else \
|
||||
0x39 if context.protocol_version >= 451 else \
|
||||
0x38 if context.protocol_version >= 389 else \
|
||||
0x37 if context.protocol_version >= 352 else \
|
||||
0x36 if context.protocol_version >= 345 else \
|
||||
0x35 if context.protocol_version >= 336 else \
|
||||
0x34 if context.protocol_version >= 332 else \
|
||||
0x35 if context.protocol_version >= 318 else \
|
||||
0x33 if context.protocol_version >= 70 else \
|
||||
return 0x39 if context.protocol_later_eq(741) else \
|
||||
0x3A if context.protocol_later_eq(721) else \
|
||||
0x3B if context.protocol_later_eq(550) else \
|
||||
0x3A if context.protocol_later_eq(471) else \
|
||||
0x38 if context.protocol_later_eq(461) else \
|
||||
0x39 if context.protocol_later_eq(451) else \
|
||||
0x38 if context.protocol_later_eq(389) else \
|
||||
0x37 if context.protocol_later_eq(352) else \
|
||||
0x36 if context.protocol_later_eq(345) else \
|
||||
0x35 if context.protocol_later_eq(336) else \
|
||||
0x34 if context.protocol_later_eq(332) else \
|
||||
0x35 if context.protocol_later_eq(318) else \
|
||||
0x33 if context.protocol_later_eq(70) else \
|
||||
0x07
|
||||
|
||||
packet_name = 'respawn'
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'dimension':
|
||||
NBT if context.protocol_version >= 748 else
|
||||
String if context.protocol_version >= 718 else
|
||||
NBT if context.protocol_later_eq(748) else
|
||||
String if context.protocol_later_eq(718) else
|
||||
Integer},
|
||||
{'world_name': String} if context.protocol_version >= 719 else {},
|
||||
{'difficulty': UnsignedByte} if context.protocol_version < 464 else {},
|
||||
{'hashed_seed': Long} if context.protocol_version >= 552 else {},
|
||||
{'world_name': String} if context.protocol_later_eq(719) else {},
|
||||
{'difficulty': UnsignedByte} if context.protocol_earlier(464) else {},
|
||||
{'hashed_seed': Long} if context.protocol_later_eq(552) else {},
|
||||
{'game_mode': UnsignedByte},
|
||||
{'previous_game_mode': UnsignedByte}
|
||||
if context.protocol_version >= 730 else {},
|
||||
{'level_type': String} if context.protocol_version < 716 else {},
|
||||
{'is_debug': Boolean} if context.protocol_version >= 716 else {},
|
||||
{'is_flat': Boolean} if context.protocol_version >= 716 else {},
|
||||
{'copy_metadata': Boolean} if context.protocol_version >= 714 else {},
|
||||
if context.protocol_later_eq(730) else {},
|
||||
{'level_type': String} if context.protocol_earlier(716) else {},
|
||||
{'is_debug': Boolean} if context.protocol_later_eq(716) else {},
|
||||
{'is_flat': Boolean} if context.protocol_later_eq(716) else {},
|
||||
{'copy_metadata': Boolean} if context.protocol_later_eq(714) else {},
|
||||
])
|
||||
|
||||
# These aliases declare the Enum type corresponding to each field:
|
||||
|
||||
@@ -8,14 +8,14 @@ from minecraft.networking.types import (
|
||||
class MapPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x25 if context.protocol_version >= 741 else \
|
||||
0x26 if context.protocol_version >= 721 else \
|
||||
0x27 if context.protocol_version >= 550 else \
|
||||
0x26 if context.protocol_version >= 389 else \
|
||||
0x25 if context.protocol_version >= 345 else \
|
||||
0x24 if context.protocol_version >= 334 else \
|
||||
0x25 if context.protocol_version >= 318 else \
|
||||
0x24 if context.protocol_version >= 107 else \
|
||||
return 0x25 if context.protocol_later_eq(741) else \
|
||||
0x26 if context.protocol_later_eq(721) else \
|
||||
0x27 if context.protocol_later_eq(550) else \
|
||||
0x26 if context.protocol_later_eq(389) else \
|
||||
0x25 if context.protocol_later_eq(345) else \
|
||||
0x24 if context.protocol_later_eq(334) else \
|
||||
0x25 if context.protocol_later_eq(318) else \
|
||||
0x24 if context.protocol_later_eq(107) else \
|
||||
0x34
|
||||
|
||||
packet_name = 'map'
|
||||
@@ -23,9 +23,9 @@ class MapPacket(Packet):
|
||||
@property
|
||||
def fields(self):
|
||||
fields = 'id', 'scale', 'icons', 'width', 'height', 'pixels'
|
||||
if self.context.protocol_version >= 107:
|
||||
if self.context.protocol_later_eq(107):
|
||||
fields += 'is_tracking_position',
|
||||
if self.context.protocol_version >= 452:
|
||||
if self.context.protocol_later_eq(452):
|
||||
fields += 'is_locked',
|
||||
return fields
|
||||
|
||||
@@ -71,12 +71,12 @@ class MapPacket(Packet):
|
||||
self.map_id = VarInt.read(file_object)
|
||||
self.scale = Byte.read(file_object)
|
||||
|
||||
if self.context.protocol_version >= 107:
|
||||
if self.context.protocol_later_eq(107):
|
||||
self.is_tracking_position = Boolean.read(file_object)
|
||||
else:
|
||||
self.is_tracking_position = True
|
||||
|
||||
if self.context.protocol_version >= 452:
|
||||
if self.context.protocol_later_eq(452):
|
||||
self.is_locked = Boolean.read(file_object)
|
||||
else:
|
||||
self.is_locked = False
|
||||
@@ -84,15 +84,15 @@ class MapPacket(Packet):
|
||||
icon_count = VarInt.read(file_object)
|
||||
self.icons = []
|
||||
for i in range(icon_count):
|
||||
if self.context.protocol_version >= 373:
|
||||
if self.context.protocol_later_eq(373):
|
||||
type = VarInt.read(file_object)
|
||||
else:
|
||||
type, direction = divmod(UnsignedByte.read(file_object), 16)
|
||||
x = Byte.read(file_object)
|
||||
z = Byte.read(file_object)
|
||||
if self.context.protocol_version >= 373:
|
||||
if self.context.protocol_later_eq(373):
|
||||
direction = UnsignedByte.read(file_object)
|
||||
if self.context.protocol_version >= 364:
|
||||
if self.context.protocol_later_eq(364):
|
||||
has_name = Boolean.read(file_object)
|
||||
display_name = String.read(file_object) if has_name else None
|
||||
else:
|
||||
@@ -134,12 +134,12 @@ class MapPacket(Packet):
|
||||
def write_fields(self, packet_buffer):
|
||||
VarInt.send(self.map_id, packet_buffer)
|
||||
Byte.send(self.scale, packet_buffer)
|
||||
if self.context.protocol_version >= 107:
|
||||
if self.context.protocol_later_eq(107):
|
||||
Boolean.send(self.is_tracking_position, packet_buffer)
|
||||
|
||||
VarInt.send(len(self.icons), packet_buffer)
|
||||
for icon in self.icons:
|
||||
if self.context.protocol_version >= 373:
|
||||
if self.context.protocol_later_eq(373):
|
||||
VarInt.send(icon.type, packet_buffer)
|
||||
else:
|
||||
type_and_direction = (icon.type << 4) & 0xF0
|
||||
@@ -147,9 +147,9 @@ class MapPacket(Packet):
|
||||
UnsignedByte.send(type_and_direction, packet_buffer)
|
||||
Byte.send(icon.location[0], packet_buffer)
|
||||
Byte.send(icon.location[1], packet_buffer)
|
||||
if self.context.protocol_version >= 373:
|
||||
if self.context.protocol_later_eq(373):
|
||||
UnsignedByte.send(icon.direction, packet_buffer)
|
||||
if self.context.protocol_version >= 364:
|
||||
if self.context.protocol_later_eq(364):
|
||||
Boolean.send(icon.display_name is not None, packet_buffer)
|
||||
if icon.display_name is not None:
|
||||
String.send(icon.display_name, packet_buffer)
|
||||
|
||||
@@ -9,17 +9,17 @@ from minecraft.networking.types import (
|
||||
class PlayerListItemPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x32 if context.protocol_version >= 741 else \
|
||||
0x33 if context.protocol_version >= 721 else \
|
||||
0x34 if context.protocol_version >= 550 else \
|
||||
0x33 if context.protocol_version >= 471 else \
|
||||
0x31 if context.protocol_version >= 451 else \
|
||||
0x30 if context.protocol_version >= 389 else \
|
||||
0x2F if context.protocol_version >= 345 else \
|
||||
0x2E if context.protocol_version >= 336 else \
|
||||
0x2D if context.protocol_version >= 332 else \
|
||||
0x2E if context.protocol_version >= 318 else \
|
||||
0x2D if context.protocol_version >= 107 else \
|
||||
return 0x32 if context.protocol_later_eq(741) else \
|
||||
0x33 if context.protocol_later_eq(721) else \
|
||||
0x34 if context.protocol_later_eq(550) else \
|
||||
0x33 if context.protocol_later_eq(471) else \
|
||||
0x31 if context.protocol_later_eq(451) else \
|
||||
0x30 if context.protocol_later_eq(389) else \
|
||||
0x2F if context.protocol_later_eq(345) else \
|
||||
0x2E if context.protocol_later_eq(336) else \
|
||||
0x2D if context.protocol_later_eq(332) else \
|
||||
0x2E if context.protocol_later_eq(318) else \
|
||||
0x2D if context.protocol_later_eq(107) else \
|
||||
0x38
|
||||
|
||||
packet_name = "player list item"
|
||||
|
||||
@@ -9,18 +9,18 @@ from minecraft.networking.types import (
|
||||
class PlayerPositionAndLookPacket(Packet, BitFieldEnum):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x34 if context.protocol_version >= 741 else \
|
||||
0x35 if context.protocol_version >= 721 else \
|
||||
0x36 if context.protocol_version >= 550 else \
|
||||
0x35 if context.protocol_version >= 471 else \
|
||||
0x33 if context.protocol_version >= 451 else \
|
||||
0x32 if context.protocol_version >= 389 else \
|
||||
0x31 if context.protocol_version >= 352 else \
|
||||
0x30 if context.protocol_version >= 345 else \
|
||||
0x2F if context.protocol_version >= 336 else \
|
||||
0x2E if context.protocol_version >= 332 else \
|
||||
0x2F if context.protocol_version >= 318 else \
|
||||
0x2E if context.protocol_version >= 70 else \
|
||||
return 0x34 if context.protocol_later_eq(741) else \
|
||||
0x35 if context.protocol_later_eq(721) else \
|
||||
0x36 if context.protocol_later_eq(550) else \
|
||||
0x35 if context.protocol_later_eq(471) else \
|
||||
0x33 if context.protocol_later_eq(451) else \
|
||||
0x32 if context.protocol_later_eq(389) else \
|
||||
0x31 if context.protocol_later_eq(352) else \
|
||||
0x30 if context.protocol_later_eq(345) else \
|
||||
0x2F if context.protocol_later_eq(336) else \
|
||||
0x2E if context.protocol_later_eq(332) else \
|
||||
0x2F if context.protocol_later_eq(318) else \
|
||||
0x2E if context.protocol_later_eq(70) else \
|
||||
0x08
|
||||
|
||||
packet_name = "player position and look"
|
||||
@@ -31,7 +31,7 @@ class PlayerPositionAndLookPacket(Packet, BitFieldEnum):
|
||||
{'yaw': Float},
|
||||
{'pitch': Float},
|
||||
{'flags': Byte},
|
||||
{'teleport_id': VarInt} if context.protocol_version >= 107 else {},
|
||||
{'teleport_id': VarInt} if context.protocol_later_eq(107) else {},
|
||||
])
|
||||
|
||||
# Access the 'x', 'y', 'z' fields as a Vector tuple.
|
||||
|
||||
@@ -9,18 +9,18 @@ __all__ = 'SoundEffectPacket',
|
||||
class SoundEffectPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x51 if context.protocol_version >= 721 else \
|
||||
0x52 if context.protocol_version >= 550 else \
|
||||
0x51 if context.protocol_version >= 471 else \
|
||||
0x4D if context.protocol_version >= 461 else \
|
||||
0x4E if context.protocol_version >= 451 else \
|
||||
0x4D if context.protocol_version >= 389 else \
|
||||
0x4C if context.protocol_version >= 352 else \
|
||||
0x4B if context.protocol_version >= 345 else \
|
||||
0x4A if context.protocol_version >= 343 else \
|
||||
0x49 if context.protocol_version >= 336 else \
|
||||
0x48 if context.protocol_version >= 318 else \
|
||||
0x46 if context.protocol_version >= 110 else \
|
||||
return 0x51 if context.protocol_later_eq(721) else \
|
||||
0x52 if context.protocol_later_eq(550) else \
|
||||
0x51 if context.protocol_later_eq(471) else \
|
||||
0x4D if context.protocol_later_eq(461) else \
|
||||
0x4E if context.protocol_later_eq(451) else \
|
||||
0x4D if context.protocol_later_eq(389) else \
|
||||
0x4C if context.protocol_later_eq(352) else \
|
||||
0x4B if context.protocol_later_eq(345) else \
|
||||
0x4A if context.protocol_later_eq(343) else \
|
||||
0x49 if context.protocol_later_eq(336) else \
|
||||
0x48 if context.protocol_later_eq(318) else \
|
||||
0x46 if context.protocol_later_eq(110) else \
|
||||
0x47
|
||||
|
||||
packet_name = 'sound effect'
|
||||
@@ -29,13 +29,16 @@ class SoundEffectPacket(Packet):
|
||||
def get_definition(context):
|
||||
return [
|
||||
({'sound_category': VarInt}
|
||||
if 326 > context.protocol_version >= 321 else {}),
|
||||
if context.protocol_later_eq(321)
|
||||
and context.protocol_earlier(326) else {}),
|
||||
{'sound_id': VarInt},
|
||||
({'sound_category': VarInt}
|
||||
if 95 <= context.protocol_version < 321
|
||||
or context.protocol_version >= 326 else {}),
|
||||
if context.protocol_later_eq(95)
|
||||
and context.protocol_earlier(321)
|
||||
or context.protocol_later_eq(326) else {}),
|
||||
({'parroted_entity_type': String}
|
||||
if 326 > context.protocol_version >= 321 else {}),
|
||||
if context.protocol_later_eq(321)
|
||||
and context.protocol_earlier(326) else {}),
|
||||
{'effect_position': SoundEffectPacket.EffectPosition},
|
||||
{'volume': Float},
|
||||
{'pitch': SoundEffectPacket.Pitch},
|
||||
@@ -66,19 +69,19 @@ class SoundEffectPacket(Packet):
|
||||
class Pitch(Type):
|
||||
@staticmethod
|
||||
def read_with_context(file_object, context):
|
||||
if context.protocol_version >= 201:
|
||||
if context.protocol_later_eq(201):
|
||||
value = Float.read(file_object)
|
||||
else:
|
||||
value = Byte.read(file_object)
|
||||
if context.protocol_version < 204:
|
||||
if context.protocol_earlier(204):
|
||||
value /= 63.5
|
||||
return value
|
||||
|
||||
@staticmethod
|
||||
def send_with_context(value, socket, context):
|
||||
if context.protocol_version < 204:
|
||||
if context.protocol_earlier(204):
|
||||
value *= 63.5
|
||||
if context.protocol_version >= 201:
|
||||
if context.protocol_later_eq(201):
|
||||
Float.send(value, socket)
|
||||
else:
|
||||
Byte.send(int(value), socket)
|
||||
@@ -10,7 +10,7 @@ from minecraft.networking.types import (
|
||||
class SpawnObjectPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x00 if context.protocol_version >= 67 else \
|
||||
return 0x00 if context.protocol_later_eq(67) else \
|
||||
0x0E
|
||||
|
||||
packet_name = 'spawn object'
|
||||
@@ -43,43 +43,44 @@ class SpawnObjectPacket(Packet):
|
||||
if field != 'type_id' or context is None:
|
||||
return
|
||||
|
||||
pv = context.protocol_version
|
||||
name = 'EntityType_%d' % pv
|
||||
name = 'EntityType_%d' % context.protocol_version
|
||||
if hasattr(cls, name):
|
||||
return getattr(cls, name)
|
||||
|
||||
era = 0 if context.protocol_earlier(458) else 1
|
||||
|
||||
class EntityType(Enum):
|
||||
# XXX This has not been updated for >= v1.15
|
||||
ACTIVATED_TNT = 50 if pv < 458 else 55 # PrimedTnt
|
||||
AREA_EFFECT_CLOUD = 3 if pv < 458 else 0
|
||||
ARMORSTAND = 78 if pv < 458 else 1
|
||||
ARROW = 60 if pv < 458 else 2
|
||||
BOAT = 1 if pv < 458 else 5
|
||||
DRAGON_FIREBALL = 93 if pv < 458 else 13
|
||||
EGG = 62 if pv < 458 else 74 # ThrownEgg
|
||||
ENDERCRYSTAL = 51 if pv < 458 else 16
|
||||
ENDERPEARL = 65 if pv < 458 else 75 # ThrownEnderpearl
|
||||
EVOCATION_FANGS = 79 if pv < 458 else 20
|
||||
EXP_BOTTLE = 75 if pv < 458 else 76 # ThrownExpBottle
|
||||
EYE_OF_ENDER = 72 if pv < 458 else 23 # EyeOfEnderSignal
|
||||
FALLING_OBJECT = 70 if pv < 458 else 24 # FallingSand
|
||||
FIREBALL = 63 if pv < 458 else 34 # Fireball (ghast)
|
||||
FIRECHARGE = 64 if pv < 458 else 65 # SmallFireball (blaze)
|
||||
FIREWORK_ROCKET = 76 if pv < 458 else 25 # FireworksRocketEntity
|
||||
FISHING_HOOK = 90 if pv < 458 else 93 # Fishing bobber
|
||||
ITEM_FRAMES = 71 if pv < 458 else 33 # ItemFrame
|
||||
ITEM_STACK = 2 if pv < 458 else 32 # Item
|
||||
LEASH_KNOT = 77 if pv < 458 else 35
|
||||
LLAMA_SPIT = 68 if pv < 458 else 37
|
||||
MINECART = 10 if pv < 458 else 39 # MinecartRideable
|
||||
POTION = 73 if pv < 458 else 77 # ThrownPotion
|
||||
SHULKER_BULLET = 67 if pv < 458 else 60
|
||||
SNOWBALL = 61 if pv < 458 else 67
|
||||
SPECTRAL_ARROW = 91 if pv < 458 else 68
|
||||
WITHER_SKULL = 66 if pv < 458 else 85
|
||||
if pv >= 393:
|
||||
ACTIVATED_TNT = (50, 55)[era] # PrimedTnt
|
||||
AREA_EFFECT_CLOUD = ( 3, 0)[era]
|
||||
ARMORSTAND = (78, 1)[era]
|
||||
ARROW = (60, 2)[era]
|
||||
BOAT = ( 1, 5)[era]
|
||||
DRAGON_FIREBALL = (93, 13)[era]
|
||||
EGG = (62, 74)[era] # ThrownEgg
|
||||
ENDERCRYSTAL = (51, 16)[era]
|
||||
ENDERPEARL = (65, 75)[era] # ThrownEnderpearl
|
||||
EVOCATION_FANGS = (79, 20)[era]
|
||||
EXP_BOTTLE = (75, 76)[era] # ThrownExpBottle
|
||||
EYE_OF_ENDER = (72, 23)[era] # EyeOfEnderSignal
|
||||
FALLING_OBJECT = (70, 24)[era] # FallingSand
|
||||
FIREBALL = (63, 34)[era] # Fireball (ghast)
|
||||
FIRECHARGE = (64, 65)[era] # SmallFireball (blaze)
|
||||
FIREWORK_ROCKET = (76, 25)[era] # FireworksRocketEntity
|
||||
FISHING_HOOK = (90, 93)[era] # Fishing bobber
|
||||
ITEM_FRAMES = (71, 33)[era] # ItemFrame
|
||||
ITEM_STACK = ( 2, 32)[era] # Item
|
||||
LEASH_KNOT = (77, 35)[era]
|
||||
LLAMA_SPIT = (68, 37)[era]
|
||||
MINECART = (10, 39)[era] # MinecartRideable
|
||||
POTION = (73, 77)[era] # ThrownPotion
|
||||
SHULKER_BULLET = (67, 60)[era]
|
||||
SNOWBALL = (61, 67)[era]
|
||||
SPECTRAL_ARROW = (91, 68)[era]
|
||||
WITHER_SKULL = (66, 85)[era]
|
||||
if context.protocol_later_eq(393):
|
||||
TRIDENT = 94
|
||||
if pv >= 458:
|
||||
if context.protocol_later_eq(458):
|
||||
MINECART_CHEST = 40
|
||||
MINECART_COMMAND_BLOCK = 41
|
||||
MINECART_FURNACE = 42
|
||||
@@ -92,44 +93,44 @@ class SpawnObjectPacket(Packet):
|
||||
|
||||
def read(self, file_object):
|
||||
self.entity_id = VarInt.read(file_object)
|
||||
if self.context.protocol_version >= 49:
|
||||
if self.context.protocol_later_eq(49):
|
||||
self.object_uuid = UUID.read(file_object)
|
||||
|
||||
if self.context.protocol_version >= 458:
|
||||
if self.context.protocol_later_eq(458):
|
||||
self.type_id = VarInt.read(file_object)
|
||||
else:
|
||||
self.type_id = Byte.read(file_object)
|
||||
|
||||
xyz_type = Double if self.context.protocol_version >= 100 else Integer
|
||||
xyz_type = Double if self.context.protocol_later_eq(100) else Integer
|
||||
for attr in 'x', 'y', 'z':
|
||||
setattr(self, attr, xyz_type.read(file_object))
|
||||
for attr in 'pitch', 'yaw':
|
||||
setattr(self, attr, Angle.read(file_object))
|
||||
|
||||
self.data = Integer.read(file_object)
|
||||
if self.context.protocol_version >= 49 or self.data > 0:
|
||||
if self.context.protocol_later_eq(49) or self.data > 0:
|
||||
for attr in 'velocity_x', 'velocity_y', 'velocity_z':
|
||||
setattr(self, attr, Short.read(file_object))
|
||||
|
||||
def write_fields(self, packet_buffer):
|
||||
VarInt.send(self.entity_id, packet_buffer)
|
||||
if self.context.protocol_version >= 49:
|
||||
if self.context.protocol_later_eq(49):
|
||||
UUID.send(self.object_uuid, packet_buffer)
|
||||
|
||||
if self.context.protocol_version >= 458:
|
||||
if self.context.protocol_later_eq(458):
|
||||
VarInt.send(self.type_id, packet_buffer)
|
||||
else:
|
||||
Byte.send(self.type_id, packet_buffer)
|
||||
|
||||
# pylint: disable=no-member
|
||||
xyz_type = Double if self.context.protocol_version >= 100 else Integer
|
||||
xyz_type = Double if self.context.protocol_later_eq(100) else Integer
|
||||
for coord in self.x, self.y, self.z:
|
||||
xyz_type.send(coord, packet_buffer)
|
||||
for coord in self.pitch, self.yaw:
|
||||
Angle.send(coord, packet_buffer)
|
||||
|
||||
Integer.send(self.data, packet_buffer)
|
||||
if self.context.protocol_version >= 49 or self.data > 0:
|
||||
if self.context.protocol_later_eq(49) or self.data > 0:
|
||||
for coord in self.velocity_x, self.velocity_y, self.velocity_z:
|
||||
Short.send(coord, packet_buffer)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ from minecraft.networking.types import (
|
||||
class AbstractKeepAlivePacket(Packet):
|
||||
packet_name = "keep alive"
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'keep_alive_id': Long} if context.protocol_version >= 339
|
||||
{'keep_alive_id': Long} if context.protocol_later_eq(339)
|
||||
else {'keep_alive_id': VarInt}
|
||||
])
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ def get_packets(context):
|
||||
LoginStartPacket,
|
||||
EncryptionResponsePacket
|
||||
}
|
||||
if context.protocol_version >= 385:
|
||||
if context.protocol_later_eq(385):
|
||||
packets |= {
|
||||
PluginResponsePacket
|
||||
}
|
||||
@@ -21,8 +21,8 @@ def get_packets(context):
|
||||
class LoginStartPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x00 if context.protocol_version >= 391 else \
|
||||
0x01 if context.protocol_version >= 385 else \
|
||||
return 0x00 if context.protocol_later_eq(391) else \
|
||||
0x01 if context.protocol_later_eq(385) else \
|
||||
0x00
|
||||
|
||||
packet_name = "login start"
|
||||
@@ -33,8 +33,8 @@ class LoginStartPacket(Packet):
|
||||
class EncryptionResponsePacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x01 if context.protocol_version >= 391 else \
|
||||
0x02 if context.protocol_version >= 385 else \
|
||||
return 0x01 if context.protocol_later_eq(391) else \
|
||||
0x02 if context.protocol_later_eq(385) else \
|
||||
0x01
|
||||
|
||||
packet_name = "encryption response"
|
||||
@@ -50,7 +50,7 @@ class PluginResponsePacket(Packet):
|
||||
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x02 if context.protocol_version >= 391 else \
|
||||
return 0x02 if context.protocol_later_eq(391) else \
|
||||
0x00
|
||||
|
||||
packet_name = 'login plugin response'
|
||||
|
||||
@@ -23,11 +23,11 @@ def get_packets(context):
|
||||
PluginMessagePacket,
|
||||
PlayerBlockPlacementPacket,
|
||||
}
|
||||
if context.protocol_version >= 69:
|
||||
if context.protocol_later_eq(69):
|
||||
packets |= {
|
||||
UseItemPacket,
|
||||
}
|
||||
if context.protocol_version >= 107:
|
||||
if context.protocol_later_eq(107):
|
||||
packets |= {
|
||||
TeleportConfirmPacket,
|
||||
}
|
||||
@@ -37,33 +37,33 @@ def get_packets(context):
|
||||
class KeepAlivePacket(AbstractKeepAlivePacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x10 if context.protocol_version >= 712 else \
|
||||
0x0F if context.protocol_version >= 471 else \
|
||||
0x10 if context.protocol_version >= 464 else \
|
||||
0x0E if context.protocol_version >= 389 else \
|
||||
0x0C if context.protocol_version >= 386 else \
|
||||
0x0B if context.protocol_version >= 345 else \
|
||||
0x0A if context.protocol_version >= 343 else \
|
||||
0x0B if context.protocol_version >= 336 else \
|
||||
0x0C if context.protocol_version >= 318 else \
|
||||
0x0B if context.protocol_version >= 107 else \
|
||||
return 0x10 if context.protocol_later_eq(712) else \
|
||||
0x0F if context.protocol_later_eq(471) else \
|
||||
0x10 if context.protocol_later_eq(464) else \
|
||||
0x0E if context.protocol_later_eq(389) else \
|
||||
0x0C if context.protocol_later_eq(386) else \
|
||||
0x0B if context.protocol_later_eq(345) else \
|
||||
0x0A if context.protocol_later_eq(343) else \
|
||||
0x0B if context.protocol_later_eq(336) else \
|
||||
0x0C if context.protocol_later_eq(318) else \
|
||||
0x0B if context.protocol_later_eq(107) else \
|
||||
0x00
|
||||
|
||||
|
||||
class ChatPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x03 if context.protocol_version >= 464 else \
|
||||
0x02 if context.protocol_version >= 389 else \
|
||||
0x01 if context.protocol_version >= 343 else \
|
||||
0x02 if context.protocol_version >= 336 else \
|
||||
0x03 if context.protocol_version >= 318 else \
|
||||
0x02 if context.protocol_version >= 107 else \
|
||||
return 0x03 if context.protocol_later_eq(464) else \
|
||||
0x02 if context.protocol_later_eq(389) else \
|
||||
0x01 if context.protocol_later_eq(343) else \
|
||||
0x02 if context.protocol_later_eq(336) else \
|
||||
0x03 if context.protocol_later_eq(318) else \
|
||||
0x02 if context.protocol_later_eq(107) else \
|
||||
0x01
|
||||
|
||||
@staticmethod
|
||||
def get_max_length(context):
|
||||
return 256 if context.protocol_version >= 306 else \
|
||||
return 256 if context.protocol_later_eq(306) else \
|
||||
100
|
||||
|
||||
@property
|
||||
@@ -79,17 +79,17 @@ class ChatPacket(Packet):
|
||||
class PositionAndLookPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x13 if context.protocol_version >= 712 else \
|
||||
0x12 if context.protocol_version >= 471 else \
|
||||
0x13 if context.protocol_version >= 464 else \
|
||||
0x11 if context.protocol_version >= 389 else \
|
||||
0x0F if context.protocol_version >= 386 else \
|
||||
0x0E if context.protocol_version >= 345 else \
|
||||
0x0D if context.protocol_version >= 343 else \
|
||||
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 \
|
||||
return 0x13 if context.protocol_later_eq(712) else \
|
||||
0x12 if context.protocol_later_eq(471) else \
|
||||
0x13 if context.protocol_later_eq(464) else \
|
||||
0x11 if context.protocol_later_eq(389) else \
|
||||
0x0F if context.protocol_later_eq(386) else \
|
||||
0x0E if context.protocol_later_eq(345) else \
|
||||
0x0D if context.protocol_later_eq(343) else \
|
||||
0x0E if context.protocol_later_eq(336) else \
|
||||
0x0F if context.protocol_later_eq(332) else \
|
||||
0x0E if context.protocol_later_eq(318) else \
|
||||
0x0D if context.protocol_later_eq(107) else \
|
||||
0x06
|
||||
|
||||
packet_name = "position and look"
|
||||
@@ -126,22 +126,22 @@ class TeleportConfirmPacket(Packet):
|
||||
class AnimationPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x2C if context.protocol_version >= 738 else \
|
||||
0x2B if context.protocol_version >= 712 else \
|
||||
0x2A if context.protocol_version >= 468 else \
|
||||
0x29 if context.protocol_version >= 464 else \
|
||||
0x27 if context.protocol_version >= 389 else \
|
||||
0x25 if context.protocol_version >= 386 else \
|
||||
0x1D if context.protocol_version >= 345 else \
|
||||
0x1C if context.protocol_version >= 343 else \
|
||||
0x1D if context.protocol_version >= 332 else \
|
||||
0x1C if context.protocol_version >= 318 else \
|
||||
0x1A if context.protocol_version >= 107 else \
|
||||
return 0x2C if context.protocol_later_eq(738) else \
|
||||
0x2B if context.protocol_later_eq(712) else \
|
||||
0x2A if context.protocol_later_eq(468) else \
|
||||
0x29 if context.protocol_later_eq(464) else \
|
||||
0x27 if context.protocol_later_eq(389) else \
|
||||
0x25 if context.protocol_later_eq(386) else \
|
||||
0x1D if context.protocol_later_eq(345) else \
|
||||
0x1C if context.protocol_later_eq(343) else \
|
||||
0x1D if context.protocol_later_eq(332) else \
|
||||
0x1C if context.protocol_later_eq(318) else \
|
||||
0x1A if context.protocol_later_eq(107) else \
|
||||
0x0A
|
||||
|
||||
packet_name = "animation"
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'hand': VarInt} if context.protocol_version >= 107 else {}])
|
||||
{'hand': VarInt} if context.protocol_later_eq(107) else {}])
|
||||
|
||||
Hand = RelativeHand
|
||||
HAND_MAIN, HAND_OFF = Hand.MAIN, Hand.OFF # For backward compatibility.
|
||||
@@ -150,14 +150,14 @@ class AnimationPacket(Packet):
|
||||
class ClientStatusPacket(Packet, Enum):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x04 if context.protocol_version >= 464 else \
|
||||
0x03 if context.protocol_version >= 389 else \
|
||||
0x02 if context.protocol_version >= 343 else \
|
||||
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 \
|
||||
return 0x04 if context.protocol_later_eq(464) else \
|
||||
0x03 if context.protocol_later_eq(389) else \
|
||||
0x02 if context.protocol_later_eq(343) else \
|
||||
0x03 if context.protocol_later_eq(336) else \
|
||||
0x04 if context.protocol_later_eq(318) else \
|
||||
0x03 if context.protocol_later_eq(80) else \
|
||||
0x02 if context.protocol_later_eq(67) else \
|
||||
0x17 if context.protocol_later_eq(49) else \
|
||||
0x16
|
||||
|
||||
packet_name = "client status"
|
||||
@@ -175,13 +175,13 @@ class ClientStatusPacket(Packet, Enum):
|
||||
class PluginMessagePacket(AbstractPluginMessagePacket):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x0B if context.protocol_version >= 464 else \
|
||||
0x0A if context.protocol_version >= 389 else \
|
||||
0x09 if context.protocol_version >= 345 else \
|
||||
0x08 if context.protocol_version >= 343 else \
|
||||
0x09 if context.protocol_version >= 336 else \
|
||||
0x0A if context.protocol_version >= 317 else \
|
||||
0x09 if context.protocol_version >= 94 else \
|
||||
return 0x0B if context.protocol_later_eq(464) else \
|
||||
0x0A if context.protocol_later_eq(389) else \
|
||||
0x09 if context.protocol_later_eq(345) else \
|
||||
0x08 if context.protocol_later_eq(343) else \
|
||||
0x09 if context.protocol_later_eq(336) else \
|
||||
0x0A if context.protocol_later_eq(317) else \
|
||||
0x09 if context.protocol_later_eq(94) else \
|
||||
0x17
|
||||
|
||||
|
||||
@@ -201,17 +201,17 @@ class PlayerBlockPlacementPacket(Packet):
|
||||
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x2E if context.protocol_version >= 738 else \
|
||||
0x2D if context.protocol_version >= 712 else \
|
||||
0x2C if context.protocol_version >= 468 else \
|
||||
0x2B if context.protocol_version >= 464 else \
|
||||
0x29 if context.protocol_version >= 389 else \
|
||||
0x27 if context.protocol_version >= 386 else \
|
||||
0x1F if context.protocol_version >= 345 else \
|
||||
0x1E if context.protocol_version >= 343 else \
|
||||
0x1F if context.protocol_version >= 332 else \
|
||||
0x1E if context.protocol_version >= 318 else \
|
||||
0x1C if context.protocol_version >= 94 else \
|
||||
return 0x2E if context.protocol_later_eq(738) else \
|
||||
0x2D if context.protocol_later_eq(712) else \
|
||||
0x2C if context.protocol_later_eq(468) else \
|
||||
0x2B if context.protocol_later_eq(464) else \
|
||||
0x29 if context.protocol_later_eq(389) else \
|
||||
0x27 if context.protocol_later_eq(386) else \
|
||||
0x1F if context.protocol_later_eq(345) else \
|
||||
0x1E if context.protocol_later_eq(343) else \
|
||||
0x1F if context.protocol_later_eq(332) else \
|
||||
0x1E if context.protocol_later_eq(318) else \
|
||||
0x1C if context.protocol_later_eq(94) else \
|
||||
0x08
|
||||
|
||||
packet_name = 'player block placement'
|
||||
@@ -219,15 +219,15 @@ class PlayerBlockPlacementPacket(Packet):
|
||||
@staticmethod
|
||||
def get_definition(context):
|
||||
return [
|
||||
{'hand': VarInt} if context.protocol_version >= 453 else {},
|
||||
{'hand': VarInt} if context.protocol_later_eq(453) else {},
|
||||
{'location': Position},
|
||||
{'face': VarInt if context.protocol_version >= 69 else Byte},
|
||||
{'hand': VarInt} if context.protocol_version < 453 else {},
|
||||
{'x': Float if context.protocol_version >= 309 else Byte},
|
||||
{'y': Float if context.protocol_version >= 309 else Byte},
|
||||
{'z': Float if context.protocol_version >= 309 else Byte},
|
||||
{'face': VarInt if context.protocol_later_eq(69) else Byte},
|
||||
{'hand': VarInt} if context.protocol_earlier(453) else {},
|
||||
{'x': Float if context.protocol_later_eq(309) else Byte},
|
||||
{'y': Float if context.protocol_later_eq(309) else Byte},
|
||||
{'z': Float if context.protocol_later_eq(309) else Byte},
|
||||
({'inside_block': Boolean}
|
||||
if context.protocol_version >= 453 else {}),
|
||||
if context.protocol_later_eq(453) else {}),
|
||||
]
|
||||
|
||||
# PlayerBlockPlacementPacket.Hand is an alias for RelativeHand.
|
||||
@@ -240,18 +240,18 @@ class PlayerBlockPlacementPacket(Packet):
|
||||
class UseItemPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x2F if context.protocol_version >= 738 else \
|
||||
0x2E if context.protocol_version >= 712 else \
|
||||
0x2D if context.protocol_version >= 468 else \
|
||||
0x2C if context.protocol_version >= 464 else \
|
||||
0x2A if context.protocol_version >= 389 else \
|
||||
0x28 if context.protocol_version >= 386 else \
|
||||
0x20 if context.protocol_version >= 345 else \
|
||||
0x1F if context.protocol_version >= 343 else \
|
||||
0x20 if context.protocol_version >= 332 else \
|
||||
0x1F if context.protocol_version >= 318 else \
|
||||
0x1D if context.protocol_version >= 94 else \
|
||||
0x1A if context.protocol_version >= 70 else \
|
||||
return 0x2F if context.protocol_later_eq(738) else \
|
||||
0x2E if context.protocol_later_eq(712) else \
|
||||
0x2D if context.protocol_later_eq(468) else \
|
||||
0x2C if context.protocol_later_eq(464) else \
|
||||
0x2A if context.protocol_later_eq(389) else \
|
||||
0x28 if context.protocol_later_eq(386) else \
|
||||
0x20 if context.protocol_later_eq(345) else \
|
||||
0x1F if context.protocol_later_eq(343) else \
|
||||
0x20 if context.protocol_later_eq(332) else \
|
||||
0x1F if context.protocol_later_eq(318) else \
|
||||
0x1D if context.protocol_later_eq(94) else \
|
||||
0x1A if context.protocol_later_eq(70) else \
|
||||
0x08
|
||||
|
||||
packet_name = "use item"
|
||||
|
||||
@@ -8,12 +8,12 @@ from minecraft.networking.types import (
|
||||
class ClientSettingsPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x05 if context.protocol_version >= 464 else \
|
||||
0x04 if context.protocol_version >= 389 else \
|
||||
0x03 if context.protocol_version >= 343 else \
|
||||
0x04 if context.protocol_version >= 336 else \
|
||||
0x05 if context.protocol_version >= 318 else \
|
||||
0x04 if context.protocol_version >= 94 else \
|
||||
return 0x05 if context.protocol_later_eq(464) else \
|
||||
0x04 if context.protocol_later_eq(389) else \
|
||||
0x03 if context.protocol_later_eq(343) else \
|
||||
0x04 if context.protocol_later_eq(336) else \
|
||||
0x05 if context.protocol_later_eq(318) else \
|
||||
0x04 if context.protocol_later_eq(94) else \
|
||||
0x15
|
||||
|
||||
packet_name = 'client settings'
|
||||
@@ -21,10 +21,10 @@ class ClientSettingsPacket(Packet):
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'locale': String},
|
||||
{'view_distance': Byte},
|
||||
{'chat_mode': VarInt if context.protocol_version > 47 else Byte},
|
||||
{'chat_mode': VarInt if context.protocol_later(47) else Byte},
|
||||
{'chat_colors': Boolean},
|
||||
{'displayed_skin_parts': UnsignedByte},
|
||||
{'main_hand': VarInt} if context.protocol_version > 49 else {}])
|
||||
{'main_hand': VarInt} if context.protocol_later(49) else {}])
|
||||
|
||||
field_enum = classmethod(
|
||||
lambda cls, field, context: {
|
||||
|
||||
Reference in new issue
Block a user