[ClientPlayer] Now sending PlayerChunkPosUpdate.
This commit is contained in:
parent
6f97f53416
commit
5bdacba397
@ -274,6 +274,14 @@ Packet sent from a client when it is ready to receive chunks.
|
|||||||
|
|
||||||
_This packet has no field._
|
_This packet has no field._
|
||||||
|
|
||||||
|
#### PlayerChunkPosUpdate
|
||||||
|
|
||||||
|
| Field name | Field type | Notes |
|
||||||
|
| ------------- | ----------- | ---------------------------------------------------- |
|
||||||
|
| Chunk X | s32 | Chunk X coordinate |
|
||||||
|
| Chunk Y | s32 | Chunk Y coordinate |
|
||||||
|
| Chunk Z | s32 | Chunk Z coordinate |
|
||||||
|
|
||||||
#### BlockActivated
|
#### BlockActivated
|
||||||
|
|
||||||
| Field name | Field type | Notes |
|
| Field name | Field type | Notes |
|
||||||
|
@ -97,6 +97,14 @@ void ClientCommandHandler::sendPlayerReady() {
|
|||||||
m_client.send(packet);
|
m_client.send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ClientCommandHandler::sendPlayerChunkPosUpdate() const {
|
||||||
|
Network::Packet packet;
|
||||||
|
const gk::Vector3i &chunkPos = m_player.getCurrentChunk();
|
||||||
|
packet << Network::Command::PlayerChunkPosUpdate
|
||||||
|
<< s32(chunkPos.x) << s32(chunkPos.y) << s32(chunkPos.z);
|
||||||
|
m_client.send(packet);
|
||||||
|
}
|
||||||
|
|
||||||
void ClientCommandHandler::sendBlockActivated(const glm::ivec4 &selectedBlock) {
|
void ClientCommandHandler::sendBlockActivated(const glm::ivec4 &selectedBlock) {
|
||||||
Network::Packet packet;
|
Network::Packet packet;
|
||||||
packet << Network::Command::BlockActivated
|
packet << Network::Command::BlockActivated
|
||||||
|
@ -53,6 +53,7 @@ class ClientCommandHandler {
|
|||||||
void sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block);
|
void sendPlayerPlaceBlock(s32 x, s32 y, s32 z, u32 block);
|
||||||
void sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID);
|
void sendPlayerHeldItemChanged(u8 hotbarSlot, u16 itemID);
|
||||||
void sendPlayerReady();
|
void sendPlayerReady();
|
||||||
|
void sendPlayerChunkPosUpdate() const;
|
||||||
void sendBlockActivated(const glm::ivec4 &selectedBlock);
|
void sendBlockActivated(const glm::ivec4 &selectedBlock);
|
||||||
void sendBlockInvUpdate(Inventory &inventory);
|
void sendBlockInvUpdate(Inventory &inventory);
|
||||||
void sendItemActivated(const glm::ivec4 &selectedBlock);
|
void sendItemActivated(const glm::ivec4 &selectedBlock);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <gk/core/input/GamePad.hpp>
|
#include <gk/core/input/GamePad.hpp>
|
||||||
#include <gk/core/Mouse.hpp>
|
#include <gk/core/Mouse.hpp>
|
||||||
|
|
||||||
|
#include "ClientCommandHandler.hpp"
|
||||||
#include "ClientPlayer.hpp"
|
#include "ClientPlayer.hpp"
|
||||||
#include "ClientWorld.hpp"
|
#include "ClientWorld.hpp"
|
||||||
#include "GameConfig.hpp"
|
#include "GameConfig.hpp"
|
||||||
@ -153,6 +154,12 @@ void ClientPlayer::updatePosition(const ClientWorld &world) {
|
|||||||
else {
|
else {
|
||||||
GameConfig::currentScreenEffect = 0;
|
GameConfig::currentScreenEffect = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sending PlayerChunkPosUpdate if needed
|
||||||
|
if (!m_lastChunkPos.has_value() || m_lastChunkPos.value() != getCurrentChunk()) {
|
||||||
|
world.client().sendPlayerChunkPosUpdate();
|
||||||
|
m_lastChunkPos = getCurrentChunk();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientPlayer::setPosition(double x, double y, double z) {
|
void ClientPlayer::setPosition(double x, double y, double z) {
|
||||||
|
@ -88,6 +88,8 @@ class ClientPlayer : public Player {
|
|||||||
bool m_isJumping = false;
|
bool m_isJumping = false;
|
||||||
|
|
||||||
const float m_jumpSpeed = 0.06f;
|
const float m_jumpSpeed = 0.06f;
|
||||||
|
|
||||||
|
std::optional<gk::Vector3i> m_lastChunkPos;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLIENTPLAYER_HPP_
|
#endif // CLIENTPLAYER_HPP_
|
||||||
|
@ -65,6 +65,8 @@ class ClientWorld : public World, public gk::Drawable {
|
|||||||
const ClientScene &scene() const { return m_scene; }
|
const ClientScene &scene() const { return m_scene; }
|
||||||
ClientScene &scene() { return m_scene; }
|
ClientScene &scene() { return m_scene; }
|
||||||
|
|
||||||
|
const ClientCommandHandler &client() const { return *m_client; }
|
||||||
|
|
||||||
void setClient(ClientCommandHandler &client) { m_client = &client; }
|
void setClient(ClientCommandHandler &client) { m_client = &client; }
|
||||||
void setCamera(gk::Camera &camera) { m_camera = &camera; m_scene.setCamera(camera); }
|
void setCamera(gk::Camera &camera) { m_camera = &camera; m_scene.setCamera(camera); }
|
||||||
void setEventHandler(gk::EventHandler &eventHandler) { m_eventHandler = &eventHandler; }
|
void setEventHandler(gk::EventHandler &eventHandler) { m_eventHandler = &eventHandler; }
|
||||||
|
@ -52,6 +52,7 @@ std::string Network::commandToString(Network::Command command) {
|
|||||||
{Network::Command::PlayerChangeDimension, "PlayerChangeDimension"},
|
{Network::Command::PlayerChangeDimension, "PlayerChangeDimension"},
|
||||||
{Network::Command::PlayerHeldItemChanged, "PlayerHeldItemChanged"},
|
{Network::Command::PlayerHeldItemChanged, "PlayerHeldItemChanged"},
|
||||||
{Network::Command::PlayerReady, "PlayerReady"},
|
{Network::Command::PlayerReady, "PlayerReady"},
|
||||||
|
{Network::Command::PlayerChunkPosUpdate, "PlayerChunkPosUpdate"},
|
||||||
|
|
||||||
{Network::Command::BlockUpdate, "BlockUpdate"},
|
{Network::Command::BlockUpdate, "BlockUpdate"},
|
||||||
{Network::Command::BlockActivated, "BlockActivated"},
|
{Network::Command::BlockActivated, "BlockActivated"},
|
||||||
|
@ -55,6 +55,7 @@ namespace Network {
|
|||||||
PlayerChangeDimension = 0x36,
|
PlayerChangeDimension = 0x36,
|
||||||
PlayerHeldItemChanged = 0x37,
|
PlayerHeldItemChanged = 0x37,
|
||||||
PlayerReady = 0x38,
|
PlayerReady = 0x38,
|
||||||
|
PlayerChunkPosUpdate = 0x39,
|
||||||
|
|
||||||
BlockUpdate = 0x40,
|
BlockUpdate = 0x40,
|
||||||
BlockActivated = 0x41,
|
BlockActivated = 0x41,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user