Cuberite
A lightweight, fast and extensible game server for Minecraft
Player.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "Pawn.h"
5 #include "../Inventory.h"
6 #include "../Defines.h"
7 #include "../World.h"
8 #include "../Items/ItemHandler.h"
9 
10 #include "../StatisticsManager.h"
11 
12 #include "../UUID.h"
13 
14 
15 
16 
17 
18 class cWindow;
19 class cClientHandle;
20 class cTeam;
21 
22 
23 
24 
25 
26 // tolua_begin
27 class cPlayer:
28  public cPawn
29 {
30  // tolua_end
31 
32  using Super = cPawn;
33 
36  {
37  BodyStanceCrouching(cPlayer & a_Player);
38  };
39 
43  {
44  BodyStanceSleeping(cPlayer & a_Player);
45  };
46 
49  {
50  };
51 
54  {
55  BodyStanceStanding(cPlayer & a_Player);
56  };
57 
60  {
61  BodyStanceGliding(cPlayer & a_Player);
62 
64  };
65 
66  /*
67  struct HandStanceNeutral
68  {
69  };
70 
71  struct HandStandChargingBow
72  {
73  int m_BowCharge;
74  };
75 
76  struct HandStanceEating
77  {
78  };
79  */
80 
81  // tolua_begin
82 
83 public:
84 
85  static const int MAX_HEALTH;
86 
87  static const int MAX_FOOD_LEVEL;
88 
89  // tolua_end
90 
92 
93  cPlayer(const std::shared_ptr<cClientHandle> & a_Client);
94  virtual ~cPlayer() override;
95 
97  void OnLoseSpectated();
98 
99  // tolua_begin
100 
105  bool SetCurrentExperience(int a_XpTotal);
106 
107  /* changes Xp by Xp_delta, you "shouldn't" inc more than MAX_EXPERIENCE_ORB_SIZE
108  Wont't allow xp to go negative
109  Returns the new current experience, -1 on error
110  */
111  int DeltaExperience(int a_Xp_delta);
112 
114  inline int GetXpLifetimeTotal(void) { return m_LifetimeTotalXp; }
115 
117  inline int GetCurrentXp(void) { return m_CurrentXp; }
118 
120  int GetXpLevel(void) const;
121 
123  float GetXpPercentage(void) const;
124 
128  static int XpForLevel(int a_Level);
129 
134  static int CalcLevelFromXp(int a_CurrentXp);
135 
136  // tolua_end
137 
139  const std::set<UInt32> & GetKnownRecipes() const;
140 
142  void StartChargingBow(void);
143 
145  int FinishChargingBow(void);
146 
148  void CancelChargingBow(void);
149 
151  bool IsChargingBow(void) const { return m_IsChargingBow; }
152 
153  void SetTouchGround(bool a_bTouchGround);
154  double GetEyeHeight(void) const; // tolua_export
155  Vector3d GetEyePosition(void) const; // tolua_export
156  inline cInventory & GetInventory(void) { return m_Inventory; } // tolua_export
157  inline const cInventory & GetInventory(void) const { return m_Inventory; }
158 
161 
162  inline const cItem & GetEquippedItem(void) const { return GetInventory().GetEquippedItem(); } // tolua_export
163 
165  bool IsClimbing(void) const;
166 
167  virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override;
168 
170  void UpdateCapabilities();
171 
172  // tolua_begin
173 
175  void Freeze(const Vector3d & a_Location);
176 
178  bool IsFrozen();
179 
181  void Unfreeze();
182 
187  void SendRotation(double a_YawDegrees, double a_PitchDegrees);
188 
190  void SpectateEntity(cEntity * a_Target);
191 
193  Vector3d GetThrowStartPos(void) const;
194 
196  Vector3d GetThrowSpeed(double a_SpeedCoeff) const;
197 
199  eGameMode GetGameMode(void) const { return m_GameMode; }
200 
202  eGameMode GetEffectiveGameMode(void) const;
203 
208  void SetGameMode(eGameMode a_GameMode);
209 
211  bool IsGameModeCreative(void) const;
212 
214  bool IsGameModeSurvival(void) const;
215 
217  bool IsGameModeAdventure(void) const;
218 
220  bool IsGameModeSpectator(void) const;
221 
225  virtual bool IsFireproof() const override
226  {
228 
229  }
230 
232  bool CanMobsTarget(void) const;
233 
234  AString GetIP(void) const; // tolua_export
235 
238 
240  cTeam * GetTeam(void) { return m_Team; } // tolua_export
241 
243  const cTeam * GetTeam(void) const { return m_Team; }
244 
246  void SetTeam(cTeam * a_Team);
247 
248  // tolua_end
249 
251  cTeam * UpdateTeam(void);
252 
256  void AwardAchievement(CustomStatistic a_Ach);
257 
260  void ForceSetSpeed(const Vector3d & a_Speed); // tolua_export
261 
262  cWindow * GetWindow(void) { return m_CurrentWindow; } // tolua_export
263  const cWindow * GetWindow(void) const { return m_CurrentWindow; }
264 
265  // tolua_begin
266 
268  void OpenWindow(cWindow & a_Window);
269 
271  void CloseWindow(bool a_CanRefuse = true);
272 
274  void CloseWindowIfID(char a_WindowID, bool a_CanRefuse = true);
275 
276  cClientHandle * GetClientHandle(void) const { return m_ClientHandle.get(); }
277 
278  // tolua_end
279 
283 
285  void PermuteEnchantmentSeed();
286 
287  // tolua_begin
288 
289  void SendMessage (const AString & a_Message);
290  void SendMessageInfo (const AString & a_Message);
291  void SendMessageFailure (const AString & a_Message);
292  void SendMessageSuccess (const AString & a_Message);
293  void SendMessageWarning (const AString & a_Message);
294  void SendMessageFatal (const AString & a_Message);
295  void SendMessagePrivateMsg (const AString & a_Message, const AString & a_Sender);
296  void SendMessage (const cCompositeChat & a_Message);
297  void SendMessageRaw (const AString & a_MessageRaw, eChatType a_Type = eChatType::ctChatBox);
298  void SendSystemMessage (const AString & a_Message);
299  void SendAboveActionBarMessage(const AString & a_Message);
300  void SendSystemMessage (const cCompositeChat & a_Message);
301  void SendAboveActionBarMessage(const cCompositeChat & a_Message);
302 
303  const AString & GetName(void) const;
304 
305  // tolua_end
306 
307  bool HasPermission(const AString & a_Permission) const; // tolua_export
308 
312  static bool PermissionMatches(const AStringVector & a_Permission, const AStringVector & a_Template); // Exported in ManualBindings with AString params
313 
315  const AStringVector & GetPermissions(void) const { return m_Permissions; } // Exported in ManualBindings.cpp
316 
318  const AStringVector & GetRestrictions(void) const { return m_Restrictions; } // Exported in ManualBindings.cpp
319 
320  // tolua_begin
321 
324  AString GetColor(void) const;
325 
327  AString GetPrefix(void) const;
328 
330  AString GetSuffix(void) const;
331 
333  AString GetPlayerListName(void) const;
334 
336  void TossEquippedItem(char a_Amount = 1);
337 
344 
346  void TossHeldItem(char a_Amount = 1);
347 
349  void TossPickup(const cItem & a_Item);
350 
352  virtual void Heal(int a_Health) override;
353 
354  int GetFoodLevel (void) const { return m_FoodLevel; }
355  double GetFoodSaturationLevel (void) const { return m_FoodSaturationLevel; }
356  int GetFoodTickTimer (void) const { return m_FoodTickTimer; }
357  double GetFoodExhaustionLevel (void) const { return m_FoodExhaustionLevel; }
358 
360  bool IsSatiated(void) const { return (m_FoodLevel >= MAX_FOOD_LEVEL); }
361 
362  void SetFoodLevel (int a_FoodLevel);
363  void SetFoodSaturationLevel (double a_FoodSaturationLevel);
364  void SetFoodTickTimer (int a_FoodTickTimer);
365  void SetFoodExhaustionLevel (double a_FoodExhaustionLevel);
366 
368  bool Feed(int a_Food, double a_Saturation);
369 
371  void AddFoodExhaustion(double a_Exhaustion);
372 
374  bool IsEating(void) const { return m_EatingFinishTick >= 0_tick; }
375 
377  bool IsFlying(void) const { return m_IsFlying; }
378 
380  bool IsInBed(void) const;
381 
383  bool IsLeftHanded() const;
384 
386  bool IsFishing(void) const { return m_IsFishing; }
387 
388  void SetIsFishing(bool a_IsFishing, UInt32 a_FloaterID = cEntity::INVALID_ID) { m_IsFishing = a_IsFishing; m_FloaterID = a_FloaterID; }
389 
390  UInt32 GetFloaterID(void) const { return m_FloaterID; }
391 
392  // tolua_end
393 
395  bool IsStanding() const;
396 
398  void TossItems(const cItems & a_Items);
399 
403  void SetIsInBed(bool a_IsInBed);
404 
406  void StartEating(void);
407 
409  void FinishEating(void);
410 
412  void AbortEating(void);
413 
414  virtual void KilledBy(TakeDamageInfo & a_TDI) override;
415 
416  virtual void Killed(const cEntity & a_Victim, eDamageType a_DamageType) override;
417 
418  void Respawn(void); // tolua_export
419 
420  void SetVisible( bool a_bVisible); // tolua_export
421 
423  void SaveToDisk(void);
424 
427  void LoadFromDisk();
428 
429  const AString & GetLoadedWorldName() const { return m_CurrentWorldName; }
430 
433  void OpenHorseInventory();
434 
437  void UseEquippedItem(short a_Damage = 1);
438 
442 
445  void UseItem(int a_SlotNumber, short a_Damage = 1);
446 
448  cItem & GetDraggingItem(void) {return m_DraggingItem; } // tolua_export
449 
451  void SetDraggingItem(const cItem & a_Item); // tolua_export
452 
453  // In UI windows, when inventory-painting:
455  void ClearInventoryPaintSlots(void);
456 
458  void AddInventoryPaintSlot(int a_SlotNum);
459 
461  const cSlotNums & GetInventoryPaintSlots(void) const;
462 
463  // tolua_begin
464 
466  double GetMaxSpeed(void) const;
467 
469  double GetNormalMaxSpeed(void) const { return m_NormalMaxSpeed; }
470 
472  double GetSprintingMaxSpeed(void) const { return m_SprintingMaxSpeed; }
473 
475  double GetFlyingMaxSpeed(void) const { return m_FlyingMaxSpeed; }
476 
478  void SetNormalMaxSpeed(double a_Speed);
479 
481  void SetSprintingMaxSpeed(double a_Speed);
482 
484  void SetFlyingMaxSpeed(double a_Speed);
485 
487  void SetCrouch(bool a_ShouldCrouch);
488 
490  void SetElytraFlight(bool a_ShouldElytraFly);
491 
493  void SetFlying(bool a_ShouldFly);
494 
496  void SetLeftHanded(bool a_IsLeftHanded);
497 
499  void SetSprint(bool a_ShouldSprint);
500 
502  void SetCanFly(bool a_CanFly);
503 
505  bool HasCustomName(void) const { return !m_CustomName.empty(); }
506 
508  const AString & GetCustomName(void) const { return m_CustomName; }
509 
512  void SetCustomName(const AString & a_CustomName);
513 
515  Vector3i GetLastBedPos(void) const { return m_RespawnPosition; }
516 
518  bool IsRespawnPointForced(void) const { return m_IsRespawnPointForced; }
519 
523  void SetBedPos(Vector3i a_Position);
524 
527  void SetBedPos(Vector3i a_Position, const cWorld & a_World);
528 
530  void SetRespawnPosition(Vector3i a_Position, const cWorld & a_World);
531 
532  // tolua_end
533 
534  // TODO lua export GetRespawnWorld
536 
538  void UpdateMovementStats(const Vector3d & a_DeltaPos, bool a_PreviousIsOnGround);
539 
541  bool DoesPlacingBlocksIntersectEntity(std::initializer_list<sSetBlock> a_Blocks) const;
542 
544  const cUUID & GetUUID(void) const; // Exported in ManualBindings.cpp
545 
546  // tolua_begin
547 
549  virtual bool CanFly(void) const { return m_IsFlightCapable; }
550 
552  void LoadRank(void);
553 
557  void SendBlocksAround(Vector3i a_BlockPos, int a_Range = 1);
558 
559  bool HasSkinPart(eSkinPart a_Part) const { return (m_SkinParts & a_Part) != 0; }
560  int GetSkinParts(void) const { return m_SkinParts; }
561  void SetSkinParts(int a_Parts);
562 
563  // tolua_end
564 
566  bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta);
567 
572  bool PlaceBlocks(std::initializer_list<sSetBlock> a_Blocks);
573 
578  void NotifyNearbyWolves(cPawn * a_Opponent, bool a_IsPlayerInvolved);
579 
584  float GetMiningProgressPerTick(BLOCKTYPE a_Block);
585 
590  bool CanInstantlyMine(BLOCKTYPE a_Block);
591 
594  void AddKnownItem(const cItem & a_Item);
595 
596  // cEntity overrides:
597  virtual cItem GetEquippedWeapon(void) const override { return m_Inventory.GetEquippedItem(); }
598  virtual cItem GetEquippedHelmet(void) const override { return m_Inventory.GetEquippedHelmet(); }
599  virtual cItem GetEquippedChestplate(void) const override { return m_Inventory.GetEquippedChestplate(); }
600  virtual cItem GetEquippedLeggings(void) const override { return m_Inventory.GetEquippedLeggings(); }
601  virtual cItem GetEquippedBoots(void) const override { return m_Inventory.GetEquippedBoots(); }
602  virtual cItem GetOffHandEquipedItem(void) const override { return m_Inventory.GetShieldSlot(); }
603  virtual bool IsCrouched(void) const override;
604  virtual bool IsOnGround(void) const override { return m_bTouchGround; }
605  virtual bool IsSprinting(void) const override;
606 
607 private:
608 
609  typedef std::vector<std::vector<AString> > AStringVectorVector;
610 
612  std::variant<BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding> m_BodyStance;
613 
616 
619 
622 
626 
630 
631  // Message visuals:
634 
635  // Food-related variables:
638 
641 
644 
647 
650 
653 
656 
660 
663  std::string m_SpawnWorldName;
664 
667  std::string m_CurrentWorldName;
668 
670  std::string m_DefaultWorldPath;
671 
673 
676 
677  std::shared_ptr<cClientHandle> m_ClientHandle;
678 
680 
685 
690 
695 
698 
701 
703 
706 
709 
712 
715 
719 
721 
724 
728  unsigned int m_EnchantmentSeed;
729 
731 
733 
735 
738 
740 
743  unsigned int m_TicksUntilNextSave;
744 
746 
749 
751  std::set<UInt32> m_KnownRecipes;
752 
754  std::set<cItem, cItem::sItemCompare> m_KnownItems;
755 
757  void HandleFood(void);
758 
760  void HandleFloater(void);
761 
764  AString GetUUIDFileName(const cUUID & a_UUID);
765 
768  void FreezeInternal(const Vector3d & a_Location, bool a_ManuallyFrozen);
769 
771  float GetLiquidHeightPercent(NIBBLETYPE a_Meta);
772 
774  bool IsInsideWater();
775 
783  float GetDigSpeed(BLOCKTYPE a_Block);
784 
787  void AddKnownRecipe(UInt32 RecipeId);
788 
789  void TickFreezeCode();
790 
793  void RefreshRank();
794 
795  // cEntity overrides:
796  virtual void ApplyArmorDamage(int DamageBlocked) override;
797  virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr) override;
798  virtual bool DoTakeDamage(TakeDamageInfo & TDI) override;
799  virtual float GetEnchantmentBlastKnockbackReduction() override;
800  virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &) override { UNUSED(a_Dt); }
801  virtual bool IsElytraFlying(void) const override;
802  virtual bool IsInvisible() const override;
803  virtual bool IsRclking(void) const override { return IsEating() || IsChargingBow(); }
804  virtual void OnAddToWorld(cWorld & a_World) override;
805  virtual void OnDetach() override;
806  virtual void OnRemoveFromWorld(cWorld & a_World) override;
807  virtual void SpawnOn(cClientHandle & a_Client) override;
808  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override;
809 
810 } ; // tolua_export
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eChatType
Definition: Defines.h:149
@ ctChatBox
Definition: Defines.h:150
eSkinPart
Definition: Defines.h:215
eGameMode
Definition: Defines.h:125
eDamageType
Damage type, used in the TakeDamageInfo structure and related functions.
Definition: Defines.h:244
std::vector< int > cSlotNums
List of slot numbers, used for inventory-painting.
Definition: Defines.h:9
#define CLASS_PROTODEF(classname)
Definition: Entity.h:13
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
Definition: Globals.h:367
unsigned int UInt32
Definition: Globals.h:157
std::chrono::duration< signed int, std::ratio_multiply< std::chrono::milliseconds::period, std::ratio< 50 > >> cTickTime
Definition: Globals.h:364
#define UNUSED
Definition: Globals.h:72
CustomStatistic
std::vector< AString > AStringVector
Definition: StringUtils.h:12
std::string AString
Definition: StringUtils.h:11
Definition: Chunk.h:36
Container for a single chat message composed of multiple functional parts.
Definition: CompositeChat.h:34
Definition: Entity.h:76
bool m_IsFireproof
Whether the entity is capable of taking fire or lava damage.
Definition: Entity.h:630
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
Definition: Entity.h:128
Definition: Pawn.h:17
bool m_bTouchGround
Definition: Pawn.h:105
cPawn(eEntityType a_EntityType, float a_Width, float a_Height)
Definition: Pawn.cpp:18
Definition: Player.h:29
cTeam * UpdateTeam(void)
Forces the player to query the scoreboard for his team.
Definition: Player.cpp:1103
void SendMessage(const AString &a_Message)
Definition: Player.cpp:1182
void SendMessageWarning(const AString &a_Message)
Definition: Player.cpp:1218
std::string m_CurrentWorldName
The name of the world which the player currently resides in.
Definition: Player.h:667
cClientHandle * GetClientHandle(void) const
Definition: Player.h:276
bool m_IsFlightCapable
If this is true the player can fly.
Definition: Player.h:700
void SendAboveActionBarMessage(const AString &a_Message)
Definition: Player.cpp:1272
void SetFlying(bool a_ShouldFly)
Starts or stops flying, broadcasting the state change.
Definition: Player.cpp:700
const AString & GetName(void) const
Definition: Player.cpp:1299
int m_SkinParts
Displayed skin part bit mask.
Definition: Player.h:748
bool m_IsFrozen
If true, we are locking m_Position to m_FrozenPosition.
Definition: Player.h:705
virtual cItem GetEquippedHelmet(void) const override
Returns the currently equipped helmet; empty item if none.
Definition: Player.h:598
const cSlotNums & GetInventoryPaintSlots(void) const
Returns the list of slots currently stored for inventory painting.
Definition: Player.cpp:581
Vector3i GetLastBedPos(void) const
Gets the player's potential respawn position (named LastBedPos for compatibility reasons).
Definition: Player.h:515
bool IsStanding() const
Returns true if a player is standing normally, that is, in a neutral pose.
Definition: Player.cpp:469
void HandleFood(void)
Called in each tick to handle food-related processing.
Definition: Player.cpp:2116
void ClearInventoryPaintSlots(void)
Clears the list of slots that are being inventory-painted.
Definition: Player.cpp:561
AString m_CustomName
Definition: Player.h:745
eGameMode m_GameMode
Definition: Player.h:672
void UpdateMovementStats(const Vector3d &a_DeltaPos, bool a_PreviousIsOnGround)
Update movement-related statistics.
Definition: Player.cpp:2216
void AwardAchievement(CustomStatistic a_Ach)
Awards the player an achievement.
Definition: Player.cpp:1372
bool m_IsChargingBow
Definition: Player.h:696
void HandleFloater(void)
Called in each tick if the player is fishing to make sure the floater dissapears when the player does...
Definition: Player.cpp:2172
AString GetColor(void) const
Returns the full color code to use for this player, based on their rank.
Definition: Player.cpp:1651
unsigned int m_TicksUntilNextSave
How long till the player's inventory will be saved Default save interval is #defined in PLAYER_INVENT...
Definition: Player.h:743
int GetSkinParts(void) const
Definition: Player.h:560
std::string m_SpawnWorldName
The name of the world which the player respawns in upon death.
Definition: Player.h:663
bool DoesPlacingBlocksIntersectEntity(std::initializer_list< sSetBlock > a_Blocks) const
Whether placing the given blocks would intersect any entitiy.
Definition: Player.cpp:2366
bool SetCurrentExperience(int a_XpTotal)
Sets the experience total Returns true on success "should" really only be called at init or player de...
Definition: Player.cpp:259
std::variant< BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding > m_BodyStance
The current body stance the player has adopted.
Definition: Player.h:612
void LoadFromDisk()
Loads the player data from the save file.
Definition: Player.cpp:1803
void SendMessageInfo(const AString &a_Message)
Definition: Player.cpp:1191
bool IsFrozen()
Is the player frozen?
Definition: Player.cpp:1432
void AddInventoryPaintSlot(int a_SlotNum)
Adds a slot to the list for inventory painting.
Definition: Player.cpp:571
double GetSprintingMaxSpeed(void) const
Gets the sprinting relative maximum speed.
Definition: Player.h:472
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
Definition: Player.h:237
double m_NormalMaxSpeed
Max speed, relative to the game default.
Definition: Player.h:684
virtual cItem GetEquippedChestplate(void) const override
Returns the currently equipped chestplate; empty item if none.
Definition: Player.h:599
void SetNormalMaxSpeed(double a_Speed)
Sets the normal relative maximum speed.
Definition: Player.cpp:611
int GetCurrentXp(void)
Gets the current experience.
Definition: Player.h:117
bool HasSkinPart(eSkinPart a_Part) const
Definition: Player.h:559
cWorld * GetRespawnWorld()
Definition: Player.cpp:817
double m_FlyingMaxSpeed
Max speed, relative to the game default flying max speed, when flying.
Definition: Player.h:694
const cInventory & GetInventory(void) const
Definition: Player.h:157
void CloseWindow(bool a_CanRefuse=true)
Closes the current window, resets current window to m_InventoryWindow.
Definition: Player.cpp:1144
cTeam * m_Team
Definition: Player.h:734
void RefreshRank()
(Re)loads the rank and permissions from the cRankManager.
Definition: Player.cpp:2807
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
Definition: Player.cpp:2431
bool IsRespawnPointForced(void) const
Returns if the respawn point is unconditionally used.
Definition: Player.h:518
UInt32 m_FloaterID
Definition: Player.h:732
bool m_IsLeftHanded
Whether the player is left-handed, or right-handed.
Definition: Player.h:708
virtual void Killed(const cEntity &a_Victim, eDamageType a_DamageType) override
Called when the entity kills another entity.
Definition: Player.cpp:896
bool m_IsFishing
Definition: Player.h:697
double m_SprintingMaxSpeed
Max speed, relative to the game default max speed, when sprinting.
Definition: Player.h:689
void Respawn(void)
Definition: Player.cpp:936
void SendRotation(double a_YawDegrees, double a_PitchDegrees)
Sends the "look" packet to the player, forcing them to set their rotation to the specified values.
Definition: Player.cpp:1460
cItemGrid m_EnderChestContents
An item grid that stores the player specific enderchest contents.
Definition: Player.h:652
bool PlaceBlocks(std::initializer_list< sSetBlock > a_Blocks)
Calls the block placement hooks and places the blocks in the world.
Definition: Player.cpp:2449
void TossItems(const cItems &a_Items)
Tosses a list of items.
Definition: Player.cpp:478
const cItem & GetEquippedItem(void) const
Definition: Player.h:162
void CancelChargingBow(void)
Cancels the current bow charging.
Definition: Player.cpp:339
cPlayer(const std::shared_ptr< cClientHandle > &a_Client)
Definition: Player.cpp:117
bool HasCustomName(void) const
Returns true if the player has a custom name.
Definition: Player.h:505
bool Feed(int a_Food, double a_Saturation)
Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed,...
Definition: Player.cpp:423
float GetXpPercentage(void) const
Gets the experience bar percentage - XpP.
Definition: Player.cpp:246
void SpectateEntity(cEntity *a_Target)
Spectates the target entity.
Definition: Player.cpp:1471
void SendSystemMessage(const AString &a_Message)
Definition: Player.cpp:1263
void UpdateCapabilities()
Updates player's capabilities - flying, visibility, etc.
Definition: Player.cpp:1346
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
Definition: Player.cpp:3157
void SendMessageFatal(const AString &a_Message)
Definition: Player.cpp:1227
void AbortEating(void)
Aborts the current eating operation.
Definition: Player.cpp:551
static bool PermissionMatches(const AStringVector &a_Permission, const AStringVector &a_Template)
Returns true iff a_Permission matches the a_Template.
Definition: Player.cpp:1622
std::string m_DefaultWorldPath
The save path of the default world.
Definition: Player.h:670
void SetIsFishing(bool a_IsFishing, UInt32 a_FloaterID=cEntity::INVALID_ID)
Definition: Player.h:388
void SaveToDisk(void)
Saves all player data, such as inventory, to JSON.
Definition: Player.cpp:1933
virtual bool IsInvisible() const override
Definition: Player.cpp:2976
int FinishChargingBow(void)
Finishes charging the current bow.
Definition: Player.cpp:324
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
Definition: Player.cpp:1123
void AddKnownItem(const cItem &a_Item)
Adds an Item to the list of known items.
Definition: Player.cpp:2708
double GetEyeHeight(void) const
Definition: Player.cpp:992
float GetDigSpeed(BLOCKTYPE a_Block)
Returns the dig speed using the current tool on the block a_Block.
Definition: Player.cpp:2607
AStringVector m_Permissions
All the permissions that this player has, based on their rank.
Definition: Player.h:618
bool IsGameModeSurvival(void) const
Returns true if the player is in Survival mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1034
virtual void ApplyArmorDamage(int DamageBlocked) override
Applies damage to the armor after the armor blocked the given amount.
Definition: Player.cpp:2848
void OpenHorseInventory()
Opens the inventory of any tame horse the player is riding.
Definition: Player.cpp:1904
std::set< cItem, cItem::sItemCompare > m_KnownItems
List of known items as Ids.
Definition: Player.h:754
void TossPickup(const cItem &a_Item)
tosses a pickup newly created from a_Item
Definition: Player.cpp:1791
bool IsFishing(void) const
Returns true if the player has thrown out a floater.
Definition: Player.h:386
virtual bool IsElytraFlying(void) const override
Definition: Player.cpp:2967
void SendMessageFailure(const AString &a_Message)
Definition: Player.cpp:1200
void LoadRank(void)
(Re)loads the rank and permissions from the cRankManager and sends a permission level update to the c...
Definition: Player.cpp:2312
int m_CurrentXp
Definition: Player.h:727
double m_FoodSaturationLevel
"Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel
Definition: Player.h:640
bool m_IsManuallyFrozen
Was the player frozen manually by a plugin or automatically by the server?
Definition: Player.h:711
int DeltaExperience(int a_Xp_delta)
Definition: Player.cpp:279
virtual bool CanFly(void) const
Returns wheter the player can fly or not.
Definition: Player.h:549
std::shared_ptr< cClientHandle > m_ClientHandle
Definition: Player.h:677
double GetFlyingMaxSpeed(void) const
Gets the flying relative maximum speed.
Definition: Player.h:475
void AddKnownRecipe(UInt32 RecipeId)
Add the recipe Id to the known recipes.
Definition: Player.cpp:2734
int m_FoodLevel
Represents the food bar, one point equals half a "drumstick".
Definition: Player.h:637
void SetBedPos(Vector3i a_Position)
Sets the player's bed position to the specified position.
Definition: Player.cpp:786
void SetFoodTickTimer(int a_FoodTickTimer)
Definition: Player.cpp:405
AString GetSuffix(void) const
Returns the player name suffix, may contain @ format directives.
Definition: Player.cpp:1676
int GetXpLevel(void) const
Gets the current level - XpLevel.
Definition: Player.cpp:237
void SetSprintingMaxSpeed(double a_Speed)
Sets the sprinting relative maximum speed.
Definition: Player.cpp:626
virtual void Heal(int a_Health) override
Heals the player by the specified amount of HPs (positive only); sends health update.
Definition: Player.cpp:369
void UseItem(int a_SlotNumber, short a_Damage=1)
Damage the item in a_SlotNumber by a_Damage, possibly less if the equipped item is enchanted.
Definition: Player.cpp:2063
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &) override
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
Definition: Player.h:800
void SetFlyingMaxSpeed(double a_Speed)
Sets the flying relative maximum speed.
Definition: Player.cpp:641
void TickFreezeCode()
Definition: Player.cpp:2749
const AString & GetLoadedWorldName() const
Definition: Player.h:429
void NotifyNearbyWolves(cPawn *a_Opponent, bool a_IsPlayerInvolved)
Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an en...
Definition: Player.cpp:831
static const int MAX_HEALTH
Definition: Player.h:85
AString GetIP(void) const
Definition: Player.cpp:1070
virtual bool IsCrouched(void) const override
Definition: Player.cpp:2949
bool IsLeftHanded() const
Returns true if the player's left hand is dominant.
Definition: Player.cpp:460
bool m_IsTeleporting
Flag used by food handling system to determine whether a teleport has just happened.
Definition: Player.h:718
int m_LifetimeTotalXp
Player Xp level.
Definition: Player.h:726
const AString & GetCustomName(void) const
Returns the custom name of this player.
Definition: Player.h:508
void TossEquippedItem(char a_Amount=1)
tosses the item in the selected hotbar slot
Definition: Player.cpp:1720
void StartChargingBow(void)
Starts charging the equipped bow.
Definition: Player.cpp:312
static int CalcLevelFromXp(int a_CurrentXp)
Inverse of XpForLevel Ref: https://minecraft.wiki/w/XP values are as per this with pre-calculations.
Definition: Player.cpp:184
bool m_IsFlying
Definition: Player.h:702
cItem m_DraggingItem
The item being dragged by the cursor while in a UI window.
Definition: Player.h:675
UInt32 GetFloaterID(void) const
Definition: Player.h:390
AString GetUUIDFileName(const cUUID &a_UUID)
Returns the filename for the player data based on the UUID given.
Definition: Player.cpp:2514
void SetDraggingItem(const cItem &a_Item)
In UI windows, set the item that the player is dragging.
Definition: Player.cpp:1707
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1025
unsigned int m_EnchantmentSeed
Definition: Player.h:728
bool IsClimbing(void) const
Returns whether the player is climbing (ladders, vines etc.)
Definition: Player.cpp:2191
void SetRespawnPosition(Vector3i a_Position, const cWorld &a_World)
Sets the player's forced respawn position and world.
Definition: Player.cpp:806
virtual ~cPlayer() override
Definition: Player.cpp:155
cWindow * m_InventoryWindow
Definition: Player.h:655
virtual cItem GetOffHandEquipedItem(void) const override
Returns the currently offhand equipped item; empty item if none.
Definition: Player.h:602
cTickTimeLong m_EatingFinishTick
The world tick in which eating will be finished.
Definition: Player.h:723
cInventory & GetInventory(void)
Definition: Player.h:156
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
Definition: Player.cpp:855
void TossHeldItem(char a_Amount=1)
tosses the item held in hand (when in UI windows)
Definition: Player.cpp:1764
eGameMode GetGameMode(void) const
Returns the current gamemode.
Definition: Player.h:199
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override
Teleports to the coordinates specified.
Definition: Player.cpp:1404
void SetVisible(bool a_bVisible)
Definition: Player.cpp:1549
void FreezeInternal(const Vector3d &a_Location, bool a_ManuallyFrozen)
Pins the player to a_Location until Unfreeze() is called.
Definition: Player.cpp:2530
virtual void OnDetach() override
Called when this entity dismounts from m_AttachedTo.
Definition: Player.cpp:3036
cItem & GetDraggingItem(void)
In UI windows, get the item that the player is dragging.
Definition: Player.h:448
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr) override
Updates clients of changes in the entity.
Definition: Player.cpp:2862
void AddFoodExhaustion(double a_Exhaustion)
Adds the specified exhaustion to m_FoodExhaustion.
Definition: Player.cpp:439
bool CanMobsTarget(void) const
Returns true if the player can be targeted by Mobs.
Definition: Player.cpp:1061
void SetFoodLevel(int a_FoodLevel)
Definition: Player.cpp:379
static const int MAX_FOOD_LEVEL
Definition: Player.h:87
Vector3d GetThrowSpeed(double a_SpeedCoeff) const
Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff.
Definition: Player.cpp:1517
void Freeze(const Vector3d &a_Location)
Prevent the player from moving and lock him into a_Location.
Definition: Player.cpp:1423
bool IsInBed(void) const
Returns true if a player is sleeping in a bed.
Definition: Player.cpp:451
std::vector< std::vector< AString > > AStringVectorVector
Definition: Player.h:609
AStringVector m_Restrictions
All the restrictions that this player has, based on their rank.
Definition: Player.h:621
cEntity * m_Spectating
The entity that this player is spectating, nullptr if none.
Definition: Player.h:737
void PermuteEnchantmentSeed()
Permute the seed for enchanting related PRNGs, don't use this for other purposes.
Definition: Player.cpp:1576
void SetSkinParts(int a_Parts)
Definition: Player.cpp:2504
double GetNormalMaxSpeed(void) const
Gets the normal relative maximum speed.
Definition: Player.h:469
bool IsGameModeSpectator(void) const
Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current wor...
Definition: Player.cpp:1052
void SetLeftHanded(bool a_IsLeftHanded)
Sets the dominant hand of the player.
Definition: Player.cpp:719
cItemGrid & GetEnderChestContents(void)
Gets the contents of the player's associated enderchest.
Definition: Player.h:160
int m_FoodTickTimer
Count-up to the healing or damaging action, based on m_FoodLevel.
Definition: Player.h:643
bool CanInstantlyMine(BLOCKTYPE a_Block)
Given tool, enchantments, status effects, and world position returns whether a_Block would be instant...
Definition: Player.cpp:2696
bool HasPermission(const AString &a_Permission) const
Definition: Player.cpp:1586
bool IsFlying(void) const
Returns true if the player is currently flying.
Definition: Player.h:377
double GetFoodExhaustionLevel(void) const
Definition: Player.h:357
bool IsInsideWater()
Checks if the player is inside of water.
Definition: Player.cpp:2578
int GetXpLifetimeTotal(void)
Gets the experience total - XpTotal for score on death.
Definition: Player.h:114
void SendMessageSuccess(const AString &a_Message)
Definition: Player.cpp:1209
bool IsEating(void) const
Returns true if the player is currently in the process of eating the currently equipped item.
Definition: Player.h:374
const std::set< UInt32 > & GetKnownRecipes() const
Gets the set of IDs for recipes this player has discovered.
Definition: Player.cpp:206
void SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
Definition: Player.cpp:414
int GetFoodLevel(void) const
Definition: Player.h:354
void SetTeam(cTeam *a_Team)
Sets the player team, nullptr if none.
Definition: Player.cpp:1079
void SetElytraFlight(bool a_ShouldElytraFly)
Starts or stops elytra flight, if our current body stance permits, broadcasting the state change.
Definition: Player.cpp:682
AString m_Rank
The name of the rank assigned to this player.
Definition: Player.h:615
virtual void OnAddToWorld(cWorld &a_World) override
Called when the entity is added to a world.
Definition: Player.cpp:2985
virtual float GetEnchantmentBlastKnockbackReduction() override
Returns explosion knock back reduction percent from blast protection level.
Definition: Player.cpp:2932
void SendMessageRaw(const AString &a_MessageRaw, eChatType a_Type=eChatType::ctChatBox)
Definition: Player.cpp:1254
cWindow * GetWindow(void)
Definition: Player.h:262
void StartEating(void)
Starts eating the currently equipped item.
Definition: Player.cpp:514
void SetCrouch(bool a_ShouldCrouch)
Starts or stops crouching, if our current body stance permits, broadcasting the state change.
Definition: Player.cpp:656
void SendBlocksAround(Vector3i a_BlockPos, int a_Range=1)
Sends the block in the specified range around the specified coord to the client as a block change pac...
Definition: Player.cpp:2325
const cWindow * GetWindow(void) const
Definition: Player.h:263
cInventory m_Inventory
Stores the player's inventory, consisting of crafting grid, hotbar, and main slots.
Definition: Player.h:649
Vector3i m_RespawnPosition
The player's potential respawn position, initialised to world spawn by default.
Definition: Player.h:659
cWindow * m_CurrentWindow
Definition: Player.h:654
void SendMessagePrivateMsg(const AString &a_Message, const AString &a_Sender)
Definition: Player.cpp:1236
const AStringVector & GetPermissions(void) const
Returns all the permissions that the player has assigned to them.
Definition: Player.h:315
virtual cItem GetEquippedBoots(void) const override
Returns the currently equipped boots; empty item if none.
Definition: Player.h:601
void ForceSetSpeed(const Vector3d &a_Speed)
Forces the player to move in the given direction.
Definition: Player.cpp:1540
void CloseWindowIfID(char a_WindowID, bool a_CanRefuse=true)
Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow.
Definition: Player.cpp:1169
AStringVectorVector m_SplitRestrictions
All the restrictions that this player has, based on their rank, split into individual dot-delimited p...
Definition: Player.h:629
virtual void SpawnOn(cClientHandle &a_Client) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
Definition: Player.cpp:3137
void SetFoodSaturationLevel(double a_FoodSaturationLevel)
Definition: Player.cpp:396
cTeam * GetTeam(void)
Returns the associated team, nullptr if none.
Definition: Player.h:240
Vector3d GetEyePosition(void) const
Definition: Player.cpp:1001
virtual bool IsSprinting(void) const override
Definition: Player.cpp:2958
bool IsSatiated(void) const
Returns true if the player is satiated, i.
Definition: Player.h:360
virtual bool IsFireproof() const override
Returns true if the player is fireproof Stops players burning in creative or spectator modes.
Definition: Player.h:225
Vector3d GetThrowStartPos(void) const
Returns the position where projectiles thrown by this player should start, player eye position + adju...
Definition: Player.cpp:1501
void SetSprint(bool a_ShouldSprint)
Starts or stops sprinting, if our current body stance permits, broadcasting the state change.
Definition: Player.cpp:729
float GetLiquidHeightPercent(NIBBLETYPE a_Meta)
Returns how high the liquid is in percent.
Definition: Player.cpp:2565
AStringVectorVector m_SplitPermissions
All the permissions that this player has, based on their rank, split into individual dot-delimited pa...
Definition: Player.h:625
void Unfreeze()
Cancels Freeze(...) and allows the player to move naturally.
Definition: Player.cpp:1441
void SetCustomName(const AString &a_CustomName)
Sets the custom name of this player.
Definition: Player.cpp:763
const cTeam * GetTeam(void) const
Returns the associated team, nullptr if none.
Definition: Player.h:243
virtual cItem GetEquippedLeggings(void) const override
Returns the currently equipped leggings; empty item if none.
Definition: Player.h:600
AString GetPrefix(void) const
Returns the player name prefix, may contain @ format directives.
Definition: Player.cpp:1667
void ReplaceOneEquippedItemTossRest(const cItem &)
Removes one item from the the current equipped item stack, and attempts to add the specified item sta...
Definition: Player.cpp:1745
bool IsGameModeAdventure(void) const
Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current wor...
Definition: Player.cpp:1043
virtual cItem GetEquippedWeapon(void) const override
Returns the curently equipped weapon; empty item if none.
Definition: Player.h:597
AString GetPlayerListName(void) const
Returns the name that is used in the playerlist.
Definition: Player.cpp:1685
AString m_MsgSuffix
Definition: Player.h:632
void SetCanFly(bool a_CanFly)
If true the player can fly even when he's not in creative.
Definition: Player.cpp:748
void SetTouchGround(bool a_bTouchGround)
Definition: Player.cpp:351
virtual void OnRemoveFromWorld(cWorld &a_World) override
Called when the entity is removed from a world.
Definition: Player.cpp:3075
double m_FoodExhaustionLevel
A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel.
Definition: Player.h:646
StatisticsManager m_Stats
Definition: Player.h:739
MTRand GetEnchantmentRandomProvider()
Get a copy of the PRNG for enchanting related generation, don't use this for other purposes.
Definition: Player.cpp:1567
double GetMaxSpeed(void) const
Returns the current relative maximum speed (takes current sprinting / flying state into account)
Definition: Player.cpp:591
virtual bool IsRclking(void) const override
Definition: Player.h:803
void OnLoseSpectated()
Called when spectation stops, because the player crouched or when the entity we're spectating gets re...
Definition: Player.cpp:173
virtual bool DoTakeDamage(TakeDamageInfo &TDI) override
Makes this entity take damage specified in the a_TDI.
Definition: Player.cpp:2881
int m_BowCharge
Definition: Player.h:730
static int XpForLevel(int a_Level)
Calculates the amount of XP needed for a given level Ref: https://minecraft.wiki/w/XP.
Definition: Player.cpp:215
virtual bool IsOnGround(void) const override
Returns whether the entity is on ground or not.
Definition: Player.h:604
void FinishEating(void)
Finishes eating the currently equipped item.
Definition: Player.cpp:527
float GetMiningProgressPerTick(BLOCKTYPE a_Block)
Returns the progress mined per tick for the block a_Block as a fraction (1 would be completely mined)...
Definition: Player.cpp:2673
std::set< UInt32 > m_KnownRecipes
List on known recipes as Ids.
Definition: Player.h:751
const AStringVector & GetRestrictions(void) const
Returns all the restrictions that the player has assigned to them.
Definition: Player.h:318
eGameMode GetEffectiveGameMode(void) const
Returns the current effective gamemode (inherited gamemode is resolved before returning)
Definition: Player.cpp:1531
void UseEquippedItem(short a_Damage=1)
Damage the player's equipped item by a_Damage, possibly less if the equipped item is enchanted.
Definition: Player.cpp:2033
int GetFoodTickTimer(void) const
Definition: Player.h:356
cSlotNums m_InventoryPaintSlots
Definition: Player.h:679
double GetFoodSaturationLevel(void) const
Definition: Player.h:355
void SetIsInBed(bool a_IsInBed)
Sets a player's in-bed state.
Definition: Player.cpp:496
AString m_MsgPrefix
Definition: Player.h:632
bool m_IsRespawnPointForced
Whether we unconditionally respawn to m_RespawnPosition, or check if a bed is unobstructed and availa...
Definition: Player.h:714
bool m_IsVisible
Definition: Player.h:720
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Attempts to place the block in the world with a call to PlaceBlocks.
Definition: Player.cpp:2440
AString m_MsgNameColorCode
Definition: Player.h:633
void SetGameMode(eGameMode a_GameMode)
Sets the gamemode for the player.
Definition: Player.cpp:1308
bool IsChargingBow(void) const
Returns true if the player is currently charging the bow.
Definition: Player.h:151
Tag representing a sneaking pose.
Definition: Player.h:36
BodyStanceCrouching(cPlayer &a_Player)
Definition: Player.cpp:80
Tag representing a sleeping pose.
Definition: Player.h:43
BodyStanceSleeping(cPlayer &a_Player)
Definition: Player.cpp:89
Tag representing a sprinting pose.
Definition: Player.h:49
Tag representing the neutral stance.
Definition: Player.h:54
BodyStanceStanding(cPlayer &a_Player)
Definition: Player.cpp:98
Tag representing a swimming or elytra flying pose.
Definition: Player.h:60
cTickTime TicksElytraFlying
Definition: Player.h:63
BodyStanceGliding(cPlayer &a_Player)
Definition: Player.cpp:107
Class to wrap any random engine to provide a more convenient interface.
Definition: FastRandom.h:58
This class represents the player's inventory The slots are divided into three areas:
Definition: Inventory.h:36
const cItem & GetEquippedChestplate(void) const
Definition: Inventory.h:177
const cItem & GetEquippedBoots(void) const
Definition: Inventory.h:179
const cItem & GetEquippedHelmet(void) const
Definition: Inventory.h:176
const cItem & GetEquippedItem(void) const
Returns current equiped item.
Definition: Inventory.cpp:463
const cItem & GetShieldSlot() const
Returns current item in shield slot.
Definition: Inventory.cpp:454
const cItem & GetEquippedLeggings(void) const
Definition: Inventory.h:178
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
eDurabilityLostAction
Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on ...
Definition: ItemHandler.h:31
Class that manages the statistics and achievements of a single player.
Represents a UI window.
Definition: Window.h:54
Definition: UUID.h:11
Definition: World.h:53