From 034f21ade75a12b0c8a4b030b8405bb5cea93ae3 Mon Sep 17 00:00:00 2001 From: Kodi Craft Date: Wed, 25 Sep 2024 11:09:26 +0200 Subject: [PATCH] begin implementing the second worst packet of this protocol --- apps/amethyst/lib/states/macros.ex | 4 ++-- apps/amethyst/lib/states/play.ex | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/apps/amethyst/lib/states/macros.ex b/apps/amethyst/lib/states/macros.ex index 0cd5722..a6def10 100644 --- a/apps/amethyst/lib/states/macros.ex +++ b/apps/amethyst/lib/states/macros.ex @@ -78,7 +78,7 @@ defmodule Amethyst.ConnectionState.Macros do end def write_signature(packet, signature) do - data = Enum.reduce(signature, "", fn {name, type}, acc -> + Enum.reduce(signature, "", fn {name, type}, acc -> #acc <> apply(Write, type, [Map.get(packet, name)]) case type do {:optional, {:compound, signature}} -> @@ -145,7 +145,7 @@ defmodule Amethyst.ConnectionState.Macros do _ -> false end end - def type_matches(value, {:optional, type}) when is_nil(value), do: true + def type_matches(value, {:optional, _type}) when is_nil(value), do: true def type_matches(value, {:optional, type}), do: type_matches(value, type) def type_matches(value, {:array, signature}) when is_list(value), do: Enum.all?(value, fn item -> check_type(item, signature) end) def type_matches(value, {:compound, signature}) when is_map(value), do: check_type(value, signature) diff --git a/apps/amethyst/lib/states/play.ex b/apps/amethyst/lib/states/play.ex index 0dbfd2c..b69ead6 100644 --- a/apps/amethyst/lib/states/play.ex +++ b/apps/amethyst/lib/states/play.ex @@ -16,6 +16,7 @@ defmodule Amethyst.ConnectionState.Play do require Amethyst.ConnectionState.Macros + alias Amethyst.Minecraft.Write alias Amethyst.ConnectionState.Macros require Logger @@ -79,6 +80,19 @@ defmodule Amethyst.ConnectionState.Play do pitch: :float, on_ground: :bool # I don't understand their obsession with this... ] + # this packet sucks, thoughtful design is for losers anyway + def serialize(%{packet_type: :game_event, event: :no_respawn_block_available}, 767), do: Write.ubyte(0) + def serialize(%{packet_type: :game_event, event: :begin_raining}, 767), do: Write.ubyte(1) + def serialize(%{packet_type: :game_event, event: :end_raining}, 767), do: Write.ubyte(2) + def serialize(%{packet_type: :game_event, event: :change_gamemode, value: v}, 767), do: Write.ubyte(3) <> Write.float(v) + def serialize(%{packet_type: :game_event, event: :win_game, value: v}, 767), do: Write.ubyte(4) <> Write.float(v) + def serialize(%{packet_type: :game_event, event: :demo_event, value: v}, 767), do: Write.ubyte(5) <> Write.float(v) + def serialize(%{packet_type: :game_event, event: :arrow_hit_player}, 767), do: Write.ubyte(6) + def serialize(%{packet_type: :game_event, event: :rain_level_change, value: v}, 767), do: Write.ubyte(7) <> Write.float(v) + def serialize(%{packet_type: :game_event, event: :thunder_level_change, value: v}, 767), do: Write.ubyte(8) <> Write.float(v) + def serialize(%{packet_type: :game_event, event: :play_pufferfish_sting_sound}, 767), do: Write.ubyte(9) + def serialize(%{packet_type: :game_event, event: :play_elder_guardian_mob_appearance}, 767), do: Write.ubyte(10) + def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 767, state) do Amethyst.API.Game.accept_teleport(state[:game], id)