#pragma once #include #include #include "botcraft/AI/TemplatedBehaviourClient.hpp" namespace Bilicraft { // CRTP keeps future behaviour-tree leaves typed as BilicraftClient, with access // to its custom fields as well as Botcraft's world/inventory/physics managers. class BilicraftClient : public Botcraft::TemplatedBehaviourClient { public: BilicraftClient(); ~BilicraftClient() override; bool WasDisconnected() const; bool HasEnteredPlay() const; // Synchronous .act execution: tasks yield to a main-thread cancellation/ // pacing hook instead of starting the upstream behaviour worker. Never use // this mode concurrently with StartBehaviour/BehaviourStep/SyncAction. void SetActionYieldHandler(std::function handler); void Yield() override; protected: using Botcraft::TemplatedBehaviourClient::Handle; void Handle(ProtocolCraft::ClientboundLoginPacket &packet) override; void Handle(ProtocolCraft::ClientboundLoginDisconnectPacket &packet) override; void Handle(ProtocolCraft::ClientboundDisconnectConfigurationPacket &packet) override; void Handle(ProtocolCraft::ClientboundDisconnectPacket &packet) override; private: // Main-thread-only hook; it is never called by network/physics handlers. std::function actionYieldHandler; // Do not use upstream's non-atomic should_be_closed as our cross-thread signal. std::atomic disconnected{false}; std::atomic enteredPlay{false}; }; } // namespace Bilicraft