mirror of
https://github.com/ammaraskar/pyCraft.git
synced 2024-11-22 02:08:56 +01:00
Added support for snapshot 20w13a
This commit is contained in:
parent
76f7b4bdc9
commit
428a599f40
@ -232,6 +232,7 @@ SUPPORTED_MINECRAFT_VERSIONS = {
|
||||
'20w10a': 705,
|
||||
'20w11a': 706,
|
||||
'20w12a': 707,
|
||||
'20w13a': 708,
|
||||
}
|
||||
|
||||
# Those Minecraft versions supported by pyCraft which are "release" versions,
|
||||
|
@ -253,6 +253,14 @@ class VarIntPrefixedByteArray(Type):
|
||||
socket.send(struct.pack(str(len(value)) + "s", value))
|
||||
|
||||
|
||||
# https://stackoverflow.com/questions/1604464/twos-complement-in-python
|
||||
def twos_comp(val, bits):
|
||||
"""compute the 2's complement of int value val"""
|
||||
if (val & (1 << (bits - 1))) != 0: # if sign bit is set
|
||||
val = val - (1 << bits) # compute negative value
|
||||
return val # return positive value as is
|
||||
|
||||
|
||||
class UUIDIntegerArray(Type):
|
||||
""" Minecraft sends an array of 4 integers to represent the most
|
||||
significant and least significant bits (as longs) of a UUID
|
||||
@ -263,7 +271,7 @@ class UUIDIntegerArray(Type):
|
||||
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)
|
||||
ints[3] << 32 | ints[2] & 0xffffffff)
|
||||
packed_uuid = uuid.UUID(bytes=packed)
|
||||
return str(packed_uuid)
|
||||
|
||||
@ -271,8 +279,12 @@ class UUIDIntegerArray(Type):
|
||||
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))
|
||||
socket.send(struct.pack(">4i", msb >> 32,
|
||||
twos_comp(msb & 0xffffffff, 32),
|
||||
lsb >> 32,
|
||||
twos_comp(lsb & 0xffffffff, 32)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class TrailingByteArray(Type):
|
||||
|
Loading…
Reference in New Issue
Block a user