Load into the world!... somewhat
All checks were successful
Build & Test / nix-build (push) Successful in 2m35s
Build & Test / nix-build (pull_request) Successful in 2m39s

This commit is contained in:
Kodi Craft 2024-10-03 22:14:00 +02:00
parent f25e6fbf93
commit 53243c14fa
Signed by: kodi
GPG Key ID: 69D9EED60B242822
3 changed files with 16 additions and 11 deletions

View File

@ -97,7 +97,7 @@ defmodule Amethyst.ConnectionHandler do
end end
loop(socket, connstate, version, state) loop(socket, connstate, version, state)
{:send_packet, packet} -> {:send_packet, packet} ->
Logger.debug("Sending packet #{inspect(packet)}") # Logger.debug("Sending packet #{inspect(packet)}")
send_packet(socket, connstate, packet, version) send_packet(socket, connstate, packet, version)
loop(socket, connstate, version, state) loop(socket, connstate, version, state)
after 0 -> after 0 ->
@ -130,7 +130,8 @@ defmodule Amethyst.ConnectionHandler do
{cx, cz} = chunk {cx, cz} = chunk
# TODO: Actually do heightmaps # 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(%{}) heightmaps = compound(%{})
data = Enum.chunk_every(chunk_array, 16, 16, 0) # 0 -> air data = Enum.chunk_every(chunk_array, 16, 16, 0) # 0 -> air
@ -142,8 +143,9 @@ defmodule Amethyst.ConnectionHandler do
unique_blocks = MapSet.new(blocks) unique_blocks = MapSet.new(blocks)
min_bpe = MapSet.size(unique_blocks) |> :math.log2() |> ceil() min_bpe = MapSet.size(unique_blocks) |> :math.log2() |> ceil()
paletted_container_data = case min_bpe do paletted_container_data = case min_bpe do
0 -> <<0::8>> <> 0 ->
# SINGLE VALUED # SINGLE VALUED
Write.ubyte(0) <>
Write.varint(MapSet.to_list(unique_blocks) |> List.first()) <> Write.varint(MapSet.to_list(unique_blocks) |> List.first()) <>
Write.varint(0) # No data, empty pallette Write.varint(0) # No data, empty pallette
min_bpe when min_bpe in 1..8 -> min_bpe when min_bpe in 1..8 ->
@ -172,8 +174,8 @@ defmodule Amethyst.ConnectionHandler do
data data
end end
# TODO: Send biome data, if that even makes sense acc <> Write.short(block_count) <> paletted_container_data <>
acc <> Write.short(block_count) <> paletted_container_data <> <<0::8, 0::8>> <<0::8, 0::8, 0::8>> # TODO: This should be biome data
end) end)
send(to, {:send_packet, %{ send(to, {:send_packet, %{
@ -183,10 +185,10 @@ defmodule Amethyst.ConnectionHandler do
data: data, data: data,
block_entities: [], block_entities: [],
# TODO: Light # TODO: Light
sky_light_mask: <<0>>, sky_light_mask: Write.varint(0),
block_light_mask: <<0>>, block_light_mask: Write.varint(0),
empty_sky_light_mask: <<0>>, empty_sky_light_mask: Write.varint(0),
empty_block_light_mask: <<0>>, empty_block_light_mask: Write.varint(0),
sky_light_arrays: [], sky_light_arrays: [],
block_light_arrays: [] block_light_arrays: []
}}) }})

View File

@ -23,7 +23,6 @@ defmodule Amethyst.ConnectionState.Play do
@moduledoc """ @moduledoc """
This module contains the packets and logic for the Play state. This module contains the packets and logic for the Play state.
""" """
Macros.defpacket_clientbound :disconnect, 0x1D, 767, [reason: :nbt] Macros.defpacket_clientbound :disconnect, 0x1D, 767, [reason: :nbt]
Macros.defpacket_clientbound :chunk_data_and_update_light, 0x27, 767, [ Macros.defpacket_clientbound :chunk_data_and_update_light, 0x27, 767, [
chunk_x: :int, 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} 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 :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, [ Macros.defpacket_serverbound :set_player_position, 0x1A, 767, [
x: :double, x: :double,
feet_y: :double, feet_y: :double,
@ -198,6 +198,9 @@ defmodule Amethyst.ConnectionState.Play do
Amethyst.API.Game.player_rotation(state[:game], {yaw, pitch}) Amethyst.API.Game.player_rotation(state[:game], {yaw, pitch})
:ok :ok
end 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 def disconnect(reason) do
%{ %{

View File

@ -40,7 +40,7 @@ defmodule Example.Game do
end end
@impl true @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}") # Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
(0..255) |> Enum.map(fn y -> (0..255) |> Enum.map(fn y ->
if y < 5 do if y < 5 do