From 8c92591e2bb081225c3a59264f7ccd64bc304c6d Mon Sep 17 00:00:00 2001 From: alemidev Date: Sun, 12 Dec 2021 22:39:09 +0100 Subject: [PATCH] keep track of tablist --- treepuncher/treepuncher.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/treepuncher/treepuncher.py b/treepuncher/treepuncher.py index 3c183b5..fa0df70 100644 --- a/treepuncher/treepuncher.py +++ b/treepuncher/treepuncher.py @@ -14,7 +14,7 @@ from aiocraft.mc.definitions import Difficulty, Dimension, Gamemode, BlockPos from aiocraft.mc.proto.play.clientbound import ( PacketRespawn, PacketLogin, PacketPosition, PacketUpdateHealth, PacketExperience, PacketSetSlot, - PacketAbilities, PacketChat as PacketChatMessage, PacketHeldItemSlot as PacketHeldItemChange + PacketAbilities, PacketPlayerInfo, PacketChat as PacketChatMessage, PacketHeldItemSlot as PacketHeldItemChange ) from aiocraft.mc.proto.play.serverbound import ( PacketTeleportConfirm, PacketClientCommand, PacketSettings, PacketChat, @@ -50,6 +50,8 @@ class Treepuncher(MinecraftClient): position : BlockPos # TODO world + tablist : Dict[str, dict] + # TODO player abilities # walk_speed : float # fly_speed : float @@ -251,3 +253,19 @@ class Treepuncher(MinecraftClient): self.lvl = packet.level self.total_xp = packet.totalExperience + @self.on_packet(PacketPlayerInfo) + async def tablist_update(packet:PacketPlayerInfo): + for record in packet.data: + uid = record['UUID'] + if packet.action == 0: + self.tablist[uid] = record + elif packet.action == 1: + self.tablist[uid]['gamemode'] = record['gamemode'] + elif packet.action == 2: + self.tablist[uid]['ping'] = record['ping'] + elif packet.action == 3: + self.tablist[uid]['displayName'] = record['displayName'] + elif packet.action == 4: + self.tablist.pop(uid, None) + +