From 65b42a2ed76079677dc38447c7254376267ea01c Mon Sep 17 00:00:00 2001 From: alemidev Date: Wed, 19 Jan 2022 01:15:54 +0100 Subject: [PATCH] tweaks to item type --- aiocraft/mc/definitions.py | 10 +++++++++- aiocraft/mc/types.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/aiocraft/mc/definitions.py b/aiocraft/mc/definitions.py index b0d4019..2887a73 100644 --- a/aiocraft/mc/definitions.py +++ b/aiocraft/mc/definitions.py @@ -101,7 +101,7 @@ class Item: nbt : dict damage : int # This got removed past 1.12.2 - def __init__(self, item:'Item' = None, id:int=0, count:int=0, nbt:dict=None, damage:int=0): + def __init__(self, item:'Item' = None, id:int=0, count:int=1, nbt:dict=None, damage:int=0): self.id = id self.count = count self.nbt = nbt or {} @@ -112,6 +112,14 @@ class Item: self.nbt = item.nbt self.damage = item.damage + def as_dict(self) -> dict: + return { + 'id': self.id, + 'count': self.count, + 'nbt': self.nbt, + 'damage': self.damage, + } + def __getitem__(self, key:str): # backwards compatibility return getattr(self, key) diff --git a/aiocraft/mc/types.py b/aiocraft/mc/types.py index 1861970..8ffd6bb 100644 --- a/aiocraft/mc/types.py +++ b/aiocraft/mc/types.py @@ -341,7 +341,7 @@ class SlotType(Type): else: check_type.write(False if new_way else -1, buffer, ctx) - def read(self, buffer:io.BytesIO, ctx:Context) -> Any: + def read(self, buffer:io.BytesIO, ctx:Context) -> Item: slot : Dict[Any, Any] = {} new_way = ctx._proto > 340 check_type = Boolean if new_way else Short