tweaks to item type

This commit is contained in:
əlemi 2022-01-19 01:15:54 +01:00
parent f35f9d5434
commit 65b42a2ed7
2 changed files with 10 additions and 2 deletions

View file

@ -101,7 +101,7 @@ class Item:
nbt : dict nbt : dict
damage : int # This got removed past 1.12.2 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.id = id
self.count = count self.count = count
self.nbt = nbt or {} self.nbt = nbt or {}
@ -112,6 +112,14 @@ class Item:
self.nbt = item.nbt self.nbt = item.nbt
self.damage = item.damage 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 def __getitem__(self, key:str): # backwards compatibility
return getattr(self, key) return getattr(self, key)

View file

@ -341,7 +341,7 @@ class SlotType(Type):
else: else:
check_type.write(False if new_way else -1, buffer, ctx) 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] = {} slot : Dict[Any, Any] = {}
new_way = ctx._proto > 340 new_way = ctx._proto > 340
check_type = Boolean if new_way else Short check_type = Boolean if new_way else Short