From f037f0de02e1844a64ff63a07e69465ff5998ecc Mon Sep 17 00:00:00 2001 From: Kodi Craft Date: Thu, 19 Sep 2024 15:11:59 +0200 Subject: [PATCH] No longer rely on loose error checking and other minor fixes --- apps/amethyst/lib/apps/tcp_listener.ex | 2 +- apps/amethyst/lib/states/configuration.ex | 2 ++ apps/amethyst/lib/states/login.ex | 2 +- apps/amethyst/lib/states/play.ex | 17 +++++++++++++---- apps/example_game/lib/example/game.ex | 5 +++++ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/apps/amethyst/lib/apps/tcp_listener.ex b/apps/amethyst/lib/apps/tcp_listener.ex index 7696ee0..7c10ca2 100644 --- a/apps/amethyst/lib/apps/tcp_listener.ex +++ b/apps/amethyst/lib/apps/tcp_listener.ex @@ -21,7 +21,7 @@ defmodule Amethyst.TCPListener do """ def accept(port) do - {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: 0, active: false, reuseaddr: true]) + {:ok, socket} = :gen_tcp.listen(port, [:binary, packet: 0, active: false, reuseaddr: true, nodelay: true]) Logger.info("Listening on port #{port}") loop_acceptor(socket) end diff --git a/apps/amethyst/lib/states/configuration.ex b/apps/amethyst/lib/states/configuration.ex index 32a2dc9..e6f6c39 100644 --- a/apps/amethyst/lib/states/configuration.ex +++ b/apps/amethyst/lib/states/configuration.ex @@ -258,6 +258,8 @@ defmodule Amethyst.ConnectionState.Configuration do %{id: "minecraft:stalagmite", data: generic_damage}, %{id: "minecraft:outside_border", data: generic_damage}, %{id: "minecraft:generic_kill", data: generic_damage}, + %{id: "minecraft:hot_floor", data: generic_damage}, + %{id: "minecraft:in_wall", data: generic_damage}, ] }}) send(self(), {:send_packet, %{packet_type: :finish_configuration}}) diff --git a/apps/amethyst/lib/states/login.ex b/apps/amethyst/lib/states/login.ex index 2e6f752..bd4be9b 100644 --- a/apps/amethyst/lib/states/login.ex +++ b/apps/amethyst/lib/states/login.ex @@ -70,7 +70,7 @@ defmodule Amethyst.ConnectionState.Login do uuid: player_uuid, username: name, properties: [], - strict_error_handling: false + strict_error_handling: true }}) :ok end diff --git a/apps/amethyst/lib/states/play.ex b/apps/amethyst/lib/states/play.ex index 9ba37a9..42a043f 100644 --- a/apps/amethyst/lib/states/play.ex +++ b/apps/amethyst/lib/states/play.ex @@ -49,19 +49,28 @@ defmodule Amethyst.ConnectionState.Play do portal_cooldown: :varint, enforces_secure_chat: :bool, ] - Macros.defpacket_clientbound :synchronize_player_position, 0x40, 747, [ + Macros.defpacket_clientbound :synchronize_player_position, 0x40, 767, [ x: :double, y: :double, z: :double, yaw: :float, - pitch: :double, + pitch: :float, flags: :byte, teleport_id: :varint ] - Macros.defpacket_serverbound :confirm_teleportation, 0x00, 747, [teleport_id: :varint] + Macros.defpacket_serverbound :confirm_teleportation, 0x00, 767, [teleport_id: :varint] - def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 747, state) do + @spec handle( + %{ + :packet_type => :confirm_teleportation, + :teleport_id => any(), + optional(any()) => any() + }, + 767, + nil | maybe_improper_list() | map() + ) :: :ok + def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 767, state) do Amethyst.API.Game.accept_teleport(state[:game], id) :ok end diff --git a/apps/example_game/lib/example/game.ex b/apps/example_game/lib/example/game.ex index 2bceca0..4754215 100644 --- a/apps/example_game/lib/example/game.ex +++ b/apps/example_game/lib/example/game.ex @@ -12,6 +12,11 @@ defmodule Example.Game do def login(from, cfg, refs) do Logger.info("Player logged in from #{inspect(from)}: #{inspect(cfg)}") Logger.info("The refs for this game are #{inspect(refs)}") + #send(from, {:send_packet, %{ + # packet_type: :synchronize_player_position, + # x: 0.0, y: 0.0, z: 0.0, yaw: 0.0, pitch: 0.0, flags: 0x00, + # teleport_id: 0 + #}}) :accept end