34 constexpr std::array variable_names = {
40 blackboard.
Set<std::string>(variable_names[0], msg);
47 constexpr std::array variable_names = {
54 const std::string& msg = blackboard.
Get<std::string>(variable_names[0]);
62 std::shared_ptr<LocalPlayer> local_player = client.
GetLocalPlayer();
64 if (local_player ==
nullptr)
72#if PROTOCOL_VERSION < 766
73 constexpr double range = 4.5;
75 const double range = local_player->GetAttributePlayerBlockInteractionRangeValue();
87 std::shared_ptr<ProtocolCraft::ServerboundUseItemOnPacket> place_block_msg = std::make_shared<ProtocolCraft::ServerboundUseItemOnPacket>();
89 place_block_msg->SetDirection(
static_cast<int>(face));
93 place_block_msg->SetCursorPositionX(0.5f);
94 place_block_msg->SetCursorPositionY(0.0f);
95 place_block_msg->SetCursorPositionZ(0.5f);
98 place_block_msg->SetCursorPositionX(0.5f);
99 place_block_msg->SetCursorPositionY(1.0f);
100 place_block_msg->SetCursorPositionZ(0.5f);
103 place_block_msg->SetCursorPositionX(0.5f);
104 place_block_msg->SetCursorPositionY(0.5f);
105 place_block_msg->SetCursorPositionZ(0.0f);
108 place_block_msg->SetCursorPositionX(0.5f);
109 place_block_msg->SetCursorPositionY(0.5f);
110 place_block_msg->SetCursorPositionZ(1.0f);
113 place_block_msg->SetCursorPositionX(1.0f);
114 place_block_msg->SetCursorPositionY(0.5f);
115 place_block_msg->SetCursorPositionZ(0.5f);
118 place_block_msg->SetCursorPositionX(0.0f);
119 place_block_msg->SetCursorPositionY(0.5f);
120 place_block_msg->SetCursorPositionZ(0.5f);
125#if PROTOCOL_VERSION > 452
126 place_block_msg->SetInside(
false);
128 place_block_msg->SetHand(
static_cast<int>(
Hand::Right));
129#if PROTOCOL_VERSION > 758
130 place_block_msg->SetSequence(client.
GetWorld()->GetNextWorldInteractionSequenceId());
136 std::shared_ptr<ProtocolCraft::ServerboundSwingPacket> animation_msg = std::make_shared<ProtocolCraft::ServerboundSwingPacket>();
137 animation_msg->SetHand(
static_cast<int>(
Hand::Right));
148 constexpr std::array variable_names = {
149 "InteractWithBlock.pos",
150 "InteractWithBlock.face",
151 "InteractWithBlock.animation"
158 blackboard.
Set<
bool>(variable_names[2], animation);
165 constexpr std::array variable_names = {
166 "InteractWithBlock.pos",
167 "InteractWithBlock.face",
168 "InteractWithBlock.animation"
178 const bool animation = blackboard.
Get(variable_names[2],
true);
191 constexpr std::array variable_names = {
192 "CheckBlackboardBoolData.key"
197 blackboard.
Set<std::string>(variable_names[0], key);
204 constexpr std::array variable_names = {
205 "CheckBlackboardBoolData.key"
211 const std::string& key = blackboard.
Get<std::string>(variable_names[0]);
226 constexpr std::array variable_names = {
227 "RemoveBlackboardData.key"
232 blackboard.
Set<std::string>(variable_names[0], key);
239 constexpr std::array variable_names = {
240 "RemoveBlackboardData.key"
246 const std::string& key = blackboard.
Get<std::string>(variable_names[0]);
259 constexpr std::array variable_names = {
265 blackboard.
Set<
int>(variable_names[0], threshold);
272 constexpr std::array variable_names = {
279 const int threshold = blackboard.
Get<
int>(variable_names[0]);
294 constexpr std::array variable_names = {
295 "CopyBlackboardData.src",
296 "CopyBlackboardData.dst"
301 blackboard.
Set<std::string>(variable_names[0], src);
302 blackboard.
Set<std::string>(variable_names[1], dst);
309 constexpr std::array variable_names = {
310 "CopyBlackboardData.src",
311 "CopyBlackboardData.dst"
317 const std::string& src = blackboard.
Get<std::string>(variable_names[0]);
318 const std::string& dst = blackboard.
Get<std::string>(variable_names[1]);
A ManagersClient extended with a blackboard that can store any kind of data and a virtual Yield funct...
Blackboard & GetBlackboard()
A map wrapper to store arbitrary data.
void Erase(const std::string &key)
Remove a map entry if present.
void Set(const std::string &key, const T &value)
Set map entry at key to value.
void Copy(const std::string &src, const std::string &dst)
Copy a blackboard value.
const T & Get(const std::string &key)
Get the map value at key, casting it to T.
std::shared_ptr< NetworkManager > GetNetworkManager() const
void SendChatMessage(const std::string &msg)
Send a message in the game chat.
void SetShouldBeClosed(const bool b)
std::shared_ptr< LocalPlayer > GetLocalPlayer() const
int GetDayTime() const
Get the current tick.
std::shared_ptr< World > GetWorld() const
Status IsHungryBlackboard(BehaviourClient &client)
Same thing as IsHungry, but reads its parameters from the blackboard.
Status RemoveBlackboardDataBlackboard(BehaviourClient &client)
Same thing as RemoveBlackboardData, but reads its parameters from the blackboard.
Status SayBlackboard(BehaviourClient &client)
Same thing as Say, but reads its parameters from the blackboard.
Status RemoveBlackboardDataImpl(BehaviourClient &client, const std::string &key)
Status GoTo(BehaviourClient &client, const Position &goal, const int dist_tolerance=0, const int min_end_dist=0, const int min_end_dist_xz=0, const bool allow_jump=true, const bool sprint=true, const float speed_factor=1.0f)
Find a path to a block position and navigate to it.
Status InteractWithBlockImpl(BehaviourClient &client, const Position &pos, const PlayerDiggingFace face, const bool animation)
Status CopyBlackboardData(BehaviourClient &client, const std::string &src, const std::string &dst)
Copy a blackboard data.
Status SayImpl(BehaviourClient &client, const std::string &msg)
Status IsHungry(BehaviourClient &client, const int threshold=20)
Return success if player food is below a threshold.
Status Disconnect(BehaviourClient &client)
Ask this client to disconnect from the server by setting should_be_closed to true.
Status CopyBlackboardDataBlackboard(BehaviourClient &client)
Same thing as CopyBlackboardData, but reads its parameters from the blackboard.
Status Yield(BehaviourClient &client)
Just call client.Yield().
Status Say(BehaviourClient &client, const std::string &msg)
Send a message in the game chat.
Status CheckBlackboardBoolDataBlackboard(BehaviourClient &client)
Same thing as CheckBlackboardBoolData, but reads its parameters from the blackboard.
Status LookAt(BehaviourClient &client, const Vector3< double > &target, const bool set_pitch=true, const bool sync_to_server=true)
Turn the camera to look at a given target and send the new rotation to the server.
Status InteractWithBlock(BehaviourClient &client, const Position &pos, const PlayerDiggingFace face=PlayerDiggingFace::Up, const bool animation=true)
Interact (right click) with the block at the given location.
Status IsHungryImpl(BehaviourClient &client, const int threshold)
Status IsNightTime(BehaviourClient &client)
Return Success if it's night time (sleep is possible)
Status InteractWithBlockBlackboard(BehaviourClient &client)
Same thing as InteractWithBlock, but reads its parameters from the blackboard.
Status CheckBlackboardBoolDataImpl(BehaviourClient &client, const std::string &key)
Status CopyBlackboardDataImpl(BehaviourClient &client, const std::string &src, const std::string &dst)
Status CheckBlackboardBoolData(BehaviourClient &client, const std::string &key)
Check in the blackboard if the bool at key is true.
Status RemoveBlackboardData(BehaviourClient &client, const std::string &key)
Remove a value from the blackboard if exist.
Status IsAlive(BehaviourClient &client)
Return success if player is alive.
double SqrDist(const Vector3 &v) const
ProtocolCraft::NetworkPosition ToNetworkPosition() const