From 1377e04d16719a5a01dc1f7d0f97e00de218db22 Mon Sep 17 00:00:00 2001 From: alemidev Date: Fri, 17 Dec 2021 13:35:50 +0100 Subject: [PATCH] added item formatter helper --- aiocraft/util/helpers.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/aiocraft/util/helpers.py b/aiocraft/util/helpers.py index 4cc75be..8ecc7f1 100644 --- a/aiocraft/util/helpers.py +++ b/aiocraft/util/helpers.py @@ -58,3 +58,17 @@ def parse_chat(msg:Union[dict,str], ansi_color:bool=False) -> str: for elem in data["extra"]: out += parse_chat(elem, ansi_color) return out + +def format_item(item:dict, compact=False, nbt:bool=False) -> str: + if not item: + return "[ ]" + item_id = f"{item['id']:03d}" + item_count = f"x{item['count']}" if 'count' in item else '' + item_damage = f"|{item['damage']:03d}" if 'damage' in item else '' + nbt = item['nbt'].pretty() if 'nbt' in item else '' + if compact: + return f"[{item_id:03d}]" + if nbt: + return f"[{item_id}{item_count}{item_damage}]({nbt})" + return f"[{item_id}{item_count}{item_damage}]" +