Added support for snapshot 20w13a
This commit is contained in:
1 parent
76f7b4bdc9
commit
428a599f40
2 files changed
+16
-3
No files matched your search
@@ -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):
|
||||
|
||||
Reference in new issue
Block a user