Botcraft 1.21.4
Loading...
Searching...
No Matches
ManagersClient.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <atomic>
4#include <map>
5#include <shared_mutex>
6#include <thread>
7
10
11namespace Botcraft
12{
13 class World;
14 class InventoryManager;
15 class EntityManager;
16 class LocalPlayer;
17 class PhysicsManager;
18
19#if USE_GUI
20 namespace Renderer
21 {
22 class RenderingManager;
23 }
24#endif
25
26 /// @brief A client containing the different managers,
27 /// and performing client-side physics.
28 /// Can be inherited if you want to handle other packets
29 /// without a need of any behaviour tree stuff.
31 {
32 public:
33 ManagersClient(const bool use_renderer_);
34 virtual ~ManagersClient();
35
36 virtual void Disconnect() override;
37
38 void SetSharedWorld(const std::shared_ptr<World> world_);
39
40 bool GetAutoRespawn() const;
41 void SetAutoRespawn(const bool b);
42
43 // Set the right transaction id, add it to the inventory manager,
44 // update the next transaction id and send it to the server
45 // return the id of the transaction
46 int SendInventoryTransaction(const std::shared_ptr<ProtocolCraft::ServerboundContainerClickPacket>& transaction);
47
48 std::shared_ptr<World> GetWorld() const;
49 std::shared_ptr<EntityManager> GetEntityManager() const;
50 std::shared_ptr<LocalPlayer> GetLocalPlayer() const;
51 std::shared_ptr<InventoryManager> GetInventoryManager() const;
52 std::shared_ptr<PhysicsManager> GetPhysicsManager() const;
53
54 /// @brief Get the name of a connected player
55 /// @param uuid UUID of the player
56 /// @return The name, or empty string if not present
57 std::string GetPlayerName(const ProtocolCraft::UUID& uuid) const;
58
59
60 /// @brief Get the current tick
61 /// @return An int representing the time of day
62 int GetDayTime() const;
63
64 protected:
65 using ConnectionClient::Handle; // Don't hide all Handle() functions from base classes
66#if PROTOCOL_VERSION < 768 /* < 1.21.2 */
67 virtual void Handle(ProtocolCraft::ClientboundGameProfilePacket& msg) override;
68#else
69 virtual void Handle(ProtocolCraft::ClientboundLoginFinishedPacket& msg) override;
70#endif
72 virtual void Handle(ProtocolCraft::ClientboundLoginPacket& msg) override;
73 virtual void Handle(ProtocolCraft::ClientboundSetHealthPacket& msg) override;
76 virtual void Handle(ProtocolCraft::ClientboundRespawnPacket& msg) override;
77 virtual void Handle(ProtocolCraft::ClientboundSetTimePacket& msg) override;
78#if PROTOCOL_VERSION < 761 /* < 1.19.3 */
79 virtual void Handle(ProtocolCraft::ClientboundPlayerInfoPacket& msg) override;
80#else
83#endif
84
85 protected:
86 std::shared_ptr<World> world;
87 std::shared_ptr<EntityManager> entity_manager;
88 std::shared_ptr<InventoryManager> inventory_manager;
89 std::shared_ptr<PhysicsManager> physics_manager;
90#if USE_GUI
91 // If true, opens a window to display the view
92 // from the bot. Only one renderer can be active
93 // at the same time
95 std::shared_ptr<Renderer::RenderingManager> rendering_manager;
96#endif
97
99
101#if PROTOCOL_VERSION > 463 /* > 1.13.2 */
103#endif
105 std::atomic<int> day_time;
106
107 /// @brief Names of all connected players
108 std::map<ProtocolCraft::UUID, std::string> player_names;
109 mutable std::shared_mutex player_names_mutex;
110 };
111} //Botcraft
The base client handling connection with a server.
virtual void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &msg) override
A client containing the different managers, and performing client-side physics.
std::atomic< int > day_time
std::map< ProtocolCraft::UUID, std::string > player_names
Names of all connected players.
std::shared_ptr< EntityManager > GetEntityManager() const
virtual void Handle(ProtocolCraft::ClientboundLoginFinishedPacket &msg) override
std::shared_ptr< PhysicsManager > GetPhysicsManager() const
void SetSharedWorld(const std::shared_ptr< World > world_)
std::shared_ptr< Renderer::RenderingManager > rendering_manager
std::shared_ptr< LocalPlayer > GetLocalPlayer() const
void SetAutoRespawn(const bool b)
std::shared_ptr< InventoryManager > GetInventoryManager() const
virtual void Disconnect() override
std::shared_ptr< PhysicsManager > physics_manager
std::shared_ptr< InventoryManager > inventory_manager
std::shared_ptr< EntityManager > entity_manager
int SendInventoryTransaction(const std::shared_ptr< ProtocolCraft::ServerboundContainerClickPacket > &transaction)
std::shared_mutex player_names_mutex
std::shared_ptr< World > world
int GetDayTime() const
Get the current tick.
std::string GetPlayerName(const ProtocolCraft::UUID &uuid) const
Get the name of a connected player.
std::shared_ptr< World > GetWorld() const
std::array< unsigned char, 16 > UUID