summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorchangyong guo <guo1487@163.com>2018-07-23 11:24:00 +0200
committerpeterbell10 <peterbell10@live.co.uk>2018-07-23 11:24:00 +0200
commit01e72ddb6567531b16f92af2564b853878b6ef65 (patch)
treeb91403cec84e0b405448d8fadbc2c39f2270ab47 /src/Entities/Entity.cpp
parentKeep players in gmNotSet (#4248) (diff)
downloadcuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar.gz
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar.bz2
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar.lz
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar.xz
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.tar.zst
cuberite-01e72ddb6567531b16f92af2564b853878b6ef65.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp64
1 files changed, 63 insertions, 1 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index d1fdcfd39..4ecc5c4da 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -14,7 +14,7 @@
#include "Items/ItemHandler.h"
#include "../FastRandom.h"
#include "../NetherPortalScanner.h"
-
+#include "../BoundingBox.h"
@@ -690,6 +690,33 @@ int cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageType
+
+float cEntity::GetEnchantmentBlastKnockbackReduction()
+{
+ UInt32 MaxLevel = 0;
+
+ const cItem ArmorItems[] = { GetEquippedHelmet(), GetEquippedChestplate(), GetEquippedLeggings(), GetEquippedBoots() };
+
+ for (auto & Item : ArmorItems)
+ {
+ UInt32 Level = Item.m_Enchantments.GetLevel(cEnchantments::enchBlastProtection);
+ if (Level > MaxLevel)
+ {
+ // Get max blast protection
+ MaxLevel = Level;
+ }
+ }
+
+ // Max blast protect level is 4, each level provide 15% knock back reduction
+ MaxLevel = std::min<UInt32>(MaxLevel, 4);
+ return MaxLevel * 0.15f;
+}
+
+
+
+
+
+
int cEntity::GetArmorCoverAgainst(const cEntity * a_Attacker, eDamageType a_DamageType, int a_Damage)
{
// Returns the hitpoints out of a_RawDamage that the currently equipped armor would cover
@@ -2241,3 +2268,38 @@ void cEntity::RemoveLeashedMob(cMonster * a_Monster)
m_LeashedMobs.remove(a_Monster);
}
+
+
+
+
+
+
+float cEntity::GetExplosionExposureRate(Vector3d a_ExplosionPosition, float a_ExlosionPower)
+{
+ double EntitySize = m_Width * m_Width * m_Height;
+ if (EntitySize <= 0)
+ {
+ // Handle entity with invalid size
+ return 0;
+ }
+
+ cBoundingBox EntityBox(GetPosition(), m_Width / 2, m_Height);
+ cBoundingBox ExplosionBox(a_ExplosionPosition, a_ExlosionPower * 2.0);
+ cBoundingBox IntersectionBox(EntityBox);
+
+ bool Overlap = EntityBox.Intersect(ExplosionBox, IntersectionBox);
+ if (Overlap)
+ {
+ Vector3d Diff = IntersectionBox.GetMax() - IntersectionBox.GetMin();
+ double OverlapSize = Diff.x * Diff.y * Diff.z;
+
+ return static_cast<float>(OverlapSize / EntitySize);
+ }
+ else
+ {
+ return 0;
+ }
+}
+
+
+