Some progress towards sending the map
This commit is contained in:
parent
453daa817b
commit
5fae9aa1ff
@ -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.
|
||||
"""
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user