diff options
author | Elisey Puzko <puzko.e02@gmail.com> | 2018-02-22 20:07:08 +0100 |
---|---|---|
committer | Elisey Puzko <puzko.e02@gmail.com> | 2018-02-22 20:07:08 +0100 |
commit | 228423d91518d0b8bd1c4bf047f3d378567e00f9 (patch) | |
tree | e05f4d5ddb11794bb4eb8691e8970d063599e669 /src | |
parent | New event: SelectedBlockChanged (diff) | |
download | AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar.gz AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar.bz2 AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar.lz AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar.xz AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.tar.zst AltCraft-228423d91518d0b8bd1c4bf047f3d378567e00f9.zip |
Diffstat (limited to 'src')
-rw-r--r-- | src/AssetManager.hpp | 2 | ||||
-rw-r--r-- | src/GameState.cpp | 8 | ||||
-rw-r--r-- | src/GameState.hpp | 1 | ||||
-rw-r--r-- | src/GlobalState.cpp | 4 | ||||
-rw-r--r-- | src/Packet.hpp | 910 | ||||
-rw-r--r-- | src/Render.cpp | 17 | ||||
-rw-r--r-- | src/RendererWorld.cpp | 2 |
7 files changed, 498 insertions, 446 deletions
diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 845c2b2..b828ee1 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -61,7 +61,7 @@ struct BlockModel { bool IsBlock = false; std::string BlockName; - bool AmbientOcclusion=true; + bool AmbientOcclusion = true; enum DisplayVariants { thirdperson_righthand, diff --git a/src/GameState.cpp b/src/GameState.cpp index 3166f1a..b963ef0 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -582,3 +582,11 @@ void GameState::CancelDigging() { auto packet = std::static_pointer_cast<Packet>(packetCancel); PUSH_EVENT("SendPacket", packet); } + +void GameState::PlaceBlock() { + auto packetPlace = std::make_shared<PacketPlayerBlockPlacement>( + selectedBlock, 1, 0, 0.0, 0.0, 0.0); + + auto packet = std::static_pointer_cast<Packet>(packetPlace); + PUSH_EVENT("SendPacket", packet); +}
\ No newline at end of file diff --git a/src/GameState.hpp b/src/GameState.hpp index 7183e64..81ab3dc 100644 --- a/src/GameState.hpp +++ b/src/GameState.hpp @@ -30,6 +30,7 @@ public: void StartDigging(); void FinishDigging(); void CancelDigging(); + void PlaceBlock(); void HandleMovement(GameState::Direction direction, float deltaTime); void HandleRotation(double yaw, double pitch); glm::mat4 GetViewMatrix(); diff --git a/src/GlobalState.cpp b/src/GlobalState.cpp index 73a34cb..8d75bac 100644 --- a/src/GlobalState.cpp +++ b/src/GlobalState.cpp @@ -163,6 +163,10 @@ void PhysExec() { gs->CancelDigging(); }); + listener.RegisterHandler("RmbPressed", [](const Event& eventData) { + gs->PlaceBlock(); + }); + listener.RegisterHandler("SelectedBlockChanged", [](const Event& eventData) { //TODO: //gs->CancelDigging(); diff --git a/src/Packet.hpp b/src/Packet.hpp index 1920ea6..7b18ce1 100644 --- a/src/Packet.hpp +++ b/src/Packet.hpp @@ -3,520 +3,520 @@ #include "Stream.hpp" enum PacketNameLoginSB { - LoginStart = 0x00, - EncryptionResponse = 0x01, + LoginStart = 0x00, + EncryptionResponse = 0x01, }; enum PacketNamePlaySB { - TeleportConfirm = 0x00, - TabCompleteSB, - ChatMessageSB, - ClientStatus, - ClientSettings, - ConfirmTransactionSB, - EnchantItem, - ClickWindow, - CloseWindowSB, - PluginMessageSB, - UseEntity, - KeepAliveSB, - Player, - PlayerPosition, - PlayerPositionAndLookSB, - PlayerLook, - VehicleMoveSB, - SteerBoat, + TeleportConfirm = 0x00, + TabCompleteSB, + ChatMessageSB, + ClientStatus, + ClientSettings, + ConfirmTransactionSB, + EnchantItem, + ClickWindow, + CloseWindowSB, + PluginMessageSB, + UseEntity, + KeepAliveSB, + Player, + PlayerPosition, + PlayerPositionAndLookSB, + PlayerLook, + VehicleMoveSB, + SteerBoat, CraftRecipeRequest, - PlayerAbilitiesSB, - PlayerDigging, - EntityAction, - SteerVehicle, - CraftingBookData, - ResourcePackStatus, - AdvancementTab, - HeldItemChangeSB, - CreativeInventoryAction, - UpdateSign, - AnimationSB, - Spectate, - PlayerBlockPlacement, - UseItem, + PlayerAbilitiesSB, + PlayerDigging, + EntityAction, + SteerVehicle, + CraftingBookData, + ResourcePackStatus, + AdvancementTab, + HeldItemChangeSB, + CreativeInventoryAction, + UpdateSign, + AnimationSB, + Spectate, + PlayerBlockPlacement, + UseItem, }; enum PacketNameHandshakingCB { - Handshake = 0x00, + Handshake = 0x00, }; enum PacketNameLoginCB { - Disconnect = 0x00, - EncryptionRequest = 0x01, - LoginSuccess = 0x02, - SetCompression = 0x03, + Disconnect = 0x00, + EncryptionRequest = 0x01, + LoginSuccess = 0x02, + SetCompression = 0x03, }; enum PacketNamePlayCB { - SpawnObject = 0x00, - SpawnExperienceOrb, - SpawnGlobalEntity, - SpawnMob, - SpawnPainting, - SpawnPlayer, - AnimationCB, - Statistics, - BlockBreakAnimation, - UpdateBlockEntity, - BlockAction, - BlockChange, - BossBar, - ServerDifficulty, - TabCompleteCB, - ChatMessageCB, - MultiBlockChange, - ConfirmTransactionCB, - CloseWindowCB, - OpenWindow, - WindowItems, - WindowProperty, - SetSlot, - SetCooldown, - PluginMessageCB, - NamedSoundEffect, - DisconnectPlay, - EntityStatus, - Explosion, - UnloadChunk, - ChangeGameState, - KeepAliveCB, - ChunkData, - Effect, - Particle, - JoinGame, - Map, - EntityRelativeMove, - EntityLookAndRelativeMove, - EntityLook, - EntityCB, - VehicleMove, - OpenSignEditor, + SpawnObject = 0x00, + SpawnExperienceOrb, + SpawnGlobalEntity, + SpawnMob, + SpawnPainting, + SpawnPlayer, + AnimationCB, + Statistics, + BlockBreakAnimation, + UpdateBlockEntity, + BlockAction, + BlockChange, + BossBar, + ServerDifficulty, + TabCompleteCB, + ChatMessageCB, + MultiBlockChange, + ConfirmTransactionCB, + CloseWindowCB, + OpenWindow, + WindowItems, + WindowProperty, + SetSlot, + SetCooldown, + PluginMessageCB, + NamedSoundEffect, + DisconnectPlay, + EntityStatus, + Explosion, + UnloadChunk, + ChangeGameState, + KeepAliveCB, + ChunkData, + Effect, + Particle, + JoinGame, + Map, + EntityRelativeMove, + EntityLookAndRelativeMove, + EntityLook, + EntityCB, + VehicleMove, + OpenSignEditor, CraftRecipeResponse, - PlayerAbilitiesCB, - CombatEvent, - PlayerListItem, - PlayerPositionAndLookCB, - UseBed, - UnlockRecipes, - DestroyEntities, - RemoveEntityEffect, - ResourcePackSend, - Respawn, - EntityHeadLook, - SelectAdvancementTab, - WorldBorder, - Camera, - HeldItemChangeCB, - DisplayScoreboard, - EntityMetadata, - AttachEntity, - EntityVelocity, - EntityEquipment, - SetExperience, - UpdateHealth, - ScoreboardObjective, - SetPassengers, - Teams, - UpdateScore, - SpawnPosition, - TimeUpdate, - Title, - SoundEffect, - PlayerListHeaderAndFooter, - CollectItem, - EntityTeleport, - Advancements, - EntityProperties, - EntityEffect, + PlayerAbilitiesCB, + CombatEvent, + PlayerListItem, + PlayerPositionAndLookCB, + UseBed, + UnlockRecipes, + DestroyEntities, + RemoveEntityEffect, + ResourcePackSend, + Respawn, + EntityHeadLook, + SelectAdvancementTab, + WorldBorder, + Camera, + HeldItemChangeCB, + DisplayScoreboard, + EntityMetadata, + AttachEntity, + EntityVelocity, + EntityEquipment, + SetExperience, + UpdateHealth, + ScoreboardObjective, + SetPassengers, + Teams, + UpdateScore, + SpawnPosition, + TimeUpdate, + Title, + SoundEffect, + PlayerListHeaderAndFooter, + CollectItem, + EntityTeleport, + Advancements, + EntityProperties, + EntityEffect, }; struct Packet { - virtual ~Packet() = default; - virtual void ToStream(StreamOutput *stream) = 0; - virtual void FromStream(StreamInput *stream) = 0; - virtual int GetPacketId() = 0; + virtual ~Packet() = default; + virtual void ToStream(StreamOutput *stream) = 0; + virtual void FromStream(StreamInput *stream) = 0; + virtual int GetPacketId() = 0; }; struct PacketHandshake : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteVarInt(protocolVersion); - stream->WriteString(serverAddress); - stream->WriteUShort(serverPort); - stream->WriteVarInt(nextState); - } - - void FromStream(StreamInput *stream) override { - protocolVersion = stream->ReadVarInt(); - serverAddress = stream->ReadString(); - serverPort = stream->ReadUShort(); - nextState = stream->ReadVarInt(); - } - - int GetPacketId() override { - return PacketNameHandshakingCB::Handshake; - } - - int protocolVersion; - std::string serverAddress; - unsigned short serverPort; - int nextState; + void ToStream(StreamOutput *stream) override { + stream->WriteVarInt(protocolVersion); + stream->WriteString(serverAddress); + stream->WriteUShort(serverPort); + stream->WriteVarInt(nextState); + } + + void FromStream(StreamInput *stream) override { + protocolVersion = stream->ReadVarInt(); + serverAddress = stream->ReadString(); + serverPort = stream->ReadUShort(); + nextState = stream->ReadVarInt(); + } + + int GetPacketId() override { + return PacketNameHandshakingCB::Handshake; + } + + int protocolVersion; + std::string serverAddress; + unsigned short serverPort; + int nextState; }; struct PacketLoginStart : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteString(Username); - } + void ToStream(StreamOutput *stream) override { + stream->WriteString(Username); + } - void FromStream(StreamInput *stream) override { - Username = stream->ReadString(); - } + void FromStream(StreamInput *stream) override { + Username = stream->ReadString(); + } - int GetPacketId() override { - return PacketNameLoginSB::LoginStart; - } + int GetPacketId() override { + return PacketNameLoginSB::LoginStart; + } - std::string Username; + std::string Username; }; struct PacketLoginSuccess : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteString(Uuid); - stream->WriteString(Username); - } - - void FromStream(StreamInput *stream) override { - Uuid = stream->ReadString(); - Username = stream->ReadString(); - } - - int GetPacketId() override { - return PacketNameLoginCB::LoginSuccess; - } - - std::string Uuid; - std::string Username; + void ToStream(StreamOutput *stream) override { + stream->WriteString(Uuid); + stream->WriteString(Username); + } + + void FromStream(StreamInput *stream) override { + Uuid = stream->ReadString(); + Username = stream->ReadString(); + } + + int GetPacketId() override { + return PacketNameLoginCB::LoginSuccess; + } + + std::string Uuid; + std::string Username; }; struct PacketJoinGame : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteInt(EntityId); - stream->WriteUByte(Gamemode); - stream->WriteInt(Dimension); - stream->WriteUByte(Difficulty); - stream->WriteUByte(MaxPlayers); - stream->WriteString(LevelType); - stream->WriteBool(ReducedDebugInfo); - } - - void FromStream(StreamInput *stream) override { - EntityId = stream->ReadInt(); - Gamemode = stream->ReadUByte(); - Dimension = stream->ReadInt(); - Difficulty = stream->ReadUByte(); - MaxPlayers = stream->ReadUByte(); - LevelType = stream->ReadString(); - ReducedDebugInfo = stream->ReadBool(); - } - - int GetPacketId() override { - return PacketNamePlayCB::JoinGame; - } - - int EntityId; - unsigned char Gamemode; - int Dimension; - unsigned char Difficulty; - unsigned char MaxPlayers; - std::string LevelType; - bool ReducedDebugInfo; + void ToStream(StreamOutput *stream) override { + stream->WriteInt(EntityId); + stream->WriteUByte(Gamemode); + stream->WriteInt(Dimension); + stream->WriteUByte(Difficulty); + stream->WriteUByte(MaxPlayers); + stream->WriteString(LevelType); + stream->WriteBool(ReducedDebugInfo); + } + + void FromStream(StreamInput *stream) override { + EntityId = stream->ReadInt(); + Gamemode = stream->ReadUByte(); + Dimension = stream->ReadInt(); + Difficulty = stream->ReadUByte(); + MaxPlayers = stream->ReadUByte(); + LevelType = stream->ReadString(); + ReducedDebugInfo = stream->ReadBool(); + } + + int GetPacketId() override { + return PacketNamePlayCB::JoinGame; + } + + int EntityId; + unsigned char Gamemode; + int Dimension; + unsigned char Difficulty; + unsigned char MaxPlayers; + std::string LevelType; + bool ReducedDebugInfo; }; struct PacketDisconnectPlay : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteString(Reason); //TODO: Implement chat-wrapper - } + void ToStream(StreamOutput *stream) override { + stream->WriteString(Reason); //TODO: Implement chat-wrapper + } - void FromStream(StreamInput *stream) override { - Reason = stream->ReadChat().text; - } + void FromStream(StreamInput *stream) override { + Reason = stream->ReadChat().text; + } - int GetPacketId() override { - return PacketNamePlayCB::DisconnectPlay; - } + int GetPacketId() override { + return PacketNamePlayCB::DisconnectPlay; + } - std::string Reason; + std::string Reason; }; struct PacketSpawnPosition : Packet { - void ToStream(StreamOutput *stream) override { - stream->WritePosition(Location); - } + void ToStream(StreamOutput *stream) override { + stream->WritePosition(Location); + } - void FromStream(StreamInput *stream) override { - Location = stream->ReadPosition(); - } + void FromStream(StreamInput *stream) override { + Location = stream->ReadPosition(); + } - int GetPacketId() override { - return PacketNamePlayCB::SpawnPosition; - } + int GetPacketId() override { + return PacketNamePlayCB::SpawnPosition; + } - Vector Location; + Vector Location; }; struct PacketKeepAliveCB : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteLong(KeepAliveId); - } + void ToStream(StreamOutput *stream) override { + stream->WriteLong(KeepAliveId); + } - void FromStream(StreamInput *stream) override { - KeepAliveId = stream->ReadLong(); - } + void FromStream(StreamInput *stream) override { + KeepAliveId = stream->ReadLong(); + } - int GetPacketId() override { - return PacketNamePlayCB::KeepAliveCB; - } + int GetPacketId() override { + return PacketNamePlayCB::KeepAliveCB; + } - long long KeepAliveId; + long long KeepAliveId; }; struct PacketKeepAliveSB : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteLong(KeepAliveId); - } + void ToStream(StreamOutput *stream) override { + stream->WriteLong(KeepAliveId); + } - void FromStream(StreamInput *stream) override { - KeepAliveId = stream->ReadLong(); - } + void FromStream(StreamInput *stream) override { + KeepAliveId = stream->ReadLong(); + } - int GetPacketId() override { - return PacketNamePlaySB::KeepAliveSB; - } + int GetPacketId() override { + return PacketNamePlaySB::KeepAliveSB; + } - long long KeepAliveId; + long long KeepAliveId; - PacketKeepAliveSB(int KeepAliveId) : KeepAliveId(KeepAliveId) {} + PacketKeepAliveSB(int KeepAliveId) : KeepAliveId(KeepAliveId) {} }; struct PacketPlayerPositionAndLookCB : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteDouble(X); - stream->WriteDouble(Y); - stream->WriteDouble(Z); - stream->WriteFloat(Yaw); - stream->WriteFloat(Pitch); - stream->WriteUByte(Flags); - stream->WriteVarInt(TeleportId); - } - - void FromStream(StreamInput *stream) override { - X = stream->ReadDouble(); - Y = stream->ReadDouble(); - Z = stream->ReadDouble(); - Yaw = stream->ReadFloat(); - Pitch = stream->ReadFloat(); - Flags = stream->ReadUByte(); - TeleportId = stream->ReadVarInt(); - } - - int GetPacketId() override { - return PacketNamePlayCB::PlayerPositionAndLookCB; - } - - double X; - double Y; - double Z; - float Yaw; - float Pitch; - unsigned char Flags; - int TeleportId; + void ToStream(StreamOutput *stream) override { + stream->WriteDouble(X); + stream->WriteDouble(Y); + stream->WriteDouble(Z); + stream->WriteFloat(Yaw); + stream->WriteFloat(Pitch); + stream->WriteUByte(Flags); + stream->WriteVarInt(TeleportId); + } + + void FromStream(StreamInput *stream) override { + X = stream->ReadDouble(); + Y = stream->ReadDouble(); + Z = stream->ReadDouble(); + Yaw = stream->ReadFloat(); + Pitch = stream->ReadFloat(); + Flags = stream->ReadUByte(); + TeleportId = stream->ReadVarInt(); + } + + int GetPacketId() override { + return PacketNamePlayCB::PlayerPositionAndLookCB; + } + + double X; + double Y; + double Z; + float Yaw; + float Pitch; + unsigned char Flags; + int TeleportId; }; struct PacketTeleportConfirm : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteVarInt(TeleportId); - } + void ToStream(StreamOutput *stream) override { + stream->WriteVarInt(TeleportId); + } - void FromStream(StreamInput *stream) override { - TeleportId = stream->ReadVarInt(); - } + void FromStream(StreamInput *stream) override { + TeleportId = stream->ReadVarInt(); + } - int GetPacketId() override { - return PacketNamePlaySB::TeleportConfirm; - } + int GetPacketId() override { + return PacketNamePlaySB::TeleportConfirm; + } - int TeleportId; + int TeleportId; - PacketTeleportConfirm(int TeleportId) : TeleportId(TeleportId) {} + PacketTeleportConfirm(int TeleportId) : TeleportId(TeleportId) {} }; struct PacketClientStatus : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteVarInt(ActionId); - } + void ToStream(StreamOutput *stream) override { + stream->WriteVarInt(ActionId); + } - void FromStream(StreamInput *stream) override { - ActionId = stream->ReadVarInt(); - } + void FromStream(StreamInput *stream) override { + ActionId = stream->ReadVarInt(); + } - int GetPacketId() override { - return PacketNamePlaySB::ClientStatus; - } + int GetPacketId() override { + return PacketNamePlaySB::ClientStatus; + } - int ActionId; + int ActionId; - PacketClientStatus(int ActionId) : ActionId(ActionId) {} + PacketClientStatus(int ActionId) : ActionId(ActionId) {} }; struct PacketPlayerPositionAndLookSB : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteDouble(X); - stream->WriteDouble(FeetY); - stream->WriteDouble(Z); - stream->WriteFloat(Yaw); - stream->WriteFloat(Pitch); - stream->WriteBool(OnGround); - } - - void FromStream(StreamInput *stream) override { - X = stream->ReadDouble(); - FeetY = stream->ReadDouble(); - Z = stream->ReadDouble(); - Yaw = stream->ReadFloat(); - Pitch = stream->ReadFloat(); - OnGround = stream->ReadBool(); - } - - int GetPacketId() override { - return PacketNamePlaySB::PlayerPositionAndLookSB; - } - - - double X; - double FeetY; - double Z; - float Yaw; - float Pitch; - bool OnGround; - - PacketPlayerPositionAndLookSB(double X, double FeetY, double Z, - float Yaw, float Pitch, bool OnGround) : X(X), FeetY(FeetY), Z(Z), Yaw(Yaw), - Pitch(Pitch), OnGround(OnGround) {} + void ToStream(StreamOutput *stream) override { + stream->WriteDouble(X); + stream->WriteDouble(FeetY); + stream->WriteDouble(Z); + stream->WriteFloat(Yaw); + stream->WriteFloat(Pitch); + stream->WriteBool(OnGround); + } + + void FromStream(StreamInput *stream) override { + X = stream->ReadDouble(); + FeetY = stream->ReadDouble(); + Z = stream->ReadDouble(); + Yaw = stream->ReadFloat(); + Pitch = stream->ReadFloat(); + OnGround = stream->ReadBool(); + } + + int GetPacketId() override { + return PacketNamePlaySB::PlayerPositionAndLookSB; + } + + + double X; + double FeetY; + double Z; + float Yaw; + float Pitch; + bool OnGround; + + PacketPlayerPositionAndLookSB(double X, double FeetY, double Z, + float Yaw, float Pitch, bool OnGround) : X(X), FeetY(FeetY), Z(Z), Yaw(Yaw), + Pitch(Pitch), OnGround(OnGround) {} }; struct PacketChunkData : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteInt(ChunkX); - stream->WriteInt(ChunkZ); - stream->WriteBool(GroundUpContinuous); - stream->WriteInt(PrimaryBitMask); - stream->WriteVarInt(Data.size()); - stream->WriteByteArray(Data); - stream->WriteVarInt(BlockEntities.size()); - //LOG(FATAL) << "Serializing unimplemented packet"; - } - - void FromStream(StreamInput *stream) override { - ChunkX = stream->ReadInt(); - ChunkZ = stream->ReadInt(); - GroundUpContinuous = stream->ReadBool(); - PrimaryBitMask = stream->ReadVarInt(); - int Size = stream->ReadVarInt(); - Data = stream->ReadByteArray(Size); - int NumberOfBlockEntities = stream->ReadVarInt(); //TODO: Need NBT - for (int i = 0; i < NumberOfBlockEntities; i++) { - //BlockEntities[i] = stream->ReadNbt(); - } - } - - int GetPacketId() override { - return PacketNamePlayCB::ChunkData; - } - - int ChunkX; - int ChunkZ; - bool GroundUpContinuous; - int PrimaryBitMask; - //int Size; - std::vector<unsigned char> Data; - //int NumberOfBlockEntities; - std::vector<int> BlockEntities; //TODO: Replace int with NbtTag and implement NbtTree + void ToStream(StreamOutput *stream) override { + stream->WriteInt(ChunkX); + stream->WriteInt(ChunkZ); + stream->WriteBool(GroundUpContinuous); + stream->WriteInt(PrimaryBitMask); + stream->WriteVarInt(Data.size()); + stream->WriteByteArray(Data); + stream->WriteVarInt(BlockEntities.size()); + //LOG(FATAL) << "Serializing unimplemented packet"; + } + + void FromStream(StreamInput *stream) override { + ChunkX = stream->ReadInt(); + ChunkZ = stream->ReadInt(); + GroundUpContinuous = stream->ReadBool(); + PrimaryBitMask = stream->ReadVarInt(); + int Size = stream->ReadVarInt(); + Data = stream->ReadByteArray(Size); + int NumberOfBlockEntities = stream->ReadVarInt(); //TODO: Need NBT + for (int i = 0; i < NumberOfBlockEntities; i++) { + //BlockEntities[i] = stream->ReadNbt(); + } + } + + int GetPacketId() override { + return PacketNamePlayCB::ChunkData; + } + + int ChunkX; + int ChunkZ; + bool GroundUpContinuous; + int PrimaryBitMask; + //int Size; + std::vector<unsigned char> Data; + //int NumberOfBlockEntities; + std::vector<int> BlockEntities; //TODO: Replace int with NbtTag and implement NbtTree }; struct PacketPlayerPosition : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteDouble(X); - stream->WriteDouble(FeetY); - stream->WriteDouble(Z); - stream->WriteBool(OnGround); - } - - void FromStream(StreamInput *stream) override { - X = stream->ReadDouble(); - FeetY = stream->ReadDouble(); - Z = stream->ReadDouble(); - OnGround = stream->ReadBool(); - } - - int GetPacketId() override { - return PacketNamePlaySB::PlayerPosition; - } - - double X; - double FeetY; - double Z; - bool OnGround; - - PacketPlayerPosition(double X, double Y, double Z, bool ground) : X(X), FeetY(Y), Z(Z), OnGround(ground) {} + void ToStream(StreamOutput *stream) override { + stream->WriteDouble(X); + stream->WriteDouble(FeetY); + stream->WriteDouble(Z); + stream->WriteBool(OnGround); + } + + void FromStream(StreamInput *stream) override { + X = stream->ReadDouble(); + FeetY = stream->ReadDouble(); + Z = stream->ReadDouble(); + OnGround = stream->ReadBool(); + } + + int GetPacketId() override { + return PacketNamePlaySB::PlayerPosition; + } + + double X; + double FeetY; + double Z; + bool OnGround; + + PacketPlayerPosition(double X, double Y, double Z, bool ground) : X(X), FeetY(Y), Z(Z), OnGround(ground) {} }; struct PacketPlayerLook : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteFloat(Yaw); - stream->WriteFloat(Pitch); - stream->WriteBool(OnGround); - } - - void FromStream(StreamInput *stream) override { - Yaw = stream->ReadFloat(); - Pitch = stream->ReadFloat(); - OnGround = stream->ReadBool(); - } - - int GetPacketId() override { - return PacketNamePlaySB::PlayerLook; - } - - float Yaw; - float Pitch; - bool OnGround; - - PacketPlayerLook(float Yaw, float Pitch, bool ground) : Yaw(Yaw), Pitch(Pitch), OnGround(ground) {} + void ToStream(StreamOutput *stream) override { + stream->WriteFloat(Yaw); + stream->WriteFloat(Pitch); + stream->WriteBool(OnGround); + } + + void FromStream(StreamInput *stream) override { + Yaw = stream->ReadFloat(); + Pitch = stream->ReadFloat(); + OnGround = stream->ReadBool(); + } + + int GetPacketId() override { + return PacketNamePlaySB::PlayerLook; + } + + float Yaw; + float Pitch; + bool OnGround; + + PacketPlayerLook(float Yaw, float Pitch, bool ground) : Yaw(Yaw), Pitch(Pitch), OnGround(ground) {} }; struct PacketUpdateHealth : Packet { - void ToStream(StreamOutput *stream) override { - stream->WriteFloat(Health); - stream->WriteVarInt(Food); - stream->WriteFloat(FoodSaturation); - } - - void FromStream(StreamInput *stream) override { - Health = stream->ReadFloat(); - Food = stream->ReadVarInt(); - FoodSaturation = stream->ReadFloat(); - } - - int GetPacketId() override { - return PacketNamePlayCB::UpdateHealth; - } - - float Health; - int Food; - float FoodSaturation; + void ToStream(StreamOutput *stream) override { + stream->WriteFloat(Health); + stream->WriteVarInt(Food); + stream->WriteFloat(FoodSaturation); + } + + void FromStream(StreamInput *stream) override { + Health = stream->ReadFloat(); + Food = stream->ReadVarInt(); + FoodSaturation = stream->ReadFloat(); + } + + int GetPacketId() override { + return PacketNamePlayCB::UpdateHealth; + } + + float Health; + int Food; + float FoodSaturation; }; struct PacketSpawnObject : Packet { @@ -1095,23 +1095,55 @@ struct PacketChatMessageSB : Packet { }; struct PacketPlayerDigging : Packet { - void ToStream(StreamOutput *stream) override { + void ToStream(StreamOutput *stream) override { stream->WriteVarInt(Status); stream->WritePosition(Location); stream->WriteByte(Face); - } + } - void FromStream(StreamInput *stream) override { + void FromStream(StreamInput *stream) override { - } + } - int GetPacketId() override { - return PacketNamePlaySB::PlayerDigging; - } + int GetPacketId() override { + return PacketNamePlaySB::PlayerDigging; + } + + int Status; + Vector Location; + signed char Face; + + PacketPlayerDigging(int status, const Vector& location, signed char face) : Status(status),Location(location),Face(face) {}; +}; + +struct PacketPlayerBlockPlacement : Packet { + void ToStream(StreamOutput *stream) override { + stream->WritePosition(location); + stream->WriteByte(face); + stream->WriteByte(hand); + stream->WriteFloat(cursorPositionX); + stream->WriteFloat(cursorPositionY); + stream->WriteFloat(cursorPositionZ); + } + + void FromStream(StreamInput *stream) override { + + } + + int GetPacketId() override { + return PacketNamePlaySB::PlayerBlockPlacement; + } - int Status; - Vector Location; - signed char Face; + PacketPlayerBlockPlacement( + const Vector& location, signed char face, unsigned char hand, + float cursorPositionX, float cursorPositionY, float cursorPositionZ) + : location(location), face(face), hand(hand), cursorPositionX(cursorPositionX), + cursorPositionY(cursorPositionY), cursorPositionZ(cursorPositionZ) {}; - PacketPlayerDigging(int status, const Vector& location, signed char face) : Status(status),Location(location),Face(face) {}; + Vector location; + signed char face; + unsigned char hand; + float cursorPositionX; + float cursorPositionY; + float cursorPositionZ; };
\ No newline at end of file diff --git a/src/Render.cpp b/src/Render.cpp index c5c295d..cb05f65 100644 --- a/src/Render.cpp +++ b/src/Render.cpp @@ -244,16 +244,23 @@ void Render::HandleEvents() { } case SDL_MOUSEBUTTONDOWN: { - if (event.button.button == SDL_BUTTON_LEFT && !ImGui::GetIO().WantCaptureMouse) - PUSH_EVENT("LmbPressed", 0); + if (!ImGui::GetIO().WantCaptureMouse) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbPressed", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbPressed", 0); + } break; } case SDL_MOUSEBUTTONUP: { - if (event.button.button == SDL_BUTTON_LEFT && !ImGui::GetIO().WantCaptureMouse) - PUSH_EVENT("LmbReleased", 0); - + if (!ImGui::GetIO().WantCaptureMouse) { + if (event.button.button == SDL_BUTTON_LEFT) + PUSH_EVENT("LmbReleased", 0); + else if (event.button.button == SDL_BUTTON_RIGHT) + PUSH_EVENT("RmbReleased", 0); + } break; } diff --git a/src/RendererWorld.cpp b/src/RendererWorld.cpp index 5065f9d..16f7950 100644 --- a/src/RendererWorld.cpp +++ b/src/RendererWorld.cpp @@ -212,7 +212,7 @@ RendererWorld::~RendererWorld() { faces += it.second.numOfFaces; } sectionsMutex.unlock(); - LOG(INFO) << "Total faces to render: "<<faces; + LOG(INFO) << "Total faces to render: " << faces; isRunning = false; for (int i = 0; i < numOfWorkers; i++) workers[i].join(); |