6 #include "../BlockInfo.h"
9 #include "../Matrix4.h"
10 #include "../ClientHandle.h"
12 #include "../Simulator/FluidSimulator.h"
13 #include "../Bindings/PluginManager.h"
14 #include "../LineBlockTracer.h"
15 #include "../Items/ItemHandler.h"
16 #include "../FastRandom.h"
17 #include "../NetherPortalScanner.h"
18 #include "../BoundingBox.h"
19 #include "../WorldStorage/NamespaceSerializer.h"
26 static std::atomic<UInt32> counter(1);
27 return counter.fetch_add(1);
41 m_AttachedTo(nullptr),
44 m_bDirtyOrientation(false),
45 m_bHasSentNoSpeed(true),
49 m_LastSentPosition(a_Pos),
50 m_LastPosition(a_Pos),
51 m_EntityType(a_EntityType),
54 m_TicksSinceLastBurnDamage(0),
55 m_TicksSinceLastLavaDamage(0),
56 m_TicksSinceLastFireDamage(0),
57 m_TicksLeftBurning(0),
58 m_TicksSinceLastVoidDamage(0),
62 m_IsHeadInWater(false),
63 m_AirLevel(MAX_AIR_LEVEL),
64 m_AirTickTimer(DROWNING_TICKS),
67 m_ParentChunk(nullptr),
71 m_WaterSpeed(0, 0, 0),
75 m_InvulnerableTicks(0)
129 a_EntityWorld.
AddEntity(std::move(a_Self));
182 Player->OnLoseSpectated();
256 LOGD(
"Destroying entity #%i (%s) from chunk (%d, %d)",
258 ParentChunkCoords.m_ChunkX, ParentChunkCoords.m_ChunkZ
260 UNUSED(ParentChunkCoords);
284 float FinalDamage =
static_cast<float>(a_RawDamage);
289 cEntity::TakeDamage(a_DamageType, a_Attacker, a_RawDamage, FinalDamage, a_KnockbackAmount);
303 Attacker = static_cast<cPawn*>(&a_Attacker);
310 TakeDamage(a_DamageType, Attacker, a_RawDamage, a_KnockbackAmount);
324 if ((a_Attacker !=
nullptr) && a_Attacker->
IsPawn())
333 if (a_RawDamage <= 0)
340 if (a_FinalDamage <= 0)
348 if (a_Attacker !=
nullptr)
353 int KnockbackHeight = 3;
361 Vector3d FinalKnockback =
Vector3d(Heading.
x * a_KnockbackAmount, Heading.
y + KnockbackHeight, Heading.
z * a_KnockbackAmount);
373 const double EPS = 0.0000001;
389 const double EPS = 0.0000001;
391 if ((std::abs(xz) < EPS) && (std::abs(
m_Speed.
y) < EPS))
418 if (
cRoot::Get()->GetPluginManager()->CallHookTakeDamage(*
this, a_TDI))
442 bool MagicalCriticalHit =
false;
461 if (SharpnessLevel > 0)
463 MagicalCriticalHit =
true;
466 else if (SmiteLevel > 0)
479 MagicalCriticalHit =
true;
487 else if (BaneOfArthropodsLevel > 0)
499 MagicalCriticalHit =
true;
516 if (FireAspectLevel > 0)
520 if (FireAspectLevel > 1)
522 BurnTicks += 4 * (FireAspectLevel - 1);
542 MagicalCriticalHit =
true;
549 if (MagicalCriticalHit)
554 unsigned int ThornsLevel = 0;
556 for (
size_t i = 0; i <
ARRAYCOUNT(ArmorItems); i++)
564 int Chance =
static_cast<int>(ThornsLevel * 15);
568 if (Random.RandBool(Chance / 100.0))
590 case eDamageType::dtBurning: return EntityAnimation::PawnBurns;
591 case eDamageType::dtDrowning: return EntityAnimation::PawnDrowns;
592 default: return EntityAnimation::PawnHurts;
664 switch (a_DamageType)
706 for (
size_t i = 0; i <
ARRAYCOUNT(ArmorItems); i++)
736 int CappedEPF = std::min(20, TotalEPF);
737 return (a_Damage * CappedEPF / 25.0f);
750 for (
auto &
Item : ArmorItems)
753 if (
Level > MaxLevel)
761 MaxLevel = std::min<UInt32>(MaxLevel, 4);
762 return MaxLevel * 0.15f;
819 float Reduction = std::max(ArmorValue / 5.0f, ArmorValue - a_Damage / (2.0f + Toughness / 4.0f));
820 return (a_Damage * std::min(20.0f, Reduction) / 25.0f);
830 double Knockback = 10;
840 unsigned int KnockbackLevelMultiplier = 8;
842 Knockback += KnockbackLevelMultiplier * KnockbackLevel;
960 (
IsPlayer() && !((
static_cast<cPlayer *
>(
this))->IsGameModeCreative() || (
static_cast<cPlayer *
>(
this))->IsGameModeSpectator()))
973 IsPlayer() && !((
static_cast<cPlayer *
>(
this))->IsGameModeCreative() || (
static_cast<cPlayer *
>(
this))->IsGameModeSpectator())
1011 auto DtSec = std::chrono::duration_cast<std::chrono::duration<double>>(a_Dt);
1025 BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ);
1026 BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) :
E_BLOCK_AIR;
1053 bool IsNoAirSurrounding =
true;
1065 IsNoAirSurrounding =
false;
1070 if (IsNoAirSurrounding)
1091 fallspeed =
m_Gravity * DtSec.count() / 3;
1092 ApplyFriction(NextSpeed, 0.7,
static_cast<float>(DtSec.count()));
1096 NextSpeed.
y *= 0.05;
1103 NextSpeed -= NextSpeed * (
m_AirDrag * 20.0f) * DtSec.count();
1105 NextSpeed.
y +=
static_cast<float>(fallspeed);
1111 int NextBlockY = BlockY;
1112 BLOCKTYPE NextBlock = NextChunk->GetBlock(RelBlockX, NextBlockY, RelBlockZ);
1115 NextBlock = NextChunk->GetBlock(RelBlockX, ++NextBlockY, RelBlockZ);
1117 NextPos.y = NextBlockY - 0.5;
1123 ApplyFriction(NextSpeed, 0.7,
static_cast<float>(DtSec.count()));
1130 NextSpeed.
x *= 0.25;
1131 NextSpeed.
z *= 0.25;
1139 auto AdjustSpeed = [](
double & a_WaterSpeed,
float a_WaterDir)
1141 if (std::abs(a_WaterDir) > (0.05f / 0.4f))
1143 a_WaterSpeed = 0.4 * a_WaterDir;
1145 else if (std::abs(a_WaterSpeed) < 0.05)
1160 Vector3d wantNextPos = NextPos + NextSpeed * DtSec.count();
1165 NextPos = HitCoords;
1168 const auto HalfWidth =
GetWidth() / 2;
1169 switch (HitBlockFace)
1174 NextPos.x -= HalfWidth;
1180 NextPos.x += HalfWidth;
1194 NextPos.y = HitBlockCoords.
y + 1;
1200 NextPos.z -= HalfWidth;
1206 NextPos.z += HalfWidth;
1218 NextPos += (NextSpeed * DtSec.count());
1234 a_Speed.
x *= a_SlowdownMultiplier / (1 + a_Dt);
1235 if (fabs(a_Speed.
x) < 0.05)
1239 a_Speed.
z *= a_SlowdownMultiplier / (1 + a_Dt);
1240 if (fabs(a_Speed.
z) < 0.05)
1372 for (
int x = MinX; x <= MaxX; x++)
1374 for (
int z = MinZ; z <= MaxZ; z++)
1376 for (
int y = MinY; y <= MaxY; y++)
1401 for (
int x = MinX; x <= MaxX; x++)
1403 for (
int z = MinZ; z <= MaxZ; z++)
1405 for (
int y = MinY; y <= MaxY; y++)
1425 if (
GetWorld()->GetLinkedNetherWorldName().empty() &&
GetWorld()->GetLinkedEndWorldName().empty())
1431 else if (
GetWorld()->GetLinkedOverworldName().empty())
1466 if (
GetWorld()->GetLinkedOverworldName().empty())
1478 ASSERT(TargetWorld !=
nullptr);
1486 if (
GetWorld()->GetLinkedNetherWorldName().empty())
1498 ASSERT(TargetWorld !=
nullptr);
1520 if (
GetWorld()->GetLinkedOverworldName().empty())
1528 ASSERT(TargetWorld !=
nullptr);
1545 if (
GetWorld()->GetLinkedEndWorldName().empty())
1553 ASSERT(TargetWorld !=
nullptr);
1591 LOGD(
"Warping entity #%i (%s) from world \"%s\" to \"%s\". Source chunk: (%d, %d) ",
1601 const auto OldWorld =
m_World;
1619 if (
cRoot::Get()->GetPluginManager()->CallHookEntityChangingWorld(*
this, a_World))
1631 if (OldWorld !=
nullptr)
1655 [EntityID](
cWorld & a_CurWorld)
1663 WCI.m_NewWorld =
nullptr;
1689 if (
World ==
nullptr)
1691 LOG(
"%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName.c_str());
1711 ASSERT(RelY <= HeadRelY);
1724 for (
int x = MinRelX; x <= MaxRelX; x++)
1726 for (
int z = MinRelZ; z <= MaxRelZ; z++)
1728 for (
int y = MinY; y <= MaxY; y++)
1813 if (RespirationLevel > 0)
1845 if (RespirationLevel > 0)
1969 if ((
GetWorld()->GetWorldTickAge() % 2_tick) != 0_tick)
2074 return ((a_ClassName !=
nullptr) && (strcmp(a_ClassName,
"cEntity") == 0));
2118 m_Mass = std::max(a_Mass, 0.001);
2233 double AddSpeedX = LookVector.
x * a_Forward + LookVector.
z * a_Sideways;
2234 double AddSpeedZ = LookVector.
z * a_Forward - LookVector.
x * a_Sideways;
2249 if ((a_Forward != 0.0f) || (a_Sideways != 0.0f))
2285 const double MaxFloat = std::pow(2, std::numeric_limits<float>().digits);
2287 const double ClampedPosX =
Clamp(a_Position.
x, -MaxFloat, MaxFloat);
2288 const double ClampedPosY =
Clamp(a_Position.
y, -MaxFloat, MaxFloat);
2289 const double ClampedPosZ =
Clamp(a_Position.
z, -MaxFloat, MaxFloat);
2292 m_Position = {ClampedPosX, ClampedPosY, ClampedPosZ};
2379 const AString DamageText = [&]
2384 case dtLightning:
return "was plasmified by lightining";
2388 case dtStarving:
return "forgot the importance of food";
2393 case dtWithering:
return "is a husk of their former selves";
2394 case dtOnFire:
return "forgot to stop, drop, and roll";
2396 case dtInVoid:
return "somehow fell out of the world";
2399 case dtAdmin:
return "was administrator'd";
2401 case dtAttack:
return "was attacked by thin air";
2406 auto DeathMessage = fmt::format(FMT_STRING(
"{} {}"), Name, DamageText);
2408 if (!DeathMessage.empty())
2416 auto DeathMessage = fmt::format(FMT_STRING(
"{0} was killed by {1}"), Name, Killer->
GetName());
2418 if (!DeathMessage.empty())
2430 DeathMessage = fmt::format(FMT_STRING(
"{0} was killed by {1}"), Name, Monster->
GetCustomName());
2435 DeathMessage = fmt::format(FMT_STRING(
"{0} was killed by a {1}"), Name, KillerName);
2439 if (!DeathMessage.empty())
static int GetBlock(lua_State *a_LuaState)
Templated bindings for the GetBlock___() functions.
bool IsBlockWater(BLOCKTYPE a_BlockType)
bool IsBlockLava(BLOCKTYPE a_BlockType)
@ E_ITEM_DIAMOND_CHESTPLATE
@ E_ITEM_DIAMOND_LEGGINGS
@ E_ITEM_CHAIN_CHESTPLATE
std::unique_ptr< cEntity > OwnedEntity
unsigned char BLOCKTYPE
The datatype used by blockdata.
AString DimensionToString(eDimension a_Dimension)
Translates a dimension enum to dimension string.
@ EntityGetsMagicalCriticalHit
double NormalizeAngleDegrees(const double a_Degrees)
Normalizes an angle in degrees to the [-180, +180) range:
eDamageType
Damage type, used in the TakeDamageInfo structure and related functions.
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
static UInt32 GetNextUniqueID(void)
#define GET_AND_VERIFY_CURRENT_CHUNK(ChunkVarName, X, Z)
MTRand & GetRandomProvider()
Returns the current thread's random number source.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
T Clamp(T a_Value, T a_Min, T a_Max)
Clamp X to the specified range.
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
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 LOG(std::string_view a_Format, const Args &... args)
static constexpr Vector3i gCrossCoords[]
Vector3< double > Vector3d
Utilities to allow casting a cWorld to one of its interfaces without including World....
unsigned char Level(const BlockState Block)
AString PrettifyEntityName(const AString &a_ID, const bool a_IsTamed=false)
std::string_view From(CustomStatistic a_ID)
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
bool CallHookKilled(cEntity &a_Victim, TakeDamageInfo &a_TDI, AString &a_DeathMessage)
bool CallHookKilling(cEntity &a_Victim, cEntity *a_Killer, TakeDamageInfo &a_TDI)
static bool IsSolid(BLOCKTYPE Block)
Is this block solid (player cannot walk through)?
cChunkCoords GetPos() const
bool IsWeatherWetAt(int a_RelX, int a_RelZ) const
Returns true if it is raining or storming at the specified location, taking into account biomes.
bool IsValid(void) const
Returns true iff the chunk block data is valid (loaded / generated)
bool UnboundedRelGetBlockType(Vector3i a_RelCoords, BLOCKTYPE &a_BlockType) const
Same as GetBlockType(), but relative coords needn't be in this chunk (uses m_Neighbor-s or m_ChunkMap...
static bool IsValidHeight(Vector3i a_BlockPosition)
Validates a height-coordinate.
static void BlockToChunk(int a_X, int a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords to chunk coords:
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
Class that stores item enchantments or stored-enchantments The enchantments may be serialized to a st...
@ enchProjectileProtection
unsigned int GetLevel(int a_EnchantmentID) const
Returns the level for the specified enchantment; 0 if not stored.
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 DoMoveToWorld(const sWorldChangeInfo &a_WorldChangeInfo)
Handles the moving of this entity between worlds.
const Vector3d & GetSpeed(void) const
Exported in ManualBindings.
static const int FIRE_TICKS_PER_DAMAGE
Ticks to wait between damaging an entity when it stands in fire.
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 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)
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.
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.
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.
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.
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.
void SetHealth(float a_Health)
Sets the health of this entity; doesn't broadcast any hurt animation.
double GetSpeedY(void) const
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.
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.
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...
void SetSpeedZ(double a_SpeedZ)
Sets the speed in the Z axis, leaving the other speed components intact.
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...
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.
virtual bool IsFireproof(void) const
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.
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.
double m_Mass
Measured in Kilograms (Kg)
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.
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.
bool m_IsHeadInWater
If the entity's head is in a water block.
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 AddSpeedZ(double a_AddSpeedZ)
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
virtual cItem GetEquippedWeapon(void) const
Returns the curently equipped weapon; empty item if none.
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.
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
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.
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.
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.
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.
void SetMaxHealth(float a_MaxHealth)
Sets the maximum value for the health.
void WrapRotation()
Makes sure rotation is not over the specified range.
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 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.
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.
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.
void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier=1)
Applies an entity effect.
const AString & GetName(void) const
Vector3i GetLastBedPos(void) const
Gets the player's potential respawn position (named LastBedPos for compatibility reasons).
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
cWorld * GetRespawnWorld()
const cItem & GetEquippedItem(void) const
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
virtual bool IsOnGround(void) const override
Returns whether the entity is on ground or not.
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
bool RandBool(double a_TrueProbability=0.5)
Return a random bool with the given probability of being true.
const cItemHandler & GetHandler(void) const
Returns the cItemHandler responsible for this item type.
cEnchantments m_Enchantments
This class bridges a vector of cItem for safe access via Lua.
virtual void OnEntityAttack(cPlayer *a_Attacker, cEntity *a_AttackedEntity) const
Called when a player attacks an entity with this item in hand.
static bool FirstSolidHitTrace(cWorld &a_World, const Vector3d &a_Start, const Vector3d &a_End, Vector3d &a_HitCoords, Vector3i &a_HitBlockCoords, eBlockFace &a_HitBlockFace)
Traces until the first solid block is hit (or until end, whichever comes first.
Vector3< T > Transform(const Vector3< T > &v) const
void Init(const Vector3< T > &a_Pos, T a_RX, T a_RY, T a_RZ)
bool HasCustomName(void) const
Returns true if the monster has a custom name.
virtual bool IsTame(void) const
const AString & GetCustomName(void) const
Gets the custom name of the monster.
eMonsterType GetMobType(void) const
cEntity * GetLeashedTo() const
Returns the entity to where this mob is leashed, returns nullptr if it's not leashed.
cPluginManager * GetPluginManager(void)
cWorld * GetWorld(const AString &a_WorldName)
Returns a pointer to the world specified.
virtual Vector3f GetFlowingDirection(Vector3i a_Pos)
Returns a unit vector in the direction the fluid is flowing or a zero-vector if not flowing.
std::unordered_map< CustomStatistic, StatValue > Custom
bool HasNonZeroLength(void) const
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
void Set(T a_x, T a_y, T a_z)
double SqrLength(void) const
virtual void BroadcastChatDeath(const AString &a_Message, const cClientHandle *a_Exclude=nullptr) override
cFluidSimulator * GetWaterSimulator(void)
void AddEntity(OwnedEntity a_Entity, cWorld *a_OldWorld=nullptr)
Adds the entity into its appropriate chunk; takes ownership of the entity ptr.
int GetSpawnX(void) const
virtual void BroadcastDetachEntity(const cEntity &a_Entity, const cEntity &a_PreviousVehicle) override
virtual void BroadcastAttachEntity(const cEntity &a_Entity, const cEntity &a_Vehicle) override
virtual void BroadcastEntityMetadata(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastEntityAnimation(const cEntity &a_Entity, EntityAnimation a_Animation, const cClientHandle *a_Exclude=nullptr) override
bool DoWithEntityByID(UInt32 a_UniqueID, cEntityCallback a_Callback)
Calls the callback if the entity with the specified ID is found, with the entity object as the callba...
const AString & GetName(void) const
Returns the name of the world.
virtual void BroadcastEntityHeadLook(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
void QueueTask(std::function< void(cWorld &)> a_Task)
Queues a task onto the tick thread.
int GetSpawnZ(void) const
virtual eDimension GetDimension(void) const override
virtual void BroadcastSpawnEntity(cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastEntityLook(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastEntityVelocity(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastLeashEntity(const cEntity &a_Entity, const cEntity &a_EntityLeashedTo) override
void SpawnItemPickups(const cItems &a_Pickups, Vector3i a_BlockPos, double a_FlyAwaySpeed=1.0, bool a_IsPlayerCreated=false)
Spawns item pickups for each item in the list.
virtual void BroadcastEntityPosition(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
virtual void BroadcastDestroyEntity(const cEntity &a_Entity, const cClientHandle *a_Exclude=nullptr) override
int GetSpawnY(void) const
OwnedEntity RemoveEntity(cEntity &a_Entity)
Removes the entity from the world.