diff --git a/apps/amethyst/lib/apps/connection_handler.ex b/apps/amethyst/lib/apps/connection_handler.ex index ac43cbe..39dc204 100644 --- a/apps/amethyst/lib/apps/connection_handler.ex +++ b/apps/amethyst/lib/apps/connection_handler.ex @@ -64,6 +64,9 @@ defmodule Amethyst.ConnectionHandler do Logger.debug("Sending packet #{inspect(packet)}") send_packet(socket, connstate, packet, version) loop(socket, connstate, version, state) + {:tp_done, id} -> + # TODO: Implement a proper teleportation API + Logger.debug("Accepted teleportation #{inspect(id)}") after 0 -> receive do {:packet, id, data} -> diff --git a/apps/amethyst/lib/states/play.ex b/apps/amethyst/lib/states/play.ex index 8830de0..c90c0cd 100644 --- a/apps/amethyst/lib/states/play.ex +++ b/apps/amethyst/lib/states/play.ex @@ -49,6 +49,28 @@ defmodule Amethyst.ConnectionState.Play do portal_cooldown: :varint, enforces_secure_chat: :bool, ] + Macros.defpacket_clientbound :synchronize_player_position, 0x40, 747, [ + x: :double, + y: :double, + z: :double, + yaw: :float, + pitch: :double, + flags: :byte, + teleport_id: :varint + ] + + Macros.defpacket_serverbound :confirm_teleportation, 0x00, 747, [teleport_id: :varint] + + def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 747, state) do + if state[:teleport_id] == id do + # The client has accepted our teleportation, we can let the connection process know + send(self(), {:tp_done, id}) + state |> Map.put(:teleport_id, nil) + else + # The client has not yet accepted our teleportation, we aren't done yet + state + end + end def disconnect(reason) do %{