Botcraft 1.21.4
Loading...
Searching...
No Matches
PathfindingTask.hpp
Go to the documentation of this file.
1#pragma once
2
5
6namespace Botcraft
7{
8 class BehaviourClient;
9
10 /// @brief Not actually a task. Helper function to compute path between start and end. Does not perfom any movement.
11 /// @param client Client used to do the pathfinding
12 /// @param start Start position
13 /// @param end End position
14 /// @param dist_tolerance Stop the search earlier if you get closer than dist_tolerance from the end position
15 /// @param min_end_dist Desired minimal checkboard distance between the final position and goal (useful if you want to place a block, you don't want to be at the exact spot, but close to it).
16 /// @param min_end_dist_xz Same as min_end_dist but only considering the XZ plane (allows to ask to stand next to a block, but above for example)
17 /// @param allow_jump If true, allow to jump above 1-wide gaps
18 /// @return A vector of <feet block position, Y position> to go through to reach end +/- min_end_dist. If not possible, will return a path to get as close as possible
19 std::vector<std::pair<Position, float>> FindPath(const BehaviourClient& client, const Position& start, const Position& end, const int dist_tolerance, const int min_end_dist, const int min_end_dist_xz, const bool allow_jump);
20
21 /// @brief Find a path to a block position and navigate to it.
22 /// @param client The client performing the action
23 /// @param goal The end goal
24 /// @param dist_tolerance If != 0 and the distance between final position and goal is < dist_tolerance, return Success even if goal is not reached.
25 /// @param min_end_dist Desired minimal checkboard distance between the final position and goal (useful if you want to place a block, you don't want to be at the exact spot, but close to it). Should always be <= dist_tolerance.
26 /// @param min_end_dist_xz Same as min_end_dist but only considering the XZ plane (allows to ask to stand next to a block, but above for example)
27 /// @param allow_jump If true, allow to jump above 1-wide gaps
28 /// @param sprint If true, the bot will sprint/swim when possible
29 /// @param speed_factor Multiply vanilla speed if different from 1.0
30 /// @return Success if goal is reached, Failure otherwise
31 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);
32
33 /// @brief Same thing as GoTo, but reads its parameters from the blackboard
34 /// @param client The client performing the action
35 /// @return Success if goal is reached, Failure otherwise
36 Status GoToBlackboard(BehaviourClient& client);
37
38
39 /// @brief Find a path to a position and navigate to it. Will first move to block center, then adjust to be as close as possible to goal on X/Z axis. Gravity may prevent reaching Y target.
40 /// @param client The client performing the action
41 /// @param goal The end goal
42 /// @param allow_jump If true, allow to jump above 1-wide gaps
43 /// @param sprint If true, the bot will sprint/swim when possible
44 /// @param speed_factor Multiply vanilla speed if different from 1.0
45 /// @return Success if goal is reached, Failure otherwise
46 Status GoToDouble(BehaviourClient& client, const Vector3<double>& goal, const bool allow_jump = true, const bool sprint = true, const float speed_factor = 1.0f);
47
48 /// @brief Same thing as GoToDouble, but reads its parameters from the blackboard
49 /// @param client The client performing the action
50 /// @return Success if goal is reached, Failure otherwise
51 Status GoToDoubleBlackboard(BehaviourClient& client);
52
53
54 /// @brief Turn the camera to look at a given target and send the new rotation to the server
55 /// @param client The client performing the action
56 /// @param target The target to look at
57 /// @param set_pitch If false, only the yaw will be changed
58 /// @param sync_to_server If true, will wait for the new orientation to be sent to the server
59 /// @return Always Success if sync_to_server is false, return the SyncPosRotToServer result otherwise
60 Status LookAt(BehaviourClient& client, const Vector3<double>& target, const bool set_pitch = true, const bool sync_to_server = true);
61
62 /// @brief Same thing as LookAt, but reads its parameters from the blackboard
63 /// @param client The client performing the action
64 /// @return Always return Success
65 Status LookAtBlackboard(BehaviourClient& client);
66
67 /// @brief Make the current player fly (as in creative/spectator mode, NOT WITH ELYTRA)
68 /// @param client The client performing the action
69 /// @return Success if the player is now flying, failure otherwise
70 Status StartFlying(BehaviourClient& client);
71
72 /// @brief Make the current player not fly (as in creative/spectator mode, NOT WITH ELYTRA)
73 /// @param client The client performing the action
74 /// @return Success if the player is now not flying anymore, failure otherwise
75 Status StopFlying(BehaviourClient& client);
76
77 /// @brief This task will make sure the current player position/orientation have been sent to the server
78 /// This is important for example if you want to throw an item: you need to first look in the desired direction
79 /// then throw the item. But if the new orientation is not registered server side, the items won't be instantiated
80 /// in the right direction
81 /// @param client The client performing the action
82 /// @return Failure if the position has not been properly sent to the server in a reasonable time (it may happen
83 /// if the physics manager is currently not running), Success otherwise
84 Status SyncPosRotToServer(BehaviourClient& client);
85
86} // namespace Botcraft
Status GoToDouble(BehaviourClient &client, const Vector3< double > &goal, const bool allow_jump=true, const bool sprint=true, const float speed_factor=1.0f)
Find a path to a position and navigate to it.
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 StartFlying(BehaviourClient &client)
Make the current player fly (as in creative/spectator mode, NOT WITH ELYTRA)
Status SyncPosRotToServer(BehaviourClient &client)
This task will make sure the current player position/orientation have been sent to the server This is...
Vector3< int > Position
Definition Vector3.hpp:282
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.
std::vector< std::pair< Position, float > > FindPath(const BehaviourClient &client, const Position &start, const Position &end, const int dist_tolerance, const int min_end_dist, const int min_end_dist_xz, const bool allow_jump)
Not actually a task.
Status GoToDoubleBlackboard(BehaviourClient &client)
Same thing as GoToDouble, but reads its parameters from the blackboard.
Status GoToBlackboard(BehaviourClient &client)
Same thing as GoTo, but reads its parameters from the blackboard.
Status StopFlying(BehaviourClient &client)
Make the current player not fly (as in creative/spectator mode, NOT WITH ELYTRA)
Status LookAtBlackboard(BehaviourClient &client)
Same thing as LookAt, but reads its parameters from the blackboard.