Some experimentation
This commit is contained in:
parent
53243c14fa
commit
fb0099352b
@ -126,7 +126,7 @@ defmodule Amethyst.ConnectionHandler do
|
|||||||
import Amethyst.NBT.Write
|
import Amethyst.NBT.Write
|
||||||
alias Amethyst.Minecraft.Write
|
alias Amethyst.Minecraft.Write
|
||||||
|
|
||||||
chunk_array = Amethyst.API.Game.chunk(Map.get(state, :game), chunk)
|
chunk_array = Amethyst.Game.chunk(Map.get(state, :game), chunk)
|
||||||
{cx, cz} = chunk
|
{cx, cz} = chunk
|
||||||
|
|
||||||
# TODO: Actually do heightmaps
|
# TODO: Actually do heightmaps
|
||||||
@ -227,8 +227,12 @@ defmodule Amethyst.ConnectionHandler do
|
|||||||
end
|
end
|
||||||
rescue
|
rescue
|
||||||
e ->
|
e ->
|
||||||
Logger.error("Error handling packet with ID #{inspect(id, base: :hex)} in state #{connstate}: #{Exception.format(:error, e, __STACKTRACE__)}")
|
if Mix.env() == :dev do
|
||||||
send(self(), {:disconnect, "§cError handling packet #{inspect(id, base: :hex)}:\n#{Exception.format(:error, e, __STACKTRACE__)}"})
|
Logger.error("Error handling packet with ID #{inspect(id, base: :hex)} in state #{connstate}: #{Exception.format(:error, e, __STACKTRACE__)}")
|
||||||
|
else
|
||||||
|
send(self(), {:disconnect, "§cError handling packet #{inspect(id, base: :hex)}:\n#{Exception.format(:error, e, __STACKTRACE__)}"})
|
||||||
|
Logger.error("Error handling packet with ID #{inspect(id, base: :hex)} in state #{connstate}: #{Exception.format(:error, e, __STACKTRACE__)}")
|
||||||
|
end
|
||||||
state
|
state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
defmodule Amethyst.API.Game do
|
defmodule Amethyst.Game do
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
This behaviour should be implemented by any Amethyst Game. It additionally
|
This behaviour should be implemented by any Amethyst Game. It additionally
|
||||||
contains functions that the internal connection handler code uses to more
|
contains functions that the internal connection handler code uses to more
|
@ -271,7 +271,7 @@ defmodule Amethyst.ConnectionState.Configuration do
|
|||||||
send(self(), {:set_state, Amethyst.ConnectionState.Play})
|
send(self(), {:set_state, Amethyst.ConnectionState.Play})
|
||||||
game = Application.fetch_env!(:amethyst, :default_game) |> Amethyst.GameCoordinator.find_or_create()
|
game = Application.fetch_env!(:amethyst, :default_game) |> Amethyst.GameCoordinator.find_or_create()
|
||||||
state = state |> Map.put(:game, game)
|
state = state |> Map.put(:game, game)
|
||||||
login = Amethyst.API.Game.login(game, state)
|
login = Amethyst.Game.login(game, state)
|
||||||
case login do
|
case login do
|
||||||
:reject ->
|
:reject ->
|
||||||
send(self(), {:disconnect, "Default game rejected connection"})
|
send(self(), {:disconnect, "Default game rejected connection"})
|
||||||
@ -291,7 +291,7 @@ defmodule Amethyst.ConnectionState.Configuration do
|
|||||||
dimension_type: 0,
|
dimension_type: 0,
|
||||||
dimension_name: "minecraft:overworld",
|
dimension_name: "minecraft:overworld",
|
||||||
hashed_seed: 0,
|
hashed_seed: 0,
|
||||||
game_mode: 3,
|
game_mode: 1,
|
||||||
previous_game_mode: -1,
|
previous_game_mode: -1,
|
||||||
is_debug: false,
|
is_debug: false,
|
||||||
is_flat: false,
|
is_flat: false,
|
||||||
|
@ -176,31 +176,60 @@ defmodule Amethyst.ConnectionState.Play do
|
|||||||
pitch: :float,
|
pitch: :float,
|
||||||
on_ground: :bool # I don't understand their obsession with this...
|
on_ground: :bool # I don't understand their obsession with this...
|
||||||
]
|
]
|
||||||
|
Macros.defpacket_serverbound :set_player_on_ground, 0x1D, 767, [on_ground: :bool]
|
||||||
|
Macros.defpacket_serverbound :player_command, 0x25, 767, [eid: :varint, action_id: :varint, jump_boost: :varint]
|
||||||
|
|
||||||
def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 767, state) do
|
def handle(%{packet_type: :confirm_teleportation, teleport_id: id}, 767, state) do
|
||||||
Amethyst.API.Game.accept_teleport(state[:game], id)
|
Amethyst.Game.accept_teleport(state[:game], id)
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle(%{packet_type: :set_player_position_and_rotation, x: x, feet_y: y, z: z, yaw: yaw, pitch: pitch, on_ground: _ground}, 767, state) do
|
def handle(%{packet_type: :set_player_position_and_rotation, x: x, feet_y: y, z: z, yaw: yaw, pitch: pitch, on_ground: _ground}, 767, state) do
|
||||||
# I don't know why we would ever trust on_ground here... the server computes that
|
# I don't know why we would ever trust on_ground here... the server computes that
|
||||||
Amethyst.API.Game.player_position(state[:game], {x, y, z})
|
Amethyst.Game.player_position(state[:game], {x, y, z})
|
||||||
Amethyst.API.Game.player_rotation(state[:game], {yaw, pitch})
|
Amethyst.Game.player_rotation(state[:game], {yaw, pitch})
|
||||||
:ok
|
|
||||||
end
|
|
||||||
def handle(%{packet_type: :set_player_position, x: x, feet_y: y, z: z, on_ground: _ground}, 767, state) do
|
|
||||||
# I don't know why we would ever trust on_ground here... the server computes that
|
|
||||||
Amethyst.API.Game.player_position(state[:game], {x, y, z})
|
|
||||||
:ok
|
|
||||||
end
|
|
||||||
def handle(%{packet_type: :set_player_rotation, yaw: yaw, pitch: pitch, on_ground: _ground}, 767, state) do
|
|
||||||
# I don't know why we would ever trust on_ground here... the server computes that
|
|
||||||
Amethyst.API.Game.player_rotation(state[:game], {yaw, pitch})
|
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
def handle(%{packet_type: :serverbound_plugin_message, channel: channel, data: _}, 767, _state) do
|
def handle(%{packet_type: :serverbound_plugin_message, channel: channel, data: _}, 767, _state) do
|
||||||
Logger.debug("Got plugin message on #{channel}")
|
Logger.debug("Got plugin message on #{channel}")
|
||||||
end
|
end
|
||||||
|
def handle(%{packet_type: :set_player_position, x: x, feet_y: y, z: z, on_ground: _ground}, 767, state) do
|
||||||
|
# I don't know why we would ever trust on_ground here... the server computes that
|
||||||
|
Amethyst.Game.player_position(state[:game], {x, y, z})
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
def handle(%{packet_type: :set_player_rotation, yaw: yaw, pitch: pitch, on_ground: _ground}, 767, state) do
|
||||||
|
# I don't know why we would ever trust on_ground here... the server computes that
|
||||||
|
Amethyst.Game.player_rotation(state[:game], {yaw, pitch})
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
def handle(%{packet_type: :set_player_on_ground, on_ground: _}, 767, _state) do
|
||||||
|
:ok # Again, don't trust the client for something we can compute
|
||||||
|
end
|
||||||
|
def handle(%{packet_type: :player_command, eid: _eid, action_id: aid, jump_boost: _horse_jump}, 767, state) do
|
||||||
|
# TODO: Actually handle these events
|
||||||
|
case aid do
|
||||||
|
0 -> # Start sneaking
|
||||||
|
:ok
|
||||||
|
1 -> # Stop sneaking
|
||||||
|
:ok
|
||||||
|
2 -> # Leave bed
|
||||||
|
:ok
|
||||||
|
3 -> # Start sprinting
|
||||||
|
:ok
|
||||||
|
4 -> # Stop sprinting
|
||||||
|
:ok
|
||||||
|
5 -> # Start horse jump
|
||||||
|
:ok
|
||||||
|
6 -> # Stop horse jump
|
||||||
|
:ok
|
||||||
|
7 -> # Open vehicle inventory
|
||||||
|
:ok
|
||||||
|
8 -> # Start elytra flying
|
||||||
|
:ok
|
||||||
|
_ -> raise RuntimeError, "Unknown Player Command Action ID"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def disconnect(reason) do
|
def disconnect(reason) do
|
||||||
%{
|
%{
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
defmodule GameCoordinatorTestGame do
|
defmodule GameCoordinatorTestGame do
|
||||||
@behaviour Amethyst.API.Game
|
@behaviour Amethyst.Game
|
||||||
|
|
||||||
@moduledoc """
|
@moduledoc """
|
||||||
This module is a sample game for the purpose of
|
This module is a sample game for the purpose of
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
defmodule Example.Game do
|
defmodule Example.Game do
|
||||||
require Logger
|
require Logger
|
||||||
@behaviour Amethyst.API.Game
|
@behaviour Amethyst.Game
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def instantiate(supervisor) do
|
def instantiate(supervisor) do
|
||||||
@ -40,7 +40,7 @@ defmodule Example.Game do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def chunk(from, {x, z}, _state_refs) do
|
def chunk(_from, {_x, _z}, _state_refs) do
|
||||||
# Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
|
# Logger.info("Player at #{inspect(from)} wants to know chunk #{x}, #{z}")
|
||||||
(0..255) |> Enum.map(fn y ->
|
(0..255) |> Enum.map(fn y ->
|
||||||
if y < 5 do
|
if y < 5 do
|
||||||
@ -49,7 +49,7 @@ defmodule Example.Game do
|
|||||||
end)
|
end)
|
||||||
else
|
else
|
||||||
(0..15) |> Enum.map(fn _z ->
|
(0..15) |> Enum.map(fn _z ->
|
||||||
(0..15) |> Enum.map(fn _x -> 0 end)
|
(0..15) |> Enum.map(fn _x -> 1 end)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user