4 #include "../BoundingBox.h"
6 #include "../OSSupport/AtomicUniquePtr.h"
13 #define CLASS_PROTODEF(classname) \
14 virtual bool IsA(const char * a_ClassName) const override\
16 return ((a_ClassName != nullptr) && ((strcmp(a_ClassName, #classname) == 0) || Super::IsA(a_ClassName))); \
18 virtual const char * GetClass(void) const override \
22 static const char * GetClassStatic(void) \
26 virtual const char * GetParentClass(void) const override \
28 return Super::GetClass(); \
31 #define POSX_TOINT FloorC(GetPosX())
32 #define POSY_TOINT FloorC(GetPosY())
33 #define POSZ_TOINT FloorC(GetPosZ())
34 #define POS_TOINT GetPosition().Floor()
36 #define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z) \
37 cChunk * ChunkVarName = a_Chunk.GetNeighborChunk(X, Z); \
39 if ((ChunkVarName == nullptr) || !ChunkVarName->IsValid()) \
176 virtual bool IsA(
const char * a_ClassName)
const;
182 virtual const char *
GetClass(
void)
const;
220 void SetYaw (
double a_Yaw);
225 void SetSpeed(
double a_SpeedX,
double a_SpeedY,
double a_SpeedZ);
244 void AddSpeed (
double a_AddSpeedX,
double a_AddSpeedY,
double a_AddSpeedZ);
364 virtual void Heal(
int a_HitPoints);
374 virtual void Tick(std::chrono::milliseconds a_Dt,
cChunk & a_Chunk);
434 bool MoveToWorld(
cWorld & a_World,
Vector3d a_NewPosition,
bool a_ShouldSetPortalCooldown =
false,
bool a_ShouldSendRespawn =
true);
438 return MoveToWorld(a_World, a_NewPosition,
false, a_ShouldSendRespawn);
491 virtual bool IsRiding (
void)
const {
return false; }
548 void SetSize(
float a_Width,
float a_Height);
std::unique_ptr< cEntity > OwnedEntity
eDamageType
Damage type, used in the TakeDamageInfo structure and related functions.
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).
Vector3< double > Vector3d
Represents two sets of coords, minimum and maximum for each direction.
void AddPosZ(double a_AddPosZ)
bool IsProjectile(void) const
virtual const char * GetParentClass(void) const
Returns the topmost class's parent class name for the object.
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
Teleports to the coordinates specified.
virtual void DetectMagma(void)
Detects the time for application of magma block damage.
Vector3d m_LastSentPosition
Last position sent to client via the Relative Move or Teleport packets (not Velocity) Only updated if...
void AddPosition(const Vector3d &a_AddPos)
void DoMoveToWorld(const sWorldChangeInfo &a_WorldChangeInfo)
Handles the moving of this entity between worlds.
const Vector3d & GetSpeed(void) const
Exported in ManualBindings.
bool IsDestroyed() const
Deprecated.
static const int FIRE_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it stands in fire.
virtual bool IsElytraFlying(void) const
virtual bool IsRclking(void) const
bool m_IsFireproof
Whether the entity is capable of taking fire or lava damage.
void SetPitch(double a_Pitch)
void SetIsTicking(bool a_IsTicking)
Set the entity's status to either ticking or not ticking.
int GetChunkZ(void) const
void SetSpeed(Vector3d a_Speed)
Sets the speed of the entity, measured in m / sec.
void AddPosY(double a_AddPosY)
void AddSpeedX(double a_AddSpeedX)
virtual void OnAddToWorld(cWorld &a_World)
Called when the entity is added to a world.
bool IsPlayer(void) const
void SteerVehicle(float a_Forward, float a_Sideways)
cBoundingBox GetBoundingBox() const
bool IsPainting(void) const
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
void SetHeadYaw(double a_HeadYaw)
bool m_IsInWater
If any part of the entity is in a water block.
cEntity * m_Attachee
The entity which is attached to this entity (rider), nullptr if none.
void BroadcastDeathMessage(TakeDamageInfo &a_TDI)
Announces a death message on chat about killing the entity.
bool IsPickup(void) const
bool IsAttachedTo(const cEntity *a_Entity) const
Returns true if this entity is attached to the specified entity.
void SetRoll(double a_Roll)
virtual float GetEnchantmentBlastKnockbackReduction()
Returns explosion knock back reduction percent from blast protection level.
void SetSpeedX(double a_SpeedX)
Sets the speed in the X axis, leaving the other speed components intact.
Vector3d m_WaterSpeed
Measured in meter / second.
float m_AirDrag
Stores the air drag that is applied to the entity every tick, measured in speed ratio per tick Acts a...
void Detach(void)
Detaches from the currently attached entity, if any.
int m_InvulnerableTicks
If a player hit a entity, the entity receive a invulnerable of 10 ticks.
virtual void OnStartedBurning(void)
Called when the entity starts burning.
virtual bool IsInWater(void) const
Returns true if any part of the entity is in a water block.
bool IsEnderCrystal(void) const
int m_TicksSinceLastBurnDamage
Time, in ticks, since the last damage dealt by being on fire.
virtual void TickInVoid(cChunk &a_Chunk)
Handles when the entity is in the void.
static const int FIRE_DAMAGE
Damage to deal when standing in fire.
virtual double GetKnockbackAmountAgainst(const cEntity &a_Receiver)
Returns the knockback amount that the currently equipped items would cause to a_Receiver on a hit.
void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
void WrapHeadYaw()
Makes sure head yaw is not over the specified range.
double GetSpeedZ(void) const
float m_Width
Width of the entity, in the XZ plane.
bool m_IsTicking
Whether the entity is ticking or not.
bool MoveToWorld(cWorld &a_World, Vector3d a_NewPosition, bool a_ShouldSetPortalCooldown=false, bool a_ShouldSendRespawn=true)
void SetYaw(double a_Yaw)
cChunk * GetParentChunk()
Returns the chunk responsible for ticking this entity.
virtual bool IsCrouched(void) const
bool m_bDirtyOrientation
Stores whether our yaw / pitch / roll (body orientation) has been set manually.
static const int VOID_BOUNDARY
Y position to begin applying void damage.
float GetAirDrag(void) const
virtual bool IsInFire(void) const
Returns true if any part of the entity is in a fire block.
virtual cItem GetEquippedLeggings(void) const
Returns the currently equipped leggings; empty item if none.
void SetPitchFromSpeed(void)
Sets the pitch to match the speed vector (entity gies "face-forward")
cMonsterList m_LeashedMobs
List of leashed mobs to this entity.
float GetMaxHealth(void) const
Vector3d m_Rot
Measured in degrees, [-180, +180)
virtual void HandleAir(void)
Called in each tick to handle air-related processing i.e.
int GetChunkX(void) const
virtual const char * GetClass(void) const
Returns the topmost class name for the object.
virtual bool DoesPreventBlockPlacement(void) const
Returns whether blocks can be placed intersecting this entities' hitbox.
void SetHealth(float a_Health)
Sets the health of this entity; doesn't broadcast any hurt animation.
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
double GetSpeedY(void) const
const cChunk * GetParentChunk() const
std::list< cMonster * > cMonsterList
int m_AirLevel
Air level of a mobile.
sPortalCooldownData m_PortalCooldownData
Portal delay timer and cooldown boolean data.
virtual void TickBurning(cChunk &a_Chunk)
Updates the state related to this entity being on fire.
double GetRoll(void) const
static const char * GetClassStatic(void)
Returns the class name of this class.
void SetSpeedY(double a_SpeedY)
Sets the speed in the Y axis, leaving the other speed components intact.
int m_TicksLeftBurning
Time, in ticks, until the entity extinguishes its fire.
virtual void TeleportToEntity(cEntity &a_Entity)
Teleports to the entity specified.
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
Vector3d m_Position
Position of the entity's XZ center and Y bottom.
std::vector< cPlayer * > m_Spectators
List of players who are spectating this entity.
bool IsItemFrame(void) const
static const int BURN_DAMAGE
Damage to deal when the entity is burning.
float m_Gravity
Stores gravity that is applied to an entity every tick For realistic effects, this should be negative...
UInt32 m_UniqueID
The ID of the entity that is guaranteed to be unique within a single run of the server.
Vector3d GetLastSentPosition(void) const
Returns the last position we sent to all the clients.
float GetGravity(void) const
void SetSpeedZ(double a_SpeedZ)
Sets the speed in the Z axis, leaving the other speed components intact.
void SetGravity(float a_Gravity)
void SetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ)
Sets the speed of the entity, measured in m / sec.
double GetPosX(void) const
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...
float m_Height
Height of the entity (Y axis).
virtual cItem GetEquippedBoots(void) const
Returns the currently equipped boots; empty item if none.
sWorldChangeInfo m_WorldChangeInfo
If field m_NewWorld not nullptr, a world change is scheduled and a task is queued in the current worl...
virtual cItem GetOffHandEquipedItem(void) const
Returns the currently offhand equipped item; empty item if none.
void SetPosition(double a_PosX, double a_PosY, double a_PosZ)
virtual void DetectCacti(void)
Detects the time for application of cacti damage.
int m_TicksSinceLastVoidDamage
Time, in ticks, since the last damage dealt by the void.
void AddSpeed(const Vector3d &a_AddSpeed)
virtual bool IsFireproof(void) const
void SetPosY(double a_PosY)
virtual void Killed(const cEntity &a_Victim, eDamageType a_DamageType)
Called when the entity kills another entity.
float GetWidth(void) const
double GetPosZ(void) const
virtual void HandleSpeedFromAttachee(float a_Forward, float a_Sideways)
virtual bool IsHeadInWater(void) const
Returns true if any part of the entity is in a water block.
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.
bool IsMinecart(void) const
virtual void OnFinishedBurning(void)
Called when the entity finishes burning.
bool Initialize(OwnedEntity a_Self, cWorld &a_EntityWorld)
Spawns the entity in the world; returns true if spawned, false if not (plugin disallowed).
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.
UInt32 GetUniqueID(void) const
void OnAcquireSpectator(cPlayer &a_Player)
Called when a player begins spectating this entity.
void Destroy()
Destroys the entity, schedules it for memory freeing and broadcasts the DestroyEntity packet.
void WrapSpeed()
Makes speed is not over 20.
virtual void GetDrops(cItems &a_Drops, cEntity *a_Killer=nullptr)
Returns the list of drops for this pawn when it is killed.
int GetAirLevel(void) const
Gets remaining air of a monster.
bool IsWorldChangeScheduled() const
Returns true if a world change is scheduled to happen.
void SetInvulnerableTicks(int a_InvulnerableTicks)
Set the invulnerable ticks from the entity.
double m_Mass
Measured in Kilograms (Kg)
eEntityType GetEntityType(void) const
double GetPitch(void) const
virtual bool IsOnFire(void) const
bool IsOrientationDirty() const
Returns whether the entity's orientation has been set manually.
static const int LAVA_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it stands in lava.
static const int BURN_TICKS
Ticks to keep an entity burning after it has stood in lava / fire.
void AddSpeedY(double a_AddSpeedY)
void AddLeashedMob(cMonster *a_Monster)
Adds a mob to the leashed list of mobs.
bool IsLeashKnot(void) const
int m_TicksSinceLastLavaDamage
Time, in ticks, since the last damage dealt by standing in lava.
double GetPosY(void) const
Vector3d m_Speed
Measured in meters / second (m / s)
void SetParentChunk(cChunk *a_Chunk)
Sets the parent chunk, which is the chunk responsible for ticking this entity.
int GetInvulnerableTicks(void) const
Gets the invulnerable ticks from the entity.
bool m_IsHeadInWater
If the entity's head is in a water block.
double GetMass(void) const
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
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...
virtual bool DetectPortal(void)
Detects whether we are in a portal block and begins teleportation procedures if so Returns true if Mo...
void AddPosition(double a_AddPosX, double a_AddPosY, double a_AddPosZ)
void AddPosX(double a_AddPosX)
void AddSpeedZ(double a_AddSpeedZ)
double GetHeadYaw(void) const
virtual bool IsOnGround(void) const
Returns whether the entity is on ground or not.
bool m_IsInFire
If any part of the entity is in a fire block.
cEntity(eEntityType a_EntityType, Vector3d a_Pos, float a_Width, float a_Height)
void SetMass(double a_Mass)
float GetHeight(void) const
void SetAirDrag(float a_AirDrag)
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
bool IsFallingBlock(void) const
void BroadcastLeashedMobs()
If has any mobs are leashed, broadcasts every leashed entity to this.
static const int DROWNING_TICKS
Number of ticks per heart of damage.
bool IsExpOrb(void) const
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
void SetPosZ(double a_PosZ)
virtual bool DoTakeDamage(TakeDamageInfo &a_TDI)
Makes this entity take damage specified in the a_TDI.
virtual void OnRemoveFromWorld(cWorld &a_World)
Called when the entity is removed from a world.
void SetPosX(double a_PosX)
bool MoveToWorld(cWorld &a_World, bool a_ShouldSendRespawn, Vector3d a_NewPosition)
bool m_bOnGround
Stores if the entity is on the ground.
virtual cItem GetEquippedHelmet(void) const
Returns the currently equipped helmet; empty item if none.
virtual bool ArmorCoversAgainst(eDamageType a_DamageType)
Returns whether armor will protect against the specified damage type.
double m_HeadYaw
Measured in degrees, [-180, +180)
cEntity * GetAttached()
Gets entity (vehicle) attached to this entity.
void StopBurning(void)
Stops the entity from burning, resets all burning timers.
bool IsFloater(void) const
long int GetTicksAlive(void) const
Gets number of ticks this entity has been alive for.
virtual bool IsInvisible(void) const
virtual void OnDetach()
Called when this entity dismounts from m_AttachedTo.
static void ApplyFriction(Vector3d &a_Speed, double a_SlowdownMultiplier, float a_Dt)
Applies friction to an entity.
double GetYaw(void) const
virtual bool IsInLava(void) const
Returns true if any part of the entity is in a lava block.
void SetIsFireproof(bool a_IsFireproof)
Sets whether the entity is fireproof.
float GetHealth(void) const
Returns the health of this entity.
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
virtual void OnRightClicked(cPlayer &a_Player)
Called when the specified player right-clicks this entity.
void WrapRotation()
Makes sure rotation is not over the specified range.
static const int FALL_DAMAGE_HEIGHT
Y difference after which fall damage is applied.
int m_TicksSinceLastFireDamage
Time, in ticks, since the last damage dealt by standing in fire.
virtual void ApplyArmorDamage(int DamageBlocked)
Applies damage to the armor after the armor blocked the given amount.
cChunk * m_ParentChunk
The chunk which is responsible for ticking this entity.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
virtual void Heal(int a_HitPoints)
Heals the specified amount of HPs.
virtual bool IsRiding(void) const
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.
static const int LAVA_DAMAGE
Damage to deal when standing in lava.
virtual int GetRawDamageAgainst(const cEntity &a_Receiver)
Returns the hitpoints that this pawn can deal to a_Receiver using its equipped items.
void SetSize(float a_Width, float a_Height)
Update an entity's size, for example, on body stance changes.
virtual void SetSwimState(cChunk &a_Chunk)
Called once per tick to set m_IsInFire, m_IsInLava, m_IsInWater and m_IsHeadInWater.
long int m_TicksAlive
The number of ticks this entity has been alive for.
void SetYawFromSpeed(void)
Sets the rotation to match the speed vector (entity goes "face-forward")
Vector3d GetLookVector(void) const
void OnLoseSpectator(cPlayer &a_Player)
Called when a player stops spectating this entity.
bool HasAnyMobLeashed() const
Returs whether the entity has any mob leashed to it.
void RemoveLeashedMob(cMonster *a_Monster)
Removes a mob from the leashed list of mobs.
virtual ~cEntity()=default
bool m_bDirtyHead
Stores whether head yaw has been set manually.
virtual bool IsSprinting(void) const
void AttachTo(cEntity &a_AttachTo)
Attaches to the specified entity; detaches from any previous one first.
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr)
Updates clients of changes in the entity.
bool m_bHasSentNoSpeed
Stores whether we have sent a Velocity packet with a speed of zero (no speed) to the client Ensures t...
void StartBurning(int a_TicksLeftBurning)
Puts the entity on fire for the specified amount of ticks.
double GetSpeedX(void) const
cWorld * GetWorld(void) const
static const int MAX_AIR_LEVEL
Maximum air an entity can have.
virtual void ResetPosition(Vector3d a_NewPos)
Set the entities position and last sent position.
virtual cItem GetEquippedChestplate(void) const
Returns the currently equipped chestplate; empty item if none.
static const int BURN_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it is burning.
void SetWorld(cWorld *a_World)
Sets the internal world pointer to a new cWorld, doesn't update anything else.
cEntity * m_AttachedTo
The entity to which this entity is attached (vehicle), nullptr if none.
State variables for MoveToWorld.
Structure storing the portal delay timer and cooldown boolean.
unsigned short m_TicksDelayed
Ticks since entry of portal, used to delay teleportation.
bool m_ShouldPreventTeleportation
Whether the entity has just exited the portal, and should therefore not be teleported again.
This class bridges a vector of cItem for safe access via Lua.