Readability
This commit is contained in:
1 parent
b45312db2f
commit
5cd8554908
1 file changed
+14
-16
+14
-16
@@ -72,40 +72,38 @@ def sendString(socket, value):
|
|||||||
|
|
||||||
def readEntityMetadata(FileObject):
|
def readEntityMetadata(FileObject):
|
||||||
metadata = {}
|
metadata = {}
|
||||||
byte = struct.unpack('!B', FileObject.read(1))[0]
|
byte = readUnsignedByte(FileObject)
|
||||||
while byte != 127:
|
while byte != 127:
|
||||||
index = byte & 0x1F # Lower 5 bits
|
index = byte & 0x1F # Lower 5 bits
|
||||||
ty = byte >> 5 # Upper 3 bits
|
ty = byte >> 5 # Upper 3 bits
|
||||||
if ty == 0: val = struct.unpack('!b', FileObject.read(1))[0]
|
if ty == 0: val = readByte(FileObject)
|
||||||
if ty == 1: val = struct.unpack('!h', FileObject.read(2))[0]
|
if ty == 1: val = readShort(FileObject)
|
||||||
if ty == 2: val = readInt(FileObject)
|
if ty == 2: val = readInt(FileObject)
|
||||||
if ty == 3: val = struct.unpack('!f', FileObject.read(4))[0]
|
if ty == 3: val = readFloat(FileObject)
|
||||||
if ty == 4:
|
if ty == 4:
|
||||||
length = struct.unpack('!h', FileObject.read(2))[0] * 2
|
val = readString(FileObject)
|
||||||
val = FileObject.read(length).decode('utf-16be')
|
|
||||||
if ty == 5:
|
if ty == 5:
|
||||||
val = {}
|
val = {}
|
||||||
val["id"] = struct.unpack('!h', FileObject.read(2))[0]
|
val["id"] = readShort(FileObject)
|
||||||
if (val["id"] != -1):
|
if (val["id"] != -1):
|
||||||
val["count"] = struct.unpack('!b', FileObject.read(1))[0]
|
val["count"] = readByte(FileObject)
|
||||||
val["damage"] = struct.unpack('!h', FileObject.read(2))[0]
|
val["damage"] = readShort(FileObject)
|
||||||
if ty == 6:
|
if ty == 6:
|
||||||
val = []
|
val = []
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
val.append(readInt(FileObject))
|
val.append(readInt(FileObject))
|
||||||
metadata[index] = (ty, val)
|
metadata[index] = (ty, val)
|
||||||
byte = struct.unpack('!B', FileObject.read(1))[0]
|
byte = readUnsignedByte(FileObject)
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
def readSlotData(FileObject):
|
def readSlotData(FileObject):
|
||||||
BlockID = struct.unpack('!h', FileObject.read(2))[0]
|
BlockID = readShort(FileObject)
|
||||||
if(BlockID != -1):
|
if(BlockID != -1):
|
||||||
ItemCount = struct.unpack('!b', FileObject.read(1))[0]
|
ItemCount = readByte(FileObject)
|
||||||
Damage = struct.unpack('!h', FileObject.read(2))[0]
|
Damage = readShort(FileObject)
|
||||||
MetadataLength = struct.unpack('!h', FileObject.read(2))[0]
|
MetadataLength = readShort(FileObject)
|
||||||
if(MetadataLength != -1):
|
if(MetadataLength != -1):
|
||||||
raw = FileObject.read(MetadataLength)
|
ByteArray = readByteArray(FileObject, MetadataLength)
|
||||||
ByteArray = struct.unpack(str(MetadataLength) + "s", raw)[0]
|
|
||||||
return {'BlockID' : BlockID,
|
return {'BlockID' : BlockID,
|
||||||
'ItemCount' : ItemCount,
|
'ItemCount' : ItemCount,
|
||||||
'Damage' : Damage,
|
'Damage' : Damage,
|
||||||
|
|||||||
Reference in new issue
Block a user