7 #include "../Bindings/PluginManager.h" 8 #include "../BoundingBox.h" 9 #include "../Blocks/BlockHandler.h" 10 #include "../EffectID.h" 11 #include "../Mobs/Monster.h" 19 m_LastGroundHeight(0),
51 std::vector<cEntityEffect *> EffectsToTick;
71 EffectsToTick.push_back(Effect);
78 for (
auto * Effect : EffectsToTick)
80 Effect->OnTick(*
this);
84 if ((!
IsPlayer()) || (!static_cast<cPlayer *>(
this)->IsGameModeSpectator()))
107 v3Delta *= 1.0 / (v3Delta.
Length() + 0.01);
175 if (
cPluginManager::Get()->CallHookEntityAddEffect(*
this, a_EffectType, a_Duration, a_Intensity, a_DistanceModifier))
186 a_Duration =
static_cast<int>(a_Duration * a_DistanceModifier);
192 ExistingEffect->second->OnDeactivate(*
this);
212 auto Effect = std::move(itr->second);
214 Effect->OnDeactivate(*
this);
257 if (Monster == a_Monster)
293 static const auto HalfWidth =
GetWidth() / 2;
294 static const auto EPS = 0.0001;
315 bool IsFootOnSlimeBlock =
false;
321 } CrossSampleCoords[] =
336 } BlockSampleOffsets[] =
345 bool OnGround =
false;
346 for (
size_t i = 0; i <
ARRAYCOUNT(CrossSampleCoords); i++)
351 Vector3d CrossTestPosition =
GetPosition() +
Vector3d(CrossSampleCoords[i].x * HalfWidth, -EPS, CrossSampleCoords[i].z * HalfWidth);
354 for (
size_t j = 0; j <
ARRAYCOUNT(BlockSampleOffsets); j++)
356 Vector3i BlockTestPosition = CrossTestPosition.
Floor() +
Vector3i(BlockSampleOffsets[j].x, BlockSampleOffsets[j].y, BlockSampleOffsets[j].z);
384 bool FallDamageAbsorbed = IsFootInWater;
389 bool ShouldBounceOnSlime =
true;
393 auto Player =
static_cast<cPlayer *
>(
this);
396 FallDamageAbsorbed |= Player->
IsFlying() || Player->IsClimbing();
399 ShouldBounceOnSlime = !Player->IsCrouched();
400 FallDamageAbsorbed |= (IsFootOnSlimeBlock && ShouldBounceOnSlime);
405 FallDamageAbsorbed |= IsFootOnSlimeBlock;
410 if (IsFootOnSlimeBlock && ShouldBounceOnSlime)
426 if ((Damage > 0) && !FallDamageAbsorbed)
435 (Damage - 1.f) * ((0.3f - 0.1f) / (15.f - 1.f)) + 0.1f,
436 static_cast<int>((Damage - 1.f) * ((50.f - 20.f) / (15.f - 1.f)) + 20.f),
477 std::map<cEntityEffect::eType, cEntityEffect *> Effects;
480 Effects.insert({ Effect.first, Effect.second.get() });
eType
All types of entity effects (numbers correspond to protocol / storage types)
virtual bool IsHeadInWater(void) const
Returns true if any part of the entity is in a water block.
double GetPosY(void) const
virtual void BroadcastEntityEffect(const cEntity &a_Entity, int a_EffectID, int a_Amplifier, int a_Duration, const cClientHandle *a_Exclude=nullptr) override
virtual bool IsFireproof(void) const override
virtual bool ForEachEntityInBox(const cBoundingBox &a_Box, cEntityCallback a_Callback) override
Calls the callback for each entity that has a nonempty intersection with the specified boundingbox...
BLOCKTYPE GetBlock(Vector3i a_BlockPos)
Returns the block type at the specified position.
eEntityType GetEntityType(void) const
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
bool IsBlockWater(BLOCKTYPE a_BlockType)
static bool IsSolid(BLOCKTYPE a_Type)
virtual void OnActivate(cPawn &a_Target)
Called when the effect is first added to an entity.
virtual void HandleAir(void)
Called in each tick to handle air-related processing i.e.
int GetDuration(void) const
Returns the duration of the effect.
unsigned char BLOCKTYPE
The datatype used by blockdata.
double m_LastGroundHeight
static cBlockHandler * GetHandler(BLOCKTYPE a_Type)
virtual void KilledBy(TakeDamageInfo &a_TDI)
Called when the health drops below zero.
static bool IsValidHeight(int a_Height)
Validates a height-coordinate.
bool IsAttachedTo(const cEntity *a_Entity) const
Returns true if this entity is attached to the specified entity.
cPawn * GetTarget()
Returns the current target.
virtual void BroadcastRemoveEntityEffect(const cEntity &a_Entity, int a_EffectID, const cClientHandle *a_Exclude=nullptr) override
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
virtual void Destroyed(void)
Represents two sets of coords, minimum and maximum for each direction.
void RemoveEntityEffect(cEntityEffect::eType a_EffectType)
Removes a currently applied entity effect.
double GetWidth(void) const
static std::unique_ptr< cEntityEffect > CreateEntityEffect(cEntityEffect::eType a_EffectType, int a_Duration, short a_Intensity, double a_DistanceModifier)
Creates a pointer to the proper entity effect from the effect type.
static cPluginManager * Get(void)
Returns the instance of the Plugin Manager (there is only ever one)
virtual void Destroyed() override
NIBBLETYPE GetBlockMeta(Vector3i a_BlockPos)
Returns the block meta at the specified position.
void NoLongerTargetingMe(cMonster *a_Monster)
Remove the monster from the list of monsters targeting this pawn.
double GetHeight(void) const
void UnsafeUnsetTarget()
Unset the target without notifying the target entity.
bool HasEntityEffect(cEntityEffect::eType a_EffectType) const
Returns true, if the entity effect is currently applied.
void AddEntityEffect(cEntityEffect::eType a_EffectType, int a_EffectDurationTicks, short a_EffectIntensity, double a_DistanceModifier=1)
Applies an entity effect.
bool IsTicking(void) const
Returns true if the entity is valid and ticking.
bool IsFlying(void) const
Returns true if the player is currently flying.
cEntityEffect * GetEntityEffect(cEntityEffect::eType a_EffectType)
Returns the entity effect, if it is currently applied or nullptr if not.
double Length(void) const
Vector3< double > Vector3d
void AddSpeed(double a_AddSpeedX, double a_AddSpeedY, double a_AddSpeedZ)
virtual void HandleAir(void) override
Called in each tick to handle air-related processing i.e.
virtual void HandleFalling(void)
virtual void ResetPosition(Vector3d a_NewPosition) override
Set the entities position and last sent position.
virtual bool IsInvisible() const override
int GetTicks(void) const
Returns how many ticks this effect has been active for.
void SetGravity(float a_Gravity)
virtual void BroadcastParticleEffect(const AString &a_ParticleName, Vector3f a_Src, Vector3f a_Offset, float a_ParticleData, int a_ParticleAmount, const cClientHandle *a_Exclude=nullptr) override
virtual void ResetPosition(Vector3d a_NewPos)
Set the entities position and last sent position.
cPawn(eEntityType a_EntityType, double a_Width, double a_Height)
std::map< cEntityEffect::eType, std::unique_ptr< cEntityEffect > > tEffectMap
void TakeDamage(cEntity &a_Attacker)
Makes this pawn take damage from an attack by a_Attacker.
bool IsPlayer(void) const
virtual ~cPawn() override
tEffectMap m_EntityEffects
std::vector< cMonster * > m_TargetingMe
A list of all monsters that are targeting this pawn.
const Vector3d & GetPosition(void) const
Exported in ManualBindings.
void SetAirDrag(float a_AirDrag)
void TargetingMe(cMonster *a_Monster)
Add the monster to the list of monsters targeting this pawn.
virtual bool IsFireproof(void) const
void StopEveryoneFromTargetingMe()
Tells all pawns which are targeting us to stop targeting us.
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta)
Tests if a_Position is inside the block where a_Position is relative to the origin of the block Note ...
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
std::map< cEntityEffect::eType, cEntityEffect * > GetEntityEffects()
Returns all entity effects.
void ClearEntityEffects(void)
Removes all currently applied entity effects (used when drinking milk)
UInt32 GetUniqueID(void) const
cWorld * GetWorld(void) const
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk)
bool IsBlockLava(BLOCKTYPE a_BlockType)