Add big and awful code
All checks were successful
Build & Test / nix-build (push) Successful in 1m10s
All checks were successful
Build & Test / nix-build (push) Successful in 1m10s
This commit is contained in:
parent
204c6b0142
commit
8572ac5443
@ -63,6 +63,10 @@ defmodule Amethyst.Minecraft.Write do
|
|||||||
def string(value) do
|
def string(value) do
|
||||||
<<varint(byte_size(value))::binary, value::binary>>
|
<<varint(byte_size(value))::binary, value::binary>>
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def position({x, y, z}) do
|
||||||
|
<<x::signed-big-26, z::signed-big-26, y::signed-big-12>>
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Amethyst.Minecraft.Read do
|
defmodule Amethyst.Minecraft.Read do
|
||||||
|
@ -38,7 +38,23 @@ defmodule Amethyst.Server.Play do
|
|||||||
|
|
||||||
## SERIALIZATION
|
## SERIALIZATION
|
||||||
@impl true
|
@impl true
|
||||||
|
# Login https://wiki.vg/Protocol#Login_(play)
|
||||||
|
def serialize({:login, eid, hardcore, dimensions,
|
||||||
|
max_players, view_distance, simulation_distance,
|
||||||
|
reduce_debug, enable_respawn_screen, limited_crafting,
|
||||||
|
dim_type, dim_name, hashed_seed, gamemode, prev_gm,
|
||||||
|
is_debug, is_flat, death_loc, portal_cooldown, enforce_chat}) do
|
||||||
|
# TODO: this singlehandedly made me regret not making the write API better, please rework :(
|
||||||
|
<<eid::big-signed-32>> <> if(hardcore, do: <<1::big-8>>, else: <<0::big-8>>) <>
|
||||||
|
Write.varint(length(dimensions)) <> Enum.reduce(dimensions, "", fn dim, acc -> acc <> Write.string(dim) end) <>
|
||||||
|
Write.varint(max_players) <> Write.varint(view_distance) <> Write.varint(simulation_distance) <> if(reduce_debug, do: <<1::big-8>>, else: <<0::big-8>>) <>
|
||||||
|
if(enable_respawn_screen, do: <<1::big-8>>, else: <<0::big-8>>)
|
||||||
|
if(limited_crafting, do: <<1::big-8>>, else: <<0::big-8>>) <> Write.varint(dim_type) <> Write.string(dim_name) <>
|
||||||
|
hashed_seed <> <<gamemode_id(gamemode)::unsigned-big-8>> <> <<gamemode_id(prev_gm)::signed-big-8>> <>
|
||||||
|
if(is_debug, do: <<1::big-8>>, else: <<0::big-8>>) <> if(is_flat, do: <<1::big-8>>, else: <<0::big-8>>) <>
|
||||||
|
if(death_loc == nil, do: <<0::big-8>>, else: <<1::big-8>> <> Write.string(elem(death_loc, 0)) <> Write.position(elem(death_loc, 1))) <>
|
||||||
|
Write.varint(portal_cooldown) <> if(enforce_chat, do: <<1::big-8>>, else: <<0::big-8>>)
|
||||||
|
end
|
||||||
def serialize(packet) do
|
def serialize(packet) do
|
||||||
raise ArgumentError, "Tried serializing unknown packet #{inspect(packet)}"
|
raise ArgumentError, "Tried serializing unknown packet #{inspect(packet)}"
|
||||||
end
|
end
|
||||||
@ -49,4 +65,14 @@ defmodule Amethyst.Server.Play do
|
|||||||
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
Logger.error("Unhandled but known packet #{elem(tuple, 0)}")
|
||||||
{:unhandled, state}
|
{:unhandled, state}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp gamemode_id(gm) do
|
||||||
|
case gm do
|
||||||
|
nil -> -1
|
||||||
|
:survival -> 0
|
||||||
|
:creative -> 1
|
||||||
|
:adventure -> 2
|
||||||
|
:spectator -> 3
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user