From 496c337cdfa593654018c171f6a74c28272265b5 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 1 Sep 2017 12:04:50 +0100 Subject: Replace ItemCallbacks with lambdas (#3948) --- src/Entities/Entity.cpp | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 836e69961..598ad4127 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -304,38 +304,22 @@ void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_R void cEntity::TakeDamage(eDamageType a_DamageType, UInt32 a_AttackerID, int a_RawDamage, double a_KnockbackAmount) { - class cFindEntity : public cEntityCallback - { - public: - - cEntity * m_Entity; - eDamageType m_DamageType; - int m_RawDamage; - double m_KnockbackAmount; - - virtual bool Item(cEntity * a_Attacker) override + m_World->DoWithEntityByID(a_AttackerID, [=](cEntity & a_Attacker) { cPawn * Attacker; - if (a_Attacker->IsPawn()) + if (a_Attacker.IsPawn()) { - Attacker = static_cast(a_Attacker); + Attacker = static_cast(&a_Attacker); } else { Attacker = nullptr; } - - m_Entity->TakeDamage(m_DamageType, Attacker, m_RawDamage, m_KnockbackAmount); + TakeDamage(a_DamageType, Attacker, a_RawDamage, a_KnockbackAmount); return true; } - } Callback; - - Callback.m_Entity = this; - Callback.m_DamageType = a_DamageType; - Callback.m_RawDamage = a_RawDamage; - Callback.m_KnockbackAmount = a_KnockbackAmount; - m_World->DoWithEntityByID(a_AttackerID, Callback); + ); } @@ -666,7 +650,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) int cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage) { - int TotalEPF = 0.0; + int TotalEPF = 0; const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() }; for (size_t i = 0; i < ARRAYCOUNT(ArmorItems); i++) -- cgit v1.2.3 From 700bbdabf53ab3b47151271526570f4a862b87f2 Mon Sep 17 00:00:00 2001 From: Alexander Harkness Date: Tue, 29 Aug 2017 21:29:06 +0100 Subject: SetSwimState now takes into account head height This affects m_IsSubmerged and IsSubmerged() for entities of all types. Also prevent squids from suffocating in water. --- src/Entities/Entity.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 598ad4127..15e00871b 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -1666,7 +1666,8 @@ void cEntity::SetSwimState(cChunk & a_Chunk) m_IsSwimming = IsBlockWater(BlockIn); // Check if the player is submerged: - VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, RelY + 1, RelZ, BlockIn)); + int HeadHeight = CeilC(GetPosY() + GetHeight()) - 1; + VERIFY(a_Chunk.UnboundedRelGetBlockType(RelX, HeadHeight, RelZ, BlockIn)); m_IsSubmerged = IsBlockWater(BlockIn); } @@ -1698,7 +1699,7 @@ void cEntity::DoSetSpeed(double a_SpeedX, double a_SpeedY, double a_SpeedZ) void cEntity::HandleAir(void) { // Ref.: https://minecraft.gamepedia.com/Chunk_format - // See if the entity is /submerged/ water (block above is water) + // See if the entity is /submerged/ water (head is in water) // Get the type of block the entity is standing in: int RespirationLevel = static_cast(GetEquippedHelmet().m_Enchantments.GetLevel(cEnchantments::enchRespiration)); -- cgit v1.2.3