Properly implement light... I think
All checks were successful
Build & Test / nix-build (push) Successful in 1m47s

This commit is contained in:
Kodi Craft 2024-10-08 09:06:54 +02:00
parent b44784e9ef
commit c2cbfdf888
Signed by: kodi
GPG Key ID: 69D9EED60B242822
3 changed files with 4 additions and 5 deletions

View File

@ -220,6 +220,7 @@ defmodule Amethyst.ConnectionHandler do
block_light_array = non_empty_block_light_sections |> Enum.map(&(Enum.reduce(&1, <<>>, fn light, acc -> block_light_array = non_empty_block_light_sections |> Enum.map(&(Enum.reduce(&1, <<>>, fn light, acc ->
<<acc::bitstring, light::size(4)>> <<acc::bitstring, light::size(4)>>
end))) end)))
Logger.debug("#{length(block_light_array)} block light sections to send")
send(to, {:send_packet, %{ send(to, {:send_packet, %{
packet_type: :chunk_data_and_update_light, packet_type: :chunk_data_and_update_light,

View File

@ -142,14 +142,12 @@ defmodule Amethyst.Minecraft.Write do
end end
def bitset(list) do def bitset(list) do
Logger.debug("Writing bitset #{inspect(list)}")
unaligned = Enum.reduce(list, <<>>, &(if &1 do <<&2::bitstring, 1::1>> else <<&2::bitstring, 0::1>> end)) unaligned = Enum.reduce(list, <<>>, &(if &1 do <<&2::bitstring, 1::1>> else <<&2::bitstring, 0::1>> end))
aligned = if rem(bit_size(unaligned), 64) == 0 do aligned = if rem(bit_size(unaligned), 64) == 0 do
unaligned unaligned
else else
<<unaligned::bitstring, 0::size(64 - rem(bit_size(unaligned), 64))>> <<0::size(64 - rem(bit_size(unaligned), 64)), unaligned::bitstring>>
end end
Logger.debug("Writing as #{inspect(aligned)}")
varint(div(byte_size(aligned), 8)) <> aligned varint(div(byte_size(aligned), 8)) <> aligned
end end
end end

View File

@ -50,9 +50,9 @@ defmodule Example.Game do
gz = cz * 16 + z gz = cz * 16 + z
gy = y gy = y
if rem(gx, 4) == 0 && rem(gy, 4) == 0 && rem(gz, 4) == 0 do if rem(gx, 4) == 0 && rem(gy, 4) == 0 && rem(gz, 4) == 0 do
{abs(rem(div(gx + gy + gz, 4), 1000)), 15, 0} {abs(rem(div(gx + gy + gz, 4), 1000)), 15, 15}
else else
{0, 15, 0} {0, 15, 15}
end end
end) end)
end) end)