Botcraft 1.21.4
Loading...
Searching...
No Matches
LocalPlayer.hpp
Go to the documentation of this file.
1#pragma once
2
4
5#include <optional>
6
7namespace Botcraft
8{
10 {
11 float forward_axis = 0.0f;
12 float left_axis = 0.0f;
13 bool jump = false;
14 bool sneak = false;
15 bool sprint = false;
16 };
17
19 {
20 friend class PhysicsManager;
21
22 public:
24 virtual ~LocalPlayer();
25
26
30
31 GameType GetGameMode() const;
32 char GetAbilitiesFlags() const;
33 bool GetInvulnerable() const;
34 bool GetFlying() const;
35 bool GetMayFly() const;
36 /// @brief If true, the player can break any block in no time (creative mode)
37 /// @return Instabuild ability value
38 bool GetInstabuild() const;
39 bool GetMayBuild() const;
40 float GetFlyingSpeed() const;
41 float GetWalkingSpeed() const;
42 float GetHealth() const;
43 int GetFood() const;
44 float GetFoodSaturation() const;
45 bool GetDirtyInputs() const;
46 bool IsClimbing() const;
47 bool IsInWater() const;
48 bool IsInLava() const;
49 bool IsInFluid() const;
50
51 void SetGameMode(const GameType game_mode_);
52 void SetAbilitiesFlags(const char abilities_flags_);
53 void SetFlyingSpeed(const float flying_speed_);
54 void SetWalkingSpeed(const float walking_speed_);
55 void SetHealth(const float health_);
56 void SetFood(const int food_);
57 void SetFoodSaturation(const float food_saturation_);
58 void SetDirtyInputs();
59
60 virtual void SetPosition(const Vector3<double>& pos) override;
61 virtual void SetX(const double x) override;
62 virtual void SetY(const double y) override;
63 virtual void SetZ(const double z) override;
64 /// @brief Set Yaw angle (horizontal plane orientation)
65 /// @param yaw_ New yaw, in degree
66 virtual void SetYaw(const float yaw_) override;
67 /// @brief Set Pitch angle (look up is -90°, look down is 90°)
68 /// @param pitch_ New pitch, in degree
69 virtual void SetPitch(const float pitch_) override;
70
71 void SetInputsForward(const float f);
72 void AddInputsForward(const float f);
73 void SetInputsLeft(const float f);
74 void AddInputsLeft(const float f);
75 void SetInputsJump(const bool b);
76 void SetInputsSneak(const bool b);
77 void SetInputsSprint(const bool b);
78 void SetInputs(const PlayerInputs& inputs_);
79
80 virtual bool IsLocalPlayer() const override;
81 virtual bool IsRemotePlayer() const override;
82
83 void LookAt(const Vector3<double>& pos, const bool set_pitch = false);
84
85 private:
86 void UpdateVectors();
87 void ResetInputs();
88 void SetAbilitiesFlagsImpl(const char abilities_flags_);
90
91#if PROTOCOL_VERSION < 405 /* < 1.14 */
92 protected:
93 virtual double GetEyeHeightImpl() const override;
94 virtual double GetHeightImpl() const override;
95#endif
96
97 private:
101
104
106
109 /// @brief Flying in creative/spectator
110 bool flying;
111 /// @brief If this player can fly in creative/spectator
113 /// @brief Insta break blocks in creative
118
119 float health;
120 int food;
122
123 // Used during physics step (accessible as PhysicsManager is a friend class)
134 std::optional<Position> supporting_block_pos;
136
146#if PROTOCOL_VERSION > 767 /* > 1.21.1 */
149#endif
150 };
151} // Botcraft
void SetFoodSaturation(const float food_saturation_)
void SetAbilitiesFlags(const char abilities_flags_)
void SetInputsLeft(const float f)
float GetFoodSaturation() const
void SetFood(const int food_)
virtual bool IsLocalPlayer() const override
virtual void SetPitch(const float pitch_) override
Set Pitch angle (look up is -90°, look down is 90°)
virtual void SetPosition(const Vector3< double > &pos) override
void SetInputsForward(const float f)
virtual void SetZ(const double z) override
float GetFlyingSpeed() const
void SetInputsSprint(const bool b)
Vector3< double > GetRightVector() const
PlayerInputs last_sent_inputs
char GetAbilitiesFlags() const
void SetFlyingSpeed(const float flying_speed_)
Vector3< double > stuck_speed_multiplier
virtual void SetY(const double y) override
void AddInputsForward(const float f)
void SetAbilitiesFlagsImpl(const char abilities_flags_)
bool GetInvulnerable() const
void SetWalkingSpeed(const float walking_speed_)
bool flying
Flying in creative/spectator.
Vector3< double > right_vector
bool GetDirtyInputs() const
Vector3< double > GetXZVector() const
GameType GetGameMode() const
void SetInputs(const PlayerInputs &inputs_)
void AddInputsLeft(const float f)
std::optional< Position > supporting_block_pos
virtual void SetX(const double x) override
void SetHealth(const float health_)
virtual void SetYaw(const float yaw_) override
Set Yaw angle (horizontal plane orientation)
virtual bool IsRemotePlayer() const override
void SetInputsJump(const bool b)
void LookAt(const Vector3< double > &pos, const bool set_pitch=false)
float GetWalkingSpeed() const
Vector3< double > GetFrontVector() const
Vector3< double > xz_vector
bool may_fly
If this player can fly in creative/spectator.
void SetGameMode(const GameType game_mode_)
bool instabuild
Insta break blocks in creative.
Vector3< double > front_vector
bool GetInstabuild() const
If true, the player can break any block in no time (creative mode)
Vector3< double > previous_position
void SetInputsSneak(const bool b)
float GetHealth() const
virtual double GetHeightImpl() const override
virtual double GetEyeHeightImpl() const