From c3c3f832864a5312b7a732bb46e9397887e89d96 Mon Sep 17 00:00:00 2001 From: Kodi Craft Date: Tue, 1 Oct 2024 20:01:14 +0200 Subject: [PATCH] more work on sending map --- apps/amethyst/lib/apps/connection_handler.ex | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/apps/amethyst/lib/apps/connection_handler.ex b/apps/amethyst/lib/apps/connection_handler.ex index 6e56076..f7509f2 100644 --- a/apps/amethyst/lib/apps/connection_handler.ex +++ b/apps/amethyst/lib/apps/connection_handler.ex @@ -120,13 +120,27 @@ defmodule Amethyst.ConnectionHandler do end defp process_chunk(chunk, state) do + import Amethyst.NBT.Write + alias Amethyst.Minecraft.Write + 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, 16, 0) # 0 -> air + |> Enum.reduce(fn chunk_section, acc -> + blocks = chunk_section |> List.flatten() + block_count = blocks + |> Enum.map(&(if &1 == 0, do: 0, else: 1)) + |> Enum.sum() + + # TODO: Proper paletting + acc <> Write.short(block_count) <> Write.ubyte(15) + end) + + # TODO: Use paletting + end defp handle_packet(id, data, connstate, version, state) do