From b754a4746da8c4aba4a8ccbfa9cb5483cfd28fcb Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Mon, 14 Dec 2020 04:27:06 +0000 Subject: [PATCH] Handle player teleport packet --- data.py | 2 +- game.py | 24 +++++++++++++++++++++--- monkey_patch.py | 9 +-------- protocol/packets.py | 33 +++++++++++++++++---------------- requirements.txt | 21 +++++++++++++++++++-- 5 files changed, 59 insertions(+), 30 deletions(-) diff --git a/data.py b/data.py index a94dfb1..9c90fa1 100644 --- a/data.py +++ b/data.py @@ -3,7 +3,7 @@ from munch import Munch import minecraft_data -mcd = minecraft_data('1.16.2') +mcd = minecraft_data('1.16.4') with open('mcdata/registries.json') as f: DATA = json.load(f) diff --git a/game.py b/game.py index f029424..e97664e 100644 --- a/game.py +++ b/game.py @@ -20,7 +20,7 @@ from protocol.packets import ( ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket, ClientWindowConfirmationPacket, EntityMetadataPacket, SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket, - EntityActionPacket, SpawnPlayerPacket, + EntityActionPacket, EntityTeleport, ) from protocol.types import Slot @@ -330,9 +330,10 @@ class Game: register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket) register(self.handle_entity_position_rotation, EntityPositionRotationPacket) register(self.handle_destroy_entities, DestroyEntitiesPacket) - register(self.handle_spawn_player, SpawnPlayerPacket) + register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket) register(self.handle_respawn, clientbound.play.RespawnPacket) register(self.handle_player_list, clientbound.play.PlayerListItemPacket) + register(self.handle_entity_teleport, EntityTeleport) #register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket) #register(self.handle_packet, Packet, early=True) @@ -917,7 +918,7 @@ class Game: print(packet) self.g.players[packet.entity_id] = Munch( entity_id=packet.entity_id, - player_uuid=packet.player_uuid, + player_uuid=packet.player_UUID, x=packet.x, y=packet.y, z=packet.z, @@ -1009,6 +1010,21 @@ class Game: if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) + def handle_entity_teleport(self, packet): + mob = self.g.mobs.get(packet.entity_id, None) + if mob: + mob.x = packet.x + mob.y = packet.y + mob.z = packet.z + + player = self.g.players.get(packet.entity_id, None) + if player: + player.x = packet.x + player.y = packet.y + player.z = packet.z + + if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet) + def handle_entity_velocity(self, packet): obj = self.g.objects.get(packet.entity_id, None) if obj: @@ -1023,6 +1039,8 @@ class Game: del self.g.objects[eid] if eid in self.g.mobs: del self.g.mobs[eid] + if eid in self.g.players: + del self.g.players[eid] def leave_bed(self): packet = EntityActionPacket() diff --git a/monkey_patch.py b/monkey_patch.py index 034c667..6bb7aa9 100644 --- a/monkey_patch.py +++ b/monkey_patch.py @@ -11,20 +11,13 @@ def get_packets(old_get_packets): mc_packets.add(packets.AcknowledgePlayerDiggingPacket) mc_packets.add(packets.BlockBreakAnimationPacket) mc_packets.add(packets.SetSlotPacket) - #mc_packets.add(packets.PlayerDiggingPacket) - #mc_packets.add(packets.PickItemPacket) - #mc_packets.add(packets.HeldItemChangePacket) mc_packets.add(packets.OpenWindowPacket) - #mc_packets.add(packets.CloseWindowPacket) - #mc_packets.add(packets.ClickWindowPacket) mc_packets.add(packets.ClientWindowConfirmationPacket) - #mc_packets.add(packets.ServerWindowConfirmationPacket) mc_packets.add(packets.EntityMetadataPacket) mc_packets.add(packets.SpawnLivingEntityPacket) mc_packets.add(packets.EntityPositionRotationPacket) mc_packets.add(packets.DestroyEntitiesPacket) - #mc_packets.add(packets.EntityActionPacket) - mc_packets.add(packets.SpawnPlayerPacket) + mc_packets.add(packets.EntityTeleport) return mc_packets diff --git a/protocol/packets.py b/protocol/packets.py index 4ab60a0..3c60920 100644 --- a/protocol/packets.py +++ b/protocol/packets.py @@ -330,6 +330,23 @@ class SpawnLivingEntityPacket(Packet): {'velocity_z': Short}, ] +class EntityTeleport(Packet): + # Sent by the server when an entity moves more than 8 blocks + # https://wiki.vg/Protocol#Entity_Teleport + + id = 0x56 + packet_name = 'entity teleport' + + definition = [ + {'entity_id': VarInt}, + {'x': Double}, + {'y': Double}, + {'z': Double}, + {'yaw': Angle}, + {'pitch': Angle}, + {'on_ground': Boolean}, + ] + class EntityPositionRotationPacket(Packet): # Sent by the server when an entity rotates and moves # https://wiki.vg/Protocol#Entity_Position_and_Rotation @@ -374,19 +391,3 @@ class EntityActionPacket(Packet): {'action_id': VarInt}, {'jump_boost': VarInt}, ] - -class SpawnPlayerPacket(Packet): - # https://wiki.vg/Protocol#Spawn_Player - - id = 0x04 - packet_name = 'spawn player' - - definition = [ - {'entity_id': VarInt}, - {'player_uuid': UUID}, - {'x': Double}, - {'y': Double}, - {'z': Double}, - {'yaw': Angle}, - {'pitch': Angle}, - ] diff --git a/requirements.txt b/requirements.txt index da3ea56..c90d4e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,23 +1,40 @@ +appdirs==1.4.3 astar==0.92 +CacheControl==0.12.6 certifi==2020.6.20 cffi==1.14.2 chardet==3.0.4 click==7.1.2 +colorama==0.4.3 +contextlib2==0.6.0 cryptography==3.1 +distlib==0.3.0 +distro==1.4.0 Flask==1.1.2 +html5lib==1.0.1 idna==2.10 +ipaddr==2.2.0 itsdangerous==1.1.0 Jinja2==2.11.2 +lockfile==0.12.2 MarkupSafe==1.1.1 -minecraft-data==2.67.0 +minecraft-data==2.70.1 +msgpack==0.6.2 munch==2.5.0 +packaging==20.3 panda3d==1.10.6.post2 pathtools==0.1.2 +pep517==0.8.2 +progress==1.5 pycparser==2.20 -pyCraft @ git+https://github.com/ammaraskar/pyCraft.git@2813d02ae7fb8182c3e5227a73de2240b09878d9 +pyCraft==0.7.0 PyNBT==3.0.0 +pyparsing==2.4.6 +pytoml==0.1.21 requests==2.24.0 +retrying==1.3.3 six==1.15.0 urllib3==1.25.10 watchdog==0.10.3 +webencodings==0.5.1 Werkzeug==1.0.1