keep track of tablist

This commit is contained in:
əlemi 2021-12-12 22:39:09 +01:00
parent ff56276662
commit 8c92591e2b

View file

@ -14,7 +14,7 @@ from aiocraft.mc.definitions import Difficulty, Dimension, Gamemode, BlockPos
from aiocraft.mc.proto.play.clientbound import ( from aiocraft.mc.proto.play.clientbound import (
PacketRespawn, PacketLogin, PacketPosition, PacketUpdateHealth, PacketExperience, PacketSetSlot, 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 ( from aiocraft.mc.proto.play.serverbound import (
PacketTeleportConfirm, PacketClientCommand, PacketSettings, PacketChat, PacketTeleportConfirm, PacketClientCommand, PacketSettings, PacketChat,
@ -50,6 +50,8 @@ class Treepuncher(MinecraftClient):
position : BlockPos position : BlockPos
# TODO world # TODO world
tablist : Dict[str, dict]
# TODO player abilities # TODO player abilities
# walk_speed : float # walk_speed : float
# fly_speed : float # fly_speed : float
@ -251,3 +253,19 @@ class Treepuncher(MinecraftClient):
self.lvl = packet.level self.lvl = packet.level
self.total_xp = packet.totalExperience 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)