From 53243c14fa323b2b251f10f94ec9a71dd7928f47 Mon Sep 17 00:00:00 2001 From: Kodi Craft Date: Thu, 3 Oct 2024 22:14:00 +0200 Subject: [PATCH] Load into the world!... somewhat --- apps/amethyst/lib/apps/connection_handler.ex | 20 +++++++++++--------- apps/amethyst/lib/states/play.ex | 5 ++++- apps/example_game/lib/example/game.ex | 2 +- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/apps/amethyst/lib/apps/connection_handler.ex b/apps/amethyst/lib/apps/connection_handler.ex index f078872..497a735 100644 --- a/apps/amethyst/lib/apps/connection_handler.ex +++ b/apps/amethyst/lib/apps/connection_handler.ex @@ -97,7 +97,7 @@ defmodule Amethyst.ConnectionHandler do end loop(socket, connstate, version, state) {:send_packet, packet} -> - Logger.debug("Sending packet #{inspect(packet)}") + # Logger.debug("Sending packet #{inspect(packet)}") send_packet(socket, connstate, packet, version) loop(socket, connstate, version, state) after 0 -> @@ -130,7 +130,8 @@ defmodule Amethyst.ConnectionHandler do {cx, cz} = chunk # TODO: Actually do heightmaps - # TODO: Doing all this processing could be at home somewhere else + # TODO: Doing all this processing could be at home somewhere else, as here it's + # not version-agnostic here heightmaps = compound(%{}) data = Enum.chunk_every(chunk_array, 16, 16, 0) # 0 -> air @@ -142,8 +143,9 @@ defmodule Amethyst.ConnectionHandler do unique_blocks = MapSet.new(blocks) min_bpe = MapSet.size(unique_blocks) |> :math.log2() |> ceil() paletted_container_data = case min_bpe do - 0 -> <<0::8>> <> + 0 -> # SINGLE VALUED + Write.ubyte(0) <> Write.varint(MapSet.to_list(unique_blocks) |> List.first()) <> Write.varint(0) # No data, empty pallette min_bpe when min_bpe in 1..8 -> @@ -172,8 +174,8 @@ defmodule Amethyst.ConnectionHandler do data end - # TODO: Send biome data, if that even makes sense - acc <> Write.short(block_count) <> paletted_container_data <> <<0::8, 0::8>> + acc <> Write.short(block_count) <> paletted_container_data <> + <<0::8, 0::8, 0::8>> # TODO: This should be biome data end) send(to, {:send_packet, %{ @@ -183,10 +185,10 @@ defmodule Amethyst.ConnectionHandler do data: data, block_entities: [], # TODO: Light - sky_light_mask: <<0>>, - block_light_mask: <<0>>, - empty_sky_light_mask: <<0>>, - empty_block_light_mask: <<0>>, + sky_light_mask: Write.varint(0), + block_light_mask: Write.varint(0), + empty_sky_light_mask: Write.varint(0), + empty_block_light_mask: Write.varint(0), sky_light_arrays: [], block_light_arrays: [] }}) diff --git a/apps/amethyst/lib/states/play.ex b/apps/amethyst/lib/states/play.ex index e91c06d..c7dface 100644 --- a/apps/amethyst/lib/states/play.ex +++ b/apps/amethyst/lib/states/play.ex @@ -23,7 +23,6 @@ defmodule Amethyst.ConnectionState.Play do @moduledoc """ This module contains the packets and logic for the Play state. """ - Macros.defpacket_clientbound :disconnect, 0x1D, 767, [reason: :nbt] Macros.defpacket_clientbound :chunk_data_and_update_light, 0x27, 767, [ chunk_x: :int, @@ -157,6 +156,7 @@ defmodule Amethyst.ConnectionState.Play do def ge_start_waiting_for_level_chunks(767), do: %{packet_type: :game_event, event: 13, value: 0} Macros.defpacket_serverbound :confirm_teleportation, 0x00, 767, [teleport_id: :varint] + Macros.defpacket_serverbound :serverbound_plugin_message, 0x12, 767, [channel: :string, data: :raw] Macros.defpacket_serverbound :set_player_position, 0x1A, 767, [ x: :double, feet_y: :double, @@ -198,6 +198,9 @@ defmodule Amethyst.ConnectionState.Play do Amethyst.API.Game.player_rotation(state[:game], {yaw, pitch}) :ok end + def handle(%{packet_type: :serverbound_plugin_message, channel: channel, data: _}, 767, _state) do + Logger.debug("Got plugin message on #{channel}") + end def disconnect(reason) do %{ diff --git a/apps/example_game/lib/example/game.ex b/apps/example_game/lib/example/game.ex index 92097b4..bcf83e7 100644 --- a/apps/example_game/lib/example/game.ex +++ b/apps/example_game/lib/example/game.ex @@ -40,7 +40,7 @@ defmodule Example.Game do end @impl true - def chunk(_from, {x, z}, _state_refs) do + def chunk(from, {x, z}, _state_refs) do # Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}") (0..255) |> Enum.map(fn y -> if y < 5 do