summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-01-05 03:13:02 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2021-01-11 17:39:56 +0100
commit9328afe65c72b29f5cedbf1897ea8559f6b2c42f (patch)
tree92d9490d062009278ed8d78f8981014e88ba8f05 /src/Mobs
parentzlib -> libdeflate (#5085) (diff)
downloadcuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar.gz
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar.bz2
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar.lz
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar.xz
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.tar.zst
cuberite-9328afe65c72b29f5cedbf1897ea8559f6b2c42f.zip
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/Enderman.cpp14
-rw-r--r--src/Mobs/Monster.cpp8
-rw-r--r--src/Mobs/SnowGolem.cpp18
3 files changed, 25 insertions, 15 deletions
diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp
index 02450487b..a107762c6 100644
--- a/src/Mobs/Enderman.cpp
+++ b/src/Mobs/Enderman.cpp
@@ -1,6 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "Chunk.h"
#include "Enderman.h"
#include "../Entities/Player.h"
#include "../LineBlockTracer.h"
@@ -148,11 +149,14 @@ void cEnderman::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
return;
}
- // Take damage when wet
- if (
- cChunkDef::IsValidHeight(POSY_TOINT) &&
- (GetWorld()->IsWeatherWetAtXYZ(GetPosition().Floor()) || IsInWater())
- )
+ PREPARE_REL_AND_CHUNK(GetPosition().Floor(), a_Chunk);
+ if (!RelSuccess)
+ {
+ return;
+ }
+
+ // Take damage when wet:
+ if (IsInWater() || Chunk->IsWeatherWetAt(Rel))
{
EventLosePlayer();
TakeDamage(dtEnvironment, nullptr, 1, 0);
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 7e8e7eba3..52b3f8454 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -1667,10 +1667,10 @@ bool cMonster::WouldBurnAt(Vector3d a_Location, cChunk & a_Chunk)
}
if (
- (Chunk->GetBlock(Rel.x, Rel.y, Rel.z) != E_BLOCK_SOULSAND) && // Not on soulsand
- (GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime
- GetWorld()->IsWeatherSunnyAt(POSX_TOINT, POSZ_TOINT) && // Not raining
- !IsInWater() // Isn't swimming
+ (Chunk->GetBlock(Rel) != E_BLOCK_SOULSAND) && // Not on soulsand
+ (GetWorld()->GetTimeOfDay() < 12000 + 1000) && // Daytime
+ Chunk->IsWeatherSunnyAt(Rel.x, Rel.z) && // Not raining
+ !IsInWater() // Isn't swimming
)
{
int MobHeight = CeilC(a_Location.y + GetHeight()) - 1; // The block Y coord of the mob's head
diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp
index 93c29cafb..c6db0cbd1 100644
--- a/src/Mobs/SnowGolem.cpp
+++ b/src/Mobs/SnowGolem.cpp
@@ -1,6 +1,7 @@
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "Chunk.h"
#include "SnowGolem.h"
#include "../BlockInfo.h"
#include "../World.h"
@@ -36,17 +37,22 @@ void cSnowGolem::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
// The base class tick destroyed us
return;
}
- if (IsBiomeNoDownfall(m_World->GetBiomeAt(POSX_TOINT, POSZ_TOINT)))
+
+ PREPARE_REL_AND_CHUNK(GetPosition().Floor(), a_Chunk);
+ if (!RelSuccess)
+ {
+ return;
+ }
+
+ if (IsBiomeNoDownfall(Chunk->GetBiomeAt(Rel.x, Rel.z)))
{
TakeDamage(dtEnvironment, nullptr, GetRawDamageAgainst(*this), GetKnockbackAmountAgainst(*this));
}
- else
+ else if (const auto Below = Rel.addedY(-1); Below.y >= 0)
{
- BLOCKTYPE BlockBelow = m_World->GetBlock(POSX_TOINT, POSY_TOINT - 1, POSZ_TOINT);
- BLOCKTYPE Block = m_World->GetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT);
- if ((Block == E_BLOCK_AIR) && cBlockInfo::IsSolid(BlockBelow))
+ if ((Chunk->GetBlock(Rel) == E_BLOCK_AIR) && cBlockInfo::IsSolid(Chunk->GetBlock(Below)))
{
- m_World->SetBlock(POSX_TOINT, POSY_TOINT, POSZ_TOINT, E_BLOCK_SNOW, 0);
+ Chunk->SetBlock(Rel, E_BLOCK_SNOW, 0);
}
}
}