bta-proxy/bta_proxy/itemstack.py

32 lines
1.0 KiB
Python
Raw Normal View History

2023-08-24 17:40:23 +03:00
2023-08-26 01:12:19 +03:00
from typing import Any
from bta_proxy.datainputstream import AsyncDataInputStream, SyncDataInputStream
2023-08-24 17:40:23 +03:00
class ItemStack:
2023-08-26 01:12:19 +03:00
__slots__ = ("item_id", "count", "data", "tag")
def __init__(self, item_id: int, count: int, data: int, tag: Any = None):
2023-08-24 17:40:23 +03:00
self.item_id = item_id
self.count = count
self.data = data
2023-08-26 01:12:19 +03:00
self.tag = tag
2023-08-24 17:40:23 +03:00
@classmethod
2023-08-25 21:49:10 +03:00
async def read_from(cls, stream: AsyncDataInputStream) -> 'ItemStack':
item_id = await stream.read_short()
count = await stream.read()
data = await stream.read_ushort()
2023-08-24 17:40:23 +03:00
return cls(item_id, count, data)
@classmethod
def read_from_sync(cls, stream: SyncDataInputStream) -> 'ItemStack':
item_id = stream.read_short()
count = stream.read()
data = stream.read_ushort()
return cls(item_id, count, data)
2023-08-26 01:12:19 +03:00
def __repr__(self):
if self.tag:
return f'<ItemStack! {self.item_id}:{self.data} x{self.count}>'
return f'<ItemStack {self.item_id}:{self.data} x{self.count}>'