Implement handling confirm_teleportation
All checks were successful
Build & Test / nix-build (push) Successful in 2m50s
Build & Test / nix-build (pull_request) Successful in 2m52s

This commit is contained in:
Kodi Craft 2024-09-17 19:23:39 +02:00
parent 0fdc00148e
commit 53fe25043d
Signed by: kodi
GPG Key ID: 69D9EED60B242822
2 changed files with 25 additions and 0 deletions

View File

@ -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} ->

View File

@ -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
%{