Cuberite
A lightweight, fast and extensible game server for Minecraft
Entity.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../BoundingBox.h"
5 #include "../Item.h"
6 #include "../OSSupport/AtomicUniquePtr.h"
7 
8 
9 
10 
11 
12 // Place this macro in the public section of each cEntity descendant class and you're done :)
13 #define CLASS_PROTODEF(classname) \
14  virtual bool IsA(const char * a_ClassName) const override\
15  { \
16  return ((a_ClassName != nullptr) && ((strcmp(a_ClassName, #classname) == 0) || Super::IsA(a_ClassName))); \
17  } \
18  virtual const char * GetClass(void) const override \
19  { \
20  return #classname; \
21  } \
22  static const char * GetClassStatic(void) \
23  { \
24  return #classname; \
25  } \
26  virtual const char * GetParentClass(void) const override \
27  { \
28  return Super::GetClass(); \
29  }
30 
31 #define POSX_TOINT FloorC(GetPosX())
32 #define POSY_TOINT FloorC(GetPosY())
33 #define POSZ_TOINT FloorC(GetPosZ())
34 #define POS_TOINT GetPosition().Floor()
35 
36 #define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) \
37  cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); \
38  do { \
39  if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) \
40  { \
41  return; \
42  } \
43  } while (false)
44 
45 
46 
47 
48 class cWorld;
49 class cClientHandle;
50 class cPlayer;
51 class cChunk;
52 class cMonster;
53 
54 
55 
56 
57 
58 // tolua_begin
60 {
61  eDamageType DamageType; // Where does the damage come from? Being hit / on fire / contact with cactus / ...
62  cEntity * Attacker; // The attacking entity; valid only for dtAttack
63  int RawDamage; // What damage would the receiver get without any armor. Usually: attacker mob type + weapons
64  float FinalDamage; // What actual damage will be received. Usually: m_RawDamage minus armor
65  Vector3d Knockback; // The amount and direction of knockback received from the damage
66  // TODO: Effects - list of effects that the hit is causing. Unknown representation yet
67 } ;
68 // tolua_end
69 
70 
71 
72 
73 
74 // tolua_begin
75 class cEntity
76 {
77 protected:
80  {
84  };
85 
86 public:
87 
89  {
90  etEntity, // For all other types
105 
106  // Common variations
107  etMob = etMonster, // DEPRECATED, use etMonster instead!
108  } ;
109 
110  // tolua_end
111 
112  static const int FIRE_TICKS_PER_DAMAGE = 10;
113  static const int FIRE_DAMAGE = 1;
114  static const int LAVA_TICKS_PER_DAMAGE = 10;
115  static const int LAVA_DAMAGE = 4;
116  static const int BURN_TICKS_PER_DAMAGE = 20;
117  static const int BURN_DAMAGE = 1;
118 
119  static const int BURN_TICKS = 160;
120 
121  static const int MAX_AIR_LEVEL = 300;
122  static const int DROWNING_TICKS = 20;
123 
124  static const int VOID_BOUNDARY = -64;
125  static const int FALL_DAMAGE_HEIGHT = 4;
126 
128  static const UInt32 INVALID_ID = 0; // Exported to Lua in ManualBindings.cpp, ToLua doesn't parse initialized constants.
129 
130 
131  cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height);
132  virtual ~cEntity() = default;
133 
136  bool Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld);
137 
139  void OnAcquireSpectator(cPlayer & a_Player);
140 
144  virtual void OnAddToWorld(cWorld & a_World);
145 
147  void OnLoseSpectator(cPlayer & a_Player);
148 
152  virtual void OnRemoveFromWorld(cWorld & a_World);
153 
154  // tolua_begin
155 
156  eEntityType GetEntityType(void) const { return m_EntityType; }
157 
158  bool IsArrow (void) const { return IsA("cArrowEntity"); }
159  bool IsEnderCrystal(void) const { return (m_EntityType == etEnderCrystal); }
160  bool IsPlayer (void) const { return (m_EntityType == etPlayer); }
161  bool IsPickup (void) const { return (m_EntityType == etPickup); }
162  bool IsMob (void) const { return (m_EntityType == etMonster); }
163  bool IsPawn (void) const { return (IsMob() || IsPlayer()); }
164  bool IsFallingBlock(void) const { return (m_EntityType == etFallingBlock); }
165  bool IsMinecart (void) const { return (m_EntityType == etMinecart); }
166  bool IsBoat (void) const { return (m_EntityType == etBoat); }
167  bool IsTNT (void) const { return (m_EntityType == etTNT); }
168  bool IsProjectile (void) const { return (m_EntityType == etProjectile); }
169  bool IsExpOrb (void) const { return (m_EntityType == etExpOrb); }
170  bool IsFloater (void) const { return (m_EntityType == etFloater); }
171  bool IsItemFrame (void) const { return (m_EntityType == etItemFrame); }
172  bool IsLeashKnot (void) const { return (m_EntityType == etLeashKnot); }
173  bool IsPainting (void) const { return (m_EntityType == etPainting); }
174 
176  virtual bool IsA(const char * a_ClassName) const;
177 
179  static const char * GetClassStatic(void);
180 
182  virtual const char * GetClass(void) const;
183 
185  virtual const char * GetParentClass(void) const;
186 
188  virtual bool DoesPreventBlockPlacement(void) const { return true; }
189 
190  cWorld * GetWorld(void) const { return m_World; }
191 
192  double GetHeadYaw (void) const { return m_HeadYaw; } // In degrees
193  float GetHeight (void) const { return m_Height; }
194  double GetMass (void) const { return m_Mass; }
195  double GetPosX (void) const { return m_Position.x; }
196  double GetPosY (void) const { return m_Position.y; }
197  double GetPosZ (void) const { return m_Position.z; }
198  double GetYaw (void) const { return m_Rot.x; } // In degrees, [-180, +180)
199  double GetPitch (void) const { return m_Rot.y; } // In degrees, [-180, +180), but normal client clips to [-90, +90]
200  double GetRoll (void) const { return m_Rot.z; } // In degrees, unused in current client
201  Vector3d GetLookVector(void) const;
202  double GetSpeedX (void) const { return m_Speed.x; }
203  double GetSpeedY (void) const { return m_Speed.y; }
204  double GetSpeedZ (void) const { return m_Speed.z; }
205  float GetWidth (void) const { return m_Width; }
206 
207  int GetChunkX(void) const { return FloorC(m_Position.x / cChunkDef::Width); }
208  int GetChunkZ(void) const { return FloorC(m_Position.z / cChunkDef::Width); }
209 
210  // Get the Entity's axis aligned bounding box, with absolute (world-relative) coordinates.
212 
213  void SetHeadYaw (double a_HeadYaw);
214  void SetMass (double a_Mass);
215  void SetPosX (double a_PosX) { SetPosition({a_PosX, m_Position.y, m_Position.z}); }
216  void SetPosY (double a_PosY) { SetPosition({m_Position.x, a_PosY, m_Position.z}); }
217  void SetPosZ (double a_PosZ) { SetPosition({m_Position.x, m_Position.y, a_PosZ}); }
218  void SetPosition(double a_PosX, double a_PosY, double a_PosZ) { SetPosition({a_PosX, a_PosY, a_PosZ}); }
219  void SetPosition(const Vector3d & a_Position);
220  void SetYaw (double a_Yaw); // In degrees, normalizes to [-180, +180)
221  void SetPitch (double a_Pitch); // In degrees, normalizes to [-180, +180)
222  void SetRoll (double a_Roll); // In degrees, normalizes to [-180, +180)
223 
225  void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ);
226 
228  void SetSpeed(Vector3d a_Speed) { SetSpeed(a_Speed.x, a_Speed.y, a_Speed.z); }
229 
231  void SetSpeedX(double a_SpeedX);
232 
234  void SetSpeedY(double a_SpeedY);
235 
237  void SetSpeedZ(double a_SpeedZ);
238 
239  void AddPosX (double a_AddPosX) { AddPosition(a_AddPosX, 0, 0); }
240  void AddPosY (double a_AddPosY) { AddPosition(0, a_AddPosY, 0); }
241  void AddPosZ (double a_AddPosZ) { AddPosition(0, 0, a_AddPosZ); }
242  void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ) { SetPosition(m_Position + Vector3d(a_AddPosX, a_AddPosY, a_AddPosZ)); }
243  void AddPosition(const Vector3d & a_AddPos) { AddPosition(a_AddPos.x, a_AddPos.y, a_AddPos.z); }
244  void AddSpeed (double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ);
245  void AddSpeed (const Vector3d & a_AddSpeed) { AddSpeed(a_AddSpeed.x, a_AddSpeed.y, a_AddSpeed.z); }
246  void AddSpeedX (double a_AddSpeedX);
247  void AddSpeedY (double a_AddSpeedY);
248  void AddSpeedZ (double a_AddSpeedZ);
249 
250  virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways);
251  void SteerVehicle(float a_Forward, float a_Sideways);
252 
253  inline UInt32 GetUniqueID(void) const { return m_UniqueID; }
254 
256  inline bool IsDestroyed() const {return !IsTicking();}
257 
261  bool IsTicking(void) const;
262 
263  // tolua_end
265  void Destroy();
266  // tolua_begin
267 
269  void TakeDamage(cEntity & a_Attacker);
270 
272  void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, double a_KnockbackAmount);
273 
275  void TakeDamage(eDamageType a_DamageType, UInt32 a_Attacker, int a_RawDamage, double a_KnockbackAmount);
276 
278  void TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, float a_FinalDamage, double a_KnockbackAmount);
279 
280  float GetGravity(void) const { return m_Gravity; }
281 
282  void SetGravity(float a_Gravity) { m_Gravity = a_Gravity; }
283 
284  float GetAirDrag(void) const { return m_AirDrag; }
285 
286  void SetAirDrag(float a_AirDrag) { m_AirDrag = a_AirDrag; }
287 
289  void SetYawFromSpeed(void);
290 
292  void SetPitchFromSpeed(void);
293 
294  // tolua_end
295 
297  const Vector3d & GetPosition(void) const { return m_Position; }
298 
300  const Vector3d & GetSpeed(void) const { return m_Speed; }
301 
305 
309  virtual bool DoTakeDamage(TakeDamageInfo & a_TDI);
310 
311  // tolua_begin
312 
314  virtual int GetRawDamageAgainst(const cEntity & a_Receiver);
315 
317  virtual bool ArmorCoversAgainst(eDamageType a_DamageType);
318 
320  virtual float GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_RawDamage);
321 
323  virtual float GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage);
324 
328 
330  virtual double GetKnockbackAmountAgainst(const cEntity & a_Receiver);
331 
333  virtual cItem GetEquippedWeapon(void) const { return cItem(); }
334 
336  virtual cItem GetEquippedHelmet(void) const { return cItem(); }
337 
339  virtual cItem GetEquippedChestplate(void) const { return cItem(); }
340 
342  virtual cItem GetEquippedLeggings(void) const { return cItem(); }
343 
345  virtual cItem GetEquippedBoots(void) const { return cItem(); }
346 
348  virtual cItem GetOffHandEquipedItem(void) const { return cItem(); }
349 
351  virtual void ApplyArmorDamage(int DamageBlocked);
352 
353  // tolua_end
354 
356  virtual void KilledBy(TakeDamageInfo & a_TDI);
357 
358  // tolua_begin
359 
361  virtual void Killed(const cEntity & a_Victim, eDamageType a_DamageType) {}
362 
364  virtual void Heal(int a_HitPoints);
365 
367  float GetHealth(void) const { return m_Health; }
368 
370  void SetHealth(float a_Health);
371 
372  // tolua_end
373 
374  virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
375 
377  virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
378 
380  virtual void TickBurning(cChunk & a_Chunk);
381 
383  virtual void DetectCacti(void);
384 
386  virtual void DetectMagma(void);
387 
391  virtual bool DetectPortal(void);
392 
394  virtual void TickInVoid(cChunk & a_Chunk);
395 
397  virtual void OnStartedBurning(void);
398 
400  virtual void OnFinishedBurning(void);
401 
402  // tolua_begin
403 
405  void SetMaxHealth(float a_MaxHealth);
406 
407  float GetMaxHealth(void) const { return m_MaxHealth; }
408 
410  void SetIsFireproof(bool a_IsFireproof);
411 
412  virtual bool IsFireproof(void) const { return m_IsFireproof; }
413 
415  void StartBurning(int a_TicksLeftBurning);
416 
418  void StopBurning(void);
419 
420  // tolua_end
421 
424  virtual void SpawnOn(cClientHandle & a_Client) = 0;
425 
426  // tolua_begin
427 
429  virtual void TeleportToEntity(cEntity & a_Entity);
430 
432  virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ);
433 
434  bool MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown = false, bool a_ShouldSendRespawn = true);
435 
436  bool MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
437  {
438  return MoveToWorld(a_World, a_NewPosition, false, a_ShouldSendRespawn);
439  }
440 
442  bool MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn = true);
443 
445  bool MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn = true);
446 
447  // tolua_end
448 
451  {
452  return (m_WorldChangeInfo.m_NewWorld != nullptr);
453  }
454 
456  virtual void BroadcastMovementUpdate(const cClientHandle * a_Exclude = nullptr);
457 
459  cEntity * GetAttached();
460 
462  void AttachTo(cEntity & a_AttachTo);
463 
465  void Detach(void);
466 
468  bool IsAttachedTo(const cEntity * a_Entity) const;
469 
472  bool IsOrientationDirty() const;
473 
475  void WrapHeadYaw();
476 
478  void WrapRotation();
479 
481  void WrapSpeed();
482 
483  // tolua_begin
484 
485  // COMMON metadata flags; descendants may override the defaults:
486  virtual bool IsCrouched (void) const { return false; }
487  virtual bool IsElytraFlying(void) const { return false; }
488  virtual bool IsInvisible (void) const { return false; }
489  virtual bool IsOnFire (void) const { return m_TicksLeftBurning > 0; }
490  virtual bool IsRclking (void) const { return false; }
491  virtual bool IsRiding (void) const { return false; }
492  virtual bool IsSprinting (void) const { return false; }
493 
495  virtual bool IsInFire(void) const { return m_IsInFire; }
496 
498  virtual bool IsInLava(void) const { return m_IsInLava; }
499 
501  virtual bool IsInWater(void) const { return m_IsInWater; }
502 
504  virtual bool IsHeadInWater(void) const { return m_IsHeadInWater; }
505 
507  int GetAirLevel(void) const { return m_AirLevel; }
508 
510  long int GetTicksAlive(void) const { return m_TicksAlive; }
511 
513  int GetInvulnerableTicks(void) const { return m_InvulnerableTicks; }
514 
516  void SetInvulnerableTicks(int a_InvulnerableTicks) { m_InvulnerableTicks = a_InvulnerableTicks; }
517 
519  virtual bool IsOnGround(void) const { return m_bOnGround; }
520 
521  // tolua_end
522 
524  virtual void OnRightClicked(cPlayer & a_Player) {}
525 
527  virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr)
528  {
529  UNUSED(a_Drops);
530  UNUSED(a_Killer);
531  }
532 
534  void SetWorld(cWorld * a_World) { m_World = a_World; }
535 
538  void SetParentChunk(cChunk * a_Chunk);
539 
542  const cChunk * GetParentChunk() const { return m_ParentChunk; }
543 
545  void SetIsTicking(bool a_IsTicking);
546 
548  void SetSize(float a_Width, float a_Height);
549 
551  void AddLeashedMob(cMonster * a_Monster);
552 
554  void RemoveLeashedMob(cMonster * a_Monster);
555 
557  bool HasAnyMobLeashed() const { return m_LeashedMobs.size() > 0; }
558 
561 
562 protected:
563 
566  {
568  unsigned short m_TicksDelayed;
569 
573  };
574 
575 
578 
583 
584  float m_Health;
585  float m_MaxHealth;
586 
589 
592 
595 
598 
602 
605 
608  float m_Gravity;
609 
614  float m_AirDrag;
615 
619 
621 
623 
625 
628 
631 
634 
637 
640 
643 
646 
649 
652 
655 
658 
662 
665 
667  long int m_TicksAlive;
668 
671  void DoMoveToWorld(const sWorldChangeInfo & a_WorldChangeInfo);
672 
676  static void ApplyFriction(Vector3d & a_Speed, double a_SlowdownMultiplier, float a_Dt);
677 
679  virtual void HandleAir(void);
680 
683  virtual void SetSwimState(cChunk & a_Chunk);
684 
687  virtual void ResetPosition(Vector3d a_NewPos);
688 
690  void BroadcastLeashedMobs();
691 
693  virtual void OnDetach();
694 
695 private:
696 
699 
702 
704  double m_HeadYaw;
705 
708 
711 
714 
716  double m_Mass;
717 
719  float m_Width;
720 
722  float m_Height;
723 
727 
728  typedef std::list<cMonster *> cMonsterList;
729 
732 
734  std::vector<cPlayer *> m_Spectators;
735 } ; // tolua_export
std::unique_ptr< cEntity > OwnedEntity
Definition: ChunkDef.h:32
eDamageType
Damage type, used in the TakeDamageInfo structure and related functions.
Definition: Defines.h:244
unsigned int UInt32
Definition: Globals.h:157
#define UNUSED
Definition: Globals.h:72
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
Definition: Globals.h:347
std::string AString
Definition: StringUtils.h:11
Vector3< double > Vector3d
Definition: Vector3.h:485
Represents two sets of coords, minimum and maximum for each direction.
Definition: BoundingBox.h:24
Definition: Chunk.h:36
static const int Width
Definition: ChunkDef.h:124
cEntity * Attacker
Definition: Entity.h:62
Vector3d Knockback
Definition: Entity.h:65
int RawDamage
Definition: Entity.h:63
eDamageType DamageType
Definition: Entity.h:61
float FinalDamage
Definition: Entity.h:64
Definition: Entity.h:76
void AddPosZ(double a_AddPosZ)
Definition: Entity.h:241
bool IsProjectile(void) const
Definition: Entity.h:168
virtual const char * GetParentClass(void) const
Returns the topmost class's parent class name for the object.
Definition: Entity.cpp:102
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
Teleports to the coordinates specified.
Definition: Entity.cpp:1953
virtual void DetectMagma(void)
Detects the time for application of magma block damage.
Definition: Entity.cpp:1392
Vector3d m_LastSentPosition
Last position sent to client via the Relative Move or Teleport packets (not Velocity) Only updated if...
Definition: Entity.h:618
void AddPosition(const Vector3d &a_AddPos)
Definition: Entity.h:243
void DoMoveToWorld(const sWorldChangeInfo &a_WorldChangeInfo)
Handles the moving of this entity between worlds.
Definition: Entity.cpp:1573
const Vector3d & GetSpeed(void) const
Exported in ManualBindings.
Definition: Entity.h:300
bool IsDestroyed() const
Deprecated.
Definition: Entity.h:256
static const int FIRE_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it stands in fire.
Definition: Entity.h:112
float m_Health
Definition: Entity.h:584
virtual bool IsElytraFlying(void) const
Definition: Entity.h:487
virtual bool IsRclking(void) const
Definition: Entity.h:490
bool m_IsFireproof
Whether the entity is capable of taking fire or lava damage.
Definition: Entity.h:630
void SetPitch(double a_Pitch)
Definition: Entity.cpp:2136
void SetIsTicking(bool a_IsTicking)
Set the entity's status to either ticking or not ticking.
Definition: Entity.cpp:1778
int GetChunkZ(void) const
Definition: Entity.h:208
void SetSpeed(Vector3d a_Speed)
Sets the speed of the entity, measured in m / sec.
Definition: Entity.h:228
void AddPosY(double a_AddPosY)
Definition: Entity.h:240
void AddSpeedX(double a_AddSpeedX)
Definition: Entity.cpp:2203
virtual void OnAddToWorld(cWorld &a_World)
Called when the entity is added to a world.
Definition: Entity.cpp:147
bool IsPlayer(void) const
Definition: Entity.h:160
Vector3d m_LastPosition
Definition: Entity.h:620
void SteerVehicle(float a_Forward, float a_Sideways)
Definition: Entity.cpp:2243
cBoundingBox GetBoundingBox() const
Definition: Entity.h:211
bool IsPainting(void) const
Definition: Entity.h:173
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
Definition: Entity.cpp:909
void SetHeadYaw(double a_HeadYaw)
Definition: Entity.cpp:2102
bool m_IsInWater
If any part of the entity is in a water block.
Definition: Entity.h:654
cEntity * m_Attachee
The entity which is attached to this entity (rider), nullptr if none.
Definition: Entity.h:591
void BroadcastDeathMessage(TakeDamageInfo &a_TDI)
Announces a death message on chat about killing the entity.
Definition: Entity.cpp:2349
bool IsPickup(void) const
Definition: Entity.h:161
bool IsAttachedTo(const cEntity *a_Entity) const
Returns true if this entity is attached to the specified entity.
Definition: Entity.cpp:2081
void SetRoll(double a_Roll)
Definition: Entity.cpp:2147
virtual float GetEnchantmentBlastKnockbackReduction()
Returns explosion knock back reduction percent from blast protection level.
Definition: Entity.cpp:744
void SetSpeedX(double a_SpeedX)
Sets the speed in the X axis, leaving the other speed components intact.
Definition: Entity.cpp:2167
Vector3d m_WaterSpeed
Measured in meter / second.
Definition: Entity.h:713
float m_AirDrag
Stores the air drag that is applied to the entity every tick, measured in speed ratio per tick Acts a...
Definition: Entity.h:614
void Detach(void)
Detaches from the currently attached entity, if any.
Definition: Entity.cpp:2052
int m_InvulnerableTicks
If a player hit a entity, the entity receive a invulnerable of 10 ticks.
Definition: Entity.h:726
virtual void OnStartedBurning(void)
Called when the entity starts burning.
Definition: Entity.cpp:1867
virtual bool IsInWater(void) const
Returns true if any part of the entity is in a water block.
Definition: Entity.h:501
bool IsTNT(void) const
Definition: Entity.h:167
bool IsEnderCrystal(void) const
Definition: Entity.h:159
int m_TicksSinceLastBurnDamage
Time, in ticks, since the last damage dealt by being on fire.
Definition: Entity.h:633
virtual void TickInVoid(cChunk &a_Chunk)
Handles when the entity is in the void.
Definition: Entity.cpp:1346
static const int FIRE_DAMAGE
Damage to deal when standing in fire.
Definition: Entity.h:113
virtual double GetKnockbackAmountAgainst(const cEntity &a_Receiver)
Returns the knockback amount that the currently equipped items would cause to a_Receiver on a hit.
Definition: Entity.cpp:827
void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
Definition: Entity.cpp:2194
void WrapHeadYaw()
Makes sure head yaw is not over the specified range.
Definition: Entity.cpp:204
double GetSpeedZ(void) const
Definition: Entity.h:204
float m_Width
Width of the entity, in the XZ plane.
Definition: Entity.h:719
bool m_IsTicking
Whether the entity is ticking or not.
Definition: Entity.h:698
bool MoveToWorld(cWorld &a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown=false, bool a_ShouldSendRespawn=true)
Definition: Entity.cpp:1616
void SetYaw(double a_Yaw)
Definition: Entity.cpp:2125
cChunk * GetParentChunk()
Returns the chunk responsible for ticking this entity.
Definition: Entity.h:541
virtual bool IsCrouched(void) const
Definition: Entity.h:486
bool m_bDirtyOrientation
Stores whether our yaw / pitch / roll (body orientation) has been set manually.
Definition: Entity.h:597
static const int VOID_BOUNDARY
Y position to begin applying void damage.
Definition: Entity.h:124
float GetAirDrag(void) const
Definition: Entity.h:284
virtual bool IsInFire(void) const
Returns true if any part of the entity is in a fire block.
Definition: Entity.h:495
virtual cItem GetEquippedLeggings(void) const
Returns the currently equipped leggings; empty item if none.
Definition: Entity.h:342
void SetPitchFromSpeed(void)
Sets the pitch to match the speed vector (entity gies "face-forward")
Definition: Entity.cpp:387
cMonsterList m_LeashedMobs
List of leashed mobs to this entity.
Definition: Entity.h:731
float GetMaxHealth(void) const
Definition: Entity.h:407
Vector3d m_Rot
Measured in degrees, [-180, +180)
Definition: Entity.h:707
virtual void HandleAir(void)
Called in each tick to handle air-related processing i.e.
Definition: Entity.cpp:1798
int GetChunkX(void) const
Definition: Entity.h:207
virtual const char * GetClass(void) const
Returns the topmost class name for the object.
Definition: Entity.cpp:84
virtual bool DoesPreventBlockPlacement(void) const
Returns whether blocks can be placed intersecting this entities' hitbox.
Definition: Entity.h:188
void SetHealth(float a_Health)
Sets the health of this entity; doesn't broadcast any hurt animation.
Definition: Entity.cpp:900
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
Definition: Entity.h:128
double GetSpeedY(void) const
Definition: Entity.h:203
const cChunk * GetParentChunk() const
Definition: Entity.h:542
std::list< cMonster * > cMonsterList
Definition: Entity.h:728
int m_AirLevel
Air level of a mobile.
Definition: Entity.h:660
sPortalCooldownData m_PortalCooldownData
Portal delay timer and cooldown boolean data.
Definition: Entity.h:664
virtual void TickBurning(cChunk &a_Chunk)
Updates the state related to this entity being on fire.
Definition: Entity.cpp:1251
double GetRoll(void) const
Definition: Entity.h:200
static const char * GetClassStatic(void)
Returns the class name of this class.
Definition: Entity.cpp:93
void SetSpeedY(double a_SpeedY)
Sets the speed in the Y axis, leaving the other speed components intact.
Definition: Entity.cpp:2176
int m_TicksLeftBurning
Time, in ticks, until the entity extinguishes its fire.
Definition: Entity.h:642
virtual void TeleportToEntity(cEntity &a_Entity)
Teleports to the entity specified.
Definition: Entity.cpp:1944
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Definition: Entity.cpp:2259
Vector3d m_Position
Position of the entity's XZ center and Y bottom.
Definition: Entity.h:710
std::vector< cPlayer * > m_Spectators
List of players who are spectating this entity.
Definition: Entity.h:734
bool IsArrow(void) const
Definition: Entity.h:158
bool IsItemFrame(void) const
Definition: Entity.h:171
static const int BURN_DAMAGE
Damage to deal when the entity is burning.
Definition: Entity.h:117
float m_Gravity
Stores gravity that is applied to an entity every tick For realistic effects, this should be negative...
Definition: Entity.h:608
UInt32 m_UniqueID
The ID of the entity that is guaranteed to be unique within a single run of the server.
Definition: Entity.h:582
Vector3d GetLastSentPosition(void) const
Returns the last position we sent to all the clients.
Definition: Entity.h:304
float GetGravity(void) const
Definition: Entity.h:280
void SetSpeedZ(double a_SpeedZ)
Sets the speed in the Z axis, leaving the other speed components intact.
Definition: Entity.cpp:2185
eEntityType m_EntityType
Definition: Entity.h:622
float m_MaxHealth
Definition: Entity.h:585
void SetGravity(float a_Gravity)
Definition: Entity.h:282
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
Sets the speed of the entity, measured in m / sec.
Definition: Entity.cpp:2157
double GetPosX(void) const
Definition: Entity.h:195
virtual bool IsA(const char *a_ClassName) const
Returns true if the entity is of the specified class or a subclass (cPawn's IsA("cEntity") returns tr...
Definition: Entity.cpp:2072
float m_Height
Height of the entity (Y axis).
Definition: Entity.h:722
virtual cItem GetEquippedBoots(void) const
Returns the currently equipped boots; empty item if none.
Definition: Entity.h:345
sWorldChangeInfo m_WorldChangeInfo
If field m_NewWorld not nullptr, a world change is scheduled and a task is queued in the current worl...
Definition: Entity.h:627
virtual cItem GetOffHandEquipedItem(void) const
Returns the currently offhand equipped item; empty item if none.
Definition: Entity.h:348
void SetPosition(double a_PosX, double a_PosY, double a_PosZ)
Definition: Entity.h:218
virtual void DetectCacti(void)
Detects the time for application of cacti damage.
Definition: Entity.cpp:1363
int m_TicksSinceLastVoidDamage
Time, in ticks, since the last damage dealt by the void.
Definition: Entity.h:645
void AddSpeed(const Vector3d &a_AddSpeed)
Definition: Entity.h:245
virtual bool IsFireproof(void) const
Definition: Entity.h:412
void SetPosY(double a_PosY)
Definition: Entity.h:216
virtual void Killed(const cEntity &a_Victim, eDamageType a_DamageType)
Called when the entity kills another entity.
Definition: Entity.h:361
float GetWidth(void) const
Definition: Entity.h:205
cWorld * m_World
Definition: Entity.h:624
double GetPosZ(void) const
Definition: Entity.h:197
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
Definition: Entity.cpp:2230
virtual bool IsHeadInWater(void) const
Returns true if any part of the entity is in a water block.
Definition: Entity.h:504
virtual void SpawnOn(cClientHandle &a_Client)=0
Descendants override this function to send a command to the specified client to spawn the entity on t...
bool m_IsInLava
If any part of the entity is in a lava block.
Definition: Entity.h:651
bool IsMinecart(void) const
Definition: Entity.h:165
virtual void OnFinishedBurning(void)
Called when the entity finishes burning.
Definition: Entity.cpp:1877
bool Initialize(OwnedEntity a_Self, cWorld &a_EntityWorld)
Spawns the entity in the world; returns true if spawned, false if not (plugin disallowed).
Definition: Entity.cpp:111
virtual float GetEnchantmentCoverAgainst(const cEntity *a_Attacker, eDamageType a_DamageType, int a_Damage)
Returns the hitpoints that the currently equipped armor's enchantments would cover.
Definition: Entity.cpp:701
UInt32 GetUniqueID(void) const
Definition: Entity.h:253
void OnAcquireSpectator(cPlayer &a_Player)
Called when a player begins spectating this entity.
Definition: Entity.cpp:138
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
Definition: Entity.cpp:243
void WrapSpeed()
Makes speed is not over 20.
Definition: Entity.cpp:223
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr)
Returns the list of drops for this pawn when it is killed.
Definition: Entity.h:527
int GetAirLevel(void) const
Gets remaining air of a monster.
Definition: Entity.h:507
bool IsWorldChangeScheduled() const
Returns true if a world change is scheduled to happen.
Definition: Entity.h:450
void SetInvulnerableTicks(int a_InvulnerableTicks)
Set the invulnerable ticks from the entity.
Definition: Entity.h:516
double m_Mass
Measured in Kilograms (Kg)
Definition: Entity.h:716
eEntityType GetEntityType(void) const
Definition: Entity.h:156
double GetPitch(void) const
Definition: Entity.h:199
virtual bool IsOnFire(void) const
Definition: Entity.h:489
bool IsOrientationDirty() const
Returns whether the entity's orientation has been set manually.
Definition: Entity.cpp:2093
int m_AirTickTimer
Definition: Entity.h:661
static const int LAVA_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it stands in lava.
Definition: Entity.h:114
static const int BURN_TICKS
Ticks to keep an entity burning after it has stood in lava / fire.
Definition: Entity.h:119
void AddSpeedY(double a_AddSpeedY)
Definition: Entity.cpp:2212
void AddLeashedMob(cMonster *a_Monster)
Adds a mob to the leashed list of mobs.
Definition: Entity.cpp:2299
bool IsLeashKnot(void) const
Definition: Entity.h:172
int m_TicksSinceLastLavaDamage
Time, in ticks, since the last damage dealt by standing in lava.
Definition: Entity.h:636
double GetPosY(void) const
Definition: Entity.h:196
Vector3d m_Speed
Measured in meters / second (m / s)
Definition: Entity.h:577
void SetParentChunk(cChunk *a_Chunk)
Sets the parent chunk, which is the chunk responsible for ticking this entity.
Definition: Entity.cpp:234
int GetInvulnerableTicks(void) const
Gets the invulnerable ticks from the entity.
Definition: Entity.h:513
bool m_IsHeadInWater
If the entity's head is in a water block.
Definition: Entity.h:657
double GetMass(void) const
Definition: Entity.h:194
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
Definition: Entity.cpp:272
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
Definition: Entity.cpp:1001
virtual bool DetectPortal(void)
Detects whether we are in a portal block and begins teleportation procedures if so Returns true if Mo...
Definition: Entity.cpp:1421
void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
Definition: Entity.h:242
void AddPosX(double a_AddPosX)
Definition: Entity.h:239
void AddSpeedZ(double a_AddSpeedZ)
Definition: Entity.cpp:2221
bool IsPawn(void) const
Definition: Entity.h:163
double GetHeadYaw(void) const
Definition: Entity.h:192
virtual bool IsOnGround(void) const
Returns whether the entity is on ground or not.
Definition: Entity.h:519
bool m_IsInFire
If any part of the entity is in a fire block.
Definition: Entity.h:648
cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height)
Definition: Entity.cpp:37
void SetMass(double a_Mass)
Definition: Entity.cpp:2113
bool IsBoat(void) const
Definition: Entity.h:166
float GetHeight(void) const
Definition: Entity.h:193
void SetAirDrag(float a_AirDrag)
Definition: Entity.h:286
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
Definition: Entity.h:333
bool IsFallingBlock(void) const
Definition: Entity.h:164
void BroadcastLeashedMobs()
If has any mobs are leashed, broadcasts every leashed entity to this.
Definition: Entity.cpp:2325
static const int DROWNING_TICKS
Number of ticks per heart of damage.
Definition: Entity.h:122
bool IsExpOrb(void) const
Definition: Entity.h:169
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
Definition: Entity.cpp:851
void SetPosZ(double a_PosZ)
Definition: Entity.h:217
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI)
Makes this entity take damage specified in the a_TDI.
Definition: Entity.cpp:404
virtual void OnRemoveFromWorld(cWorld &a_World)
Called when the entity is removed from a world.
Definition: Entity.cpp:172
void SetPosX(double a_PosX)
Definition: Entity.h:215
bool MoveToWorld(cWorld &a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
Definition: Entity.h:436
bool m_bOnGround
Stores if the entity is on the ground.
Definition: Entity.h:604
virtual cItem GetEquippedHelmet(void) const
Returns the currently equipped helmet; empty item if none.
Definition: Entity.h:336
virtual bool ArmorCoversAgainst(eDamageType a_DamageType)
Returns whether armor will protect against the specified damage type.
Definition: Entity.cpp:661
double m_HeadYaw
Measured in degrees, [-180, +180)
Definition: Entity.h:704
cEntity * GetAttached()
Gets entity (vehicle) attached to this entity.
Definition: Entity.cpp:2018
void StopBurning(void)
Stops the entity from burning, resets all burning timers.
Definition: Entity.cpp:1925
bool IsFloater(void) const
Definition: Entity.h:170
long int GetTicksAlive(void) const
Gets number of ticks this entity has been alive for.
Definition: Entity.h:510
virtual bool IsInvisible(void) const
Definition: Entity.h:488
virtual void OnDetach()
Called when this entity dismounts from m_AttachedTo.
Definition: Entity.cpp:2341
static void ApplyFriction(Vector3d &a_Speed, double a_SlowdownMultiplier, float a_Dt)
Applies friction to an entity.
Definition: Entity.cpp:1230
double GetYaw(void) const
Definition: Entity.h:198
virtual bool IsInLava(void) const
Returns true if any part of the entity is in a lava block.
Definition: Entity.h:498
void SetIsFireproof(bool a_IsFireproof)
Sets whether the entity is fireproof.
Definition: Entity.cpp:1899
float GetHealth(void) const
Returns the health of this entity.
Definition: Entity.h:367
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
Definition: Entity.cpp:1887
virtual void OnRightClicked(cPlayer &a_Player)
Called when the specified player right-clicks this entity.
Definition: Entity.h:524
void WrapRotation()
Makes sure rotation is not over the specified range.
Definition: Entity.cpp:213
static const int FALL_DAMAGE_HEIGHT
Y difference after which fall damage is applied.
Definition: Entity.h:125
int m_TicksSinceLastFireDamage
Time, in ticks, since the last damage dealt by standing in fire.
Definition: Entity.h:639
virtual void ApplyArmorDamage(int DamageBlocked)
Applies damage to the armor after the armor blocked the given amount.
Definition: Entity.cpp:652
cChunk * m_ParentChunk
The chunk which is responsible for ticking this entity.
Definition: Entity.h:701
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
Definition: Entity.h:297
virtual void Heal(int a_HitPoints)
Heals the specified amount of HPs.
Definition: Entity.cpp:890
virtual bool IsRiding(void) const
Definition: Entity.h:491
virtual float GetArmorCoverAgainst(const cEntity *a_Attacker, eDamageType a_DamageType, int a_RawDamage)
Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover.
Definition: Entity.cpp:769
static const int LAVA_DAMAGE
Damage to deal when standing in lava.
Definition: Entity.h:115
virtual int GetRawDamageAgainst(const cEntity &a_Receiver)
Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items.
Definition: Entity.cpp:614
void SetSize(float a_Width, float a_Height)
Update an entity's size, for example, on body stance changes.
Definition: Entity.cpp:1788
virtual void SetSwimState(cChunk &a_Chunk)
Called once per tick to set m_IsInFire, m_IsInLava, m_IsInWater and m_IsHeadInWater.
Definition: Entity.cpp:1702
long int m_TicksAlive
The number of ticks this entity has been alive for.
Definition: Entity.h:667
void SetYawFromSpeed(void)
Sets the rotation to match the speed vector (entity goes "face-forward")
Definition: Entity.cpp:371
Vector3d GetLookVector(void) const
Definition: Entity.cpp:2267
eEntityType
Definition: Entity.h:89
@ etEntity
Definition: Entity.h:90
@ etPickup
Definition: Entity.h:93
@ etProjectile
Definition: Entity.h:99
@ etItemFrame
Definition: Entity.h:102
@ etMinecart
Definition: Entity.h:96
@ etFallingBlock
Definition: Entity.h:95
@ etMob
Definition: Entity.h:107
@ etExpOrb
Definition: Entity.h:100
@ etPainting
Definition: Entity.h:103
@ etEnderCrystal
Definition: Entity.h:91
@ etMonster
Definition: Entity.h:94
@ etFloater
Definition: Entity.h:101
@ etLeashKnot
Definition: Entity.h:104
@ etBoat
Definition: Entity.h:97
@ etTNT
Definition: Entity.h:98
@ etPlayer
Definition: Entity.h:92
void OnLoseSpectator(cPlayer &a_Player)
Called when a player stops spectating this entity.
Definition: Entity.cpp:159
bool HasAnyMobLeashed() const
Returs whether the entity has any mob leashed to it.
Definition: Entity.h:557
void RemoveLeashedMob(cMonster *a_Monster)
Removes a mob from the leashed list of mobs.
Definition: Entity.cpp:2311
virtual ~cEntity()=default
bool m_bDirtyHead
Stores whether head yaw has been set manually.
Definition: Entity.h:594
virtual bool IsSprinting(void) const
Definition: Entity.h:492
void AttachTo(cEntity &a_AttachTo)
Attaches to the specified entity; detaches from any previous one first.
Definition: Entity.cpp:2027
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
Definition: Entity.cpp:1966
bool m_bHasSentNoSpeed
Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client Ensures t...
Definition: Entity.h:601
void StartBurning(int a_TicksLeftBurning)
Puts the entity on fire for the specified amount of ticks.
Definition: Entity.cpp:1908
double GetSpeedX(void) const
Definition: Entity.h:202
cWorld * GetWorld(void) const
Definition: Entity.h:190
static const int MAX_AIR_LEVEL
Maximum air an entity can have.
Definition: Entity.h:121
virtual void ResetPosition(Vector3d a_NewPos)
Set the entities position and last sent position.
Definition: Entity.cpp:1857
virtual cItem GetEquippedChestplate(void) const
Returns the currently equipped chestplate; empty item if none.
Definition: Entity.h:339
static const int BURN_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it is burning.
Definition: Entity.h:116
void SetWorld(cWorld *a_World)
Sets the internal world pointer to a new cWorld, doesn't update anything else.
Definition: Entity.h:534
cEntity * m_AttachedTo
The entity to which this entity is attached (vehicle), nullptr if none.
Definition: Entity.h:588
bool IsMob(void) const
Definition: Entity.h:162
State variables for MoveToWorld.
Definition: Entity.h:80
Vector3d m_NewPosition
Definition: Entity.h:82
Structure storing the portal delay timer and cooldown boolean.
Definition: Entity.h:566
unsigned short m_TicksDelayed
Ticks since entry of portal, used to delay teleportation.
Definition: Entity.h:568
bool m_ShouldPreventTeleportation
Whether the entity has just exited the portal, and should therefore not be teleported again.
Definition: Entity.h:572
Definition: Player.h:29
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17
Definition: World.h:53