summaryrefslogtreecommitdiffstats
path: root/src/Entities/Entity.cpp
diff options
context:
space:
mode:
authorAiden Neill <aidenneill@gmail.com>2020-11-25 18:56:55 +0100
committerGitHub <noreply@github.com>2020-11-25 18:56:55 +0100
commit3d044d2dde2e348dc5c9f6a7fe44e914ef501878 (patch)
tree7f3ed1fa8aaccc27044bd8bc1a2a7cbfe87dbd49 /src/Entities/Entity.cpp
parentAdding new monster types to enum and saving/loading for easier future implementation (#4941) (diff)
downloadcuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar.gz
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar.bz2
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar.lz
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar.xz
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.tar.zst
cuberite-3d044d2dde2e348dc5c9f6a7fe44e914ef501878.zip
Diffstat (limited to 'src/Entities/Entity.cpp')
-rw-r--r--src/Entities/Entity.cpp53
1 files changed, 49 insertions, 4 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 34d5bf6e5..579541dd3 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -147,6 +147,7 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
);
*/
+
ASSERT(m_World == nullptr);
ASSERT(GetParentChunk() == nullptr);
SetWorld(&a_EntityWorld);
@@ -628,6 +629,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType)
case dtAttack:
case dtArrowAttack:
case dtCactusContact:
+ case dtMagmaContact:
case dtLavaContact:
case dtFireContact:
case dtExplosion:
@@ -656,7 +658,7 @@ float cEntity::GetEnchantmentCoverAgainst(const cEntity * a_Attacker, eDamageTyp
TotalEPF += static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchProtection)) * 1;
}
- if ((a_DamageType == dtBurning) || (a_DamageType == dtFireContact) || (a_DamageType == dtLavaContact))
+ if ((a_DamageType == dtBurning) || (a_DamageType == dtFireContact) || (a_DamageType == dtLavaContact) || (a_DamageType == dtMagmaContact))
{
TotalEPF += static_cast<int>(Item.m_Enchantments.GetLevel(cEnchantments::enchFireProtection)) * 2;
}
@@ -899,6 +901,23 @@ void cEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
DetectCacti();
}
+ // Handle magma block damage
+ if
+ (
+ IsOnGround() &&
+ (
+ (IsMob() && !static_cast<cPawn *>(this)->IsFireproof()) ||
+ (
+ IsPlayer() && !((static_cast<cPlayer *>(this))->IsGameModeCreative() || (static_cast<cPlayer *>(this))->IsGameModeSpectator())
+ && !static_cast<cPlayer *>(this)->IsFireproof()
+ && !static_cast<cPlayer *>(this)->HasEntityEffect(cEntityEffect::effFireResistance)
+ )
+ )
+ )
+ {
+ DetectMagma();
+ }
+
// Handle drowning:
if (IsMob() || IsPlayer())
{
@@ -1314,6 +1333,35 @@ void cEntity::DetectCacti(void)
+void cEntity::DetectMagma(void)
+{
+ int MinX = FloorC(GetPosX() - m_Width / 2);
+ int MaxX = FloorC(GetPosX() + m_Width / 2);
+ int MinZ = FloorC(GetPosZ() - m_Width / 2);
+ int MaxZ = FloorC(GetPosZ() + m_Width / 2);
+ int MinY = Clamp(POSY_TOINT - 1, 0, cChunkDef::Height - 1);
+ int MaxY = Clamp(FloorC(GetPosY() + m_Height), 0, cChunkDef::Height - 1);
+
+ for (int x = MinX; x <= MaxX; x++)
+ {
+ for (int z = MinZ; z <= MaxZ; z++)
+ {
+ for (int y = MinY; y <= MaxY; y++)
+ {
+ if (GetWorld()->GetBlock(x, y, z) == E_BLOCK_MAGMA)
+ {
+ TakeDamage(dtMagmaContact, nullptr, 1, 0);
+ return;
+ }
+ } // for y
+ } // for z
+ } // for x
+}
+
+
+
+
+
bool cEntity::DetectPortal()
{
// If somebody scheduled a world change, do nothing.
@@ -2334,6 +2382,3 @@ float cEntity::GetExplosionExposureRate(Vector3d a_ExplosionPosition, float a_Ex
return 0;
}
}
-
-
-