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