Some progress towards sending the map
All checks were successful
Build & Test / nix-build (pull_request) Successful in 2m39s
Build & Test / nix-build (push) Successful in 2m40s

This commit is contained in:
Kodi Craft 2024-10-01 19:26:24 +02:00
parent 453daa817b
commit 5fae9aa1ff
Signed by: kodi
GPG Key ID: 69D9EED60B242822
3 changed files with 34 additions and 3 deletions

View File

@ -88,6 +88,15 @@ defmodule Amethyst.API.Game do
mod.accept_teleport(self(), id, refs)
end
@doc """
The terrain of a specific chunk column. This is automatically used to load chunks for a player.
For now, this data must be formatted as a 3D list, indexed as [y][z][x].
"""
@callback chunk(from :: pid(), {x :: integer(), z :: integer()}, state_refs :: map()) :: [[[pos_integer()]]]
def chunk(%{:mod => mod, :refs => refs}, pos) do
mod.chunk(self(), pos, refs)
end
@doc """
Whether or not this game instance can be joined by a new player. This should include basic logic such as
if joining makes sense, for instance if the game is full or if the game has already started.
"""

View File

@ -119,8 +119,14 @@ defmodule Amethyst.ConnectionHandler do
end)
end
defp process_chunk(_chunk, _state) do
# TODO: Actually ask the game for the desired chunk then send the packets.
defp process_chunk(chunk, state) do
chunk_array = Amethyst.API.Game.chunk(Map.get(state, :game), chunk)
# TODO: Actually do heightmaps
import Amethyst.NBT.Write
heightmaps = compound(%{})
data = Enum.chunk_every(chunk_array, 16)
end
defp handle_packet(id, data, connstate, version, state) do

View File

@ -12,7 +12,7 @@ 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)}")
{:accept, {0.0, 0.0, 0.0}, {0.0, 0.0}}
{:accept, {0.0, 10.0, 0.0}, {0.0, 0.0}}
end
@impl true
@ -38,4 +38,20 @@ defmodule Example.Game do
def joinable?(_refs) do
true
end
@impl true
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
(0..15) |> Enum.map(fn _z ->
(0..15) |> Enum.map(fn _x -> 1 end)
end)
else
(0..15) |> Enum.map(fn _z ->
(0..15) |> Enum.map(fn _x -> 0 end)
end)
end
end)
end
end