diff --git a/aiocraft/mc/mctypes.py b/aiocraft/mc/mctypes.py index ba40449..a31a0fa 100644 --- a/aiocraft/mc/mctypes.py +++ b/aiocraft/mc/mctypes.py @@ -165,13 +165,29 @@ class ByteArray(Type): length = VarInt.read(buffer) return buffer.read(length) +class IntegerByteArray(Type): + _pytype : type = bytes + + @classmethod + def write(cls, data:bytes, buffer:io.BytesIO): + Int.write(len(data), buffer) + buffer.write(data) + + @classmethod + def read(cls, buffer:io.BytesIO) -> bytes: + length = Int.read(buffer) + return buffer.read(length) + class Chat(String): _pytype : type = str - pass class Identifier(String): _pytype : type = str - pass + +class Angle(Type): + _pytype : type = int + _size : int = 1 + _fmt : str = ">b" class EntityMetadata(Type): _pytype : type = bytes @@ -198,10 +214,6 @@ class Position(Type): # TODO pass -class Angle(Type): - _pytype : type = bytes - # TODO - pass class UUID(Type): _pytype : type = bytes diff --git a/compiler/proto.py b/compiler/proto.py index 389e1f8..17907f8 100644 --- a/compiler/proto.py +++ b/compiler/proto.py @@ -55,7 +55,11 @@ def mctype(slot_type:Any) -> Type: if isinstance(slot_type, list): name = slot_type[0] if name == "buffer": - return ByteArray + data = slot_type[1] + if data["countType"] == "varint": + return ByteArray + elif data["countType"] == "integer": + return IntegerByteArray # TODO composite data types return TrailingByteArray