mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-12-23 00:57:47 +01:00
Added support for snapshot 20w12a
This commit is contained in:
parent
5c6edf5e44
commit
76f7b4bdc9
@ -231,6 +231,7 @@ SUPPORTED_MINECRAFT_VERSIONS = {
|
||||
'20w09a': 704,
|
||||
'20w10a': 705,
|
||||
'20w11a': 706,
|
||||
'20w12a': 707,
|
||||
}
|
||||
|
||||
# Those Minecraft versions supported by pyCraft which are "release" versions,
|
||||
|
@ -1,7 +1,8 @@
|
||||
from minecraft.networking.packets import Packet
|
||||
|
||||
from minecraft.networking.types import (
|
||||
VarInt, String, VarIntPrefixedByteArray, TrailingByteArray
|
||||
VarInt, String, VarIntPrefixedByteArray, TrailingByteArray,
|
||||
UUIDIntegerArray
|
||||
)
|
||||
|
||||
|
||||
@ -54,9 +55,11 @@ class LoginSuccessPacket(Packet):
|
||||
0x02
|
||||
|
||||
packet_name = "login success"
|
||||
definition = [
|
||||
{'UUID': String},
|
||||
{'Username': String}]
|
||||
get_definition = staticmethod(lambda context: [
|
||||
{'UUID': UUIDIntegerArray} if context.protocol_version >= 707
|
||||
else {'UUID': String},
|
||||
{'Username': String}
|
||||
])
|
||||
|
||||
|
||||
class SetCompressionPacket(Packet):
|
||||
|
@ -206,7 +206,8 @@ class SpawnPlayerPacket(Packet):
|
||||
class EntityVelocityPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x46 if context.protocol_version >= 550 else \
|
||||
return 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 \
|
||||
@ -232,7 +233,8 @@ class EntityVelocityPacket(Packet):
|
||||
class UpdateHealthPacket(Packet):
|
||||
@staticmethod
|
||||
def get_id(context):
|
||||
return 0x49 if context.protocol_version >= 550 else \
|
||||
return 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 \
|
||||
|
@ -13,7 +13,6 @@ class SoundEffectPacket(Packet):
|
||||
0x51 if context.protocol_version >= 471 else \
|
||||
0x4D if context.protocol_version >= 461 else \
|
||||
0x4E if context.protocol_version >= 451 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 \
|
||||
|
@ -14,7 +14,7 @@ __all__ = (
|
||||
'Integer', 'FixedPointInteger', 'Angle', 'VarInt', 'Long',
|
||||
'UnsignedLong', 'Float', 'Double', 'ShortPrefixedByteArray',
|
||||
'VarIntPrefixedByteArray', 'TrailingByteArray', 'String', 'UUID',
|
||||
'Position',
|
||||
'Position', 'UUIDIntegerArray'
|
||||
)
|
||||
|
||||
|
||||
@ -253,6 +253,28 @@ class VarIntPrefixedByteArray(Type):
|
||||
socket.send(struct.pack(str(len(value)) + "s", value))
|
||||
|
||||
|
||||
class UUIDIntegerArray(Type):
|
||||
""" Minecraft sends an array of 4 integers to represent the most
|
||||
significant and least significant bits (as longs) of a UUID
|
||||
because that is how UUIDs are constructed in Java. We need to
|
||||
unpack this array and repack it with the right endianness to be
|
||||
used as a python UUID. """
|
||||
@staticmethod
|
||||
def read(file_object):
|
||||
ints = struct.unpack("4i", file_object.read(4 * 4))
|
||||
packed = struct.pack("<qq", ints[1] << 32 | ints[0] & 0xffffffff,
|
||||
ints[3] << 32 | ints[2] & 0xffffffff)
|
||||
packed_uuid = uuid.UUID(bytes=packed)
|
||||
return str(packed_uuid)
|
||||
|
||||
@staticmethod
|
||||
def send(value, socket):
|
||||
player_uuid = uuid.UUID(value)
|
||||
msb, lsb = struct.unpack(">qq", player_uuid.bytes)
|
||||
socket.send(struct.pack("4i", msb & 0xffffffff, msb >> 32,
|
||||
lsb & 0xffffffff, lsb >> 32))
|
||||
|
||||
|
||||
class TrailingByteArray(Type):
|
||||
""" A byte array consisting of all remaining data. If present in a packet
|
||||
definition, this should only be the type of the last field. """
|
||||
|
Loading…
Reference in New Issue
Block a user