From 4c5d9d38f45ae7c18a3e9799152305757a8a1d2a Mon Sep 17 00:00:00 2001 From: Rorkh Date: Sat, 18 Sep 2021 14:10:31 +0500 Subject: [PATCH] Only nether-native mobs can see through lava --- src/Mobs/AggressiveMonster.cpp | 2 +- src/Mobs/Blaze.cpp | 29 +++++++++++++---------------- src/Mobs/Blaze.h | 10 ++++++---- src/Mobs/Ghast.cpp | 32 +++++++++++++++----------------- src/Mobs/Ghast.h | 16 +++++++--------- src/Mobs/MagmaCube.cpp | 26 +++++++++++++------------- src/Mobs/MagmaCube.h | 10 ++++------ src/Mobs/Monster.cpp | 9 +++++++++ src/Mobs/Monster.h | 4 ++++ src/Mobs/WitherSkeleton.h | 8 +++----- src/Mobs/ZombiePigman.cpp | 16 ++++++---------- src/Mobs/ZombiePigman.h | 10 ++++------ tests/Generating/Stubs.cpp | 11 ++++++++++- 13 files changed, 95 insertions(+), 88 deletions(-) diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index bcc824bba..f7392d92e 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -72,7 +72,7 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) *GetWorld(), GetPosition().addedY(GetHeight()), GetTarget()->GetPosition().addedY(GetTarget()->GetHeight()), - cLineBlockTracer::losAirWaterLava // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. + (IsNetherNative() ? cLineBlockTracer::losAirWaterLava : cLineBlockTracer::losAirWater) ) && (GetHealth() > 0.0) ) diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp index b771ef7e7..4a87e698b 100644 --- a/src/Mobs/Blaze.cpp +++ b/src/Mobs/Blaze.cpp @@ -21,19 +21,6 @@ cBlaze::cBlaze(void) : -void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) - { - unsigned int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); - } -} - - - - - bool cBlaze::Attack(std::chrono::milliseconds a_Dt) { if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0) && (!m_IsCharging)) @@ -48,6 +35,19 @@ bool cBlaze::Attack(std::chrono::milliseconds a_Dt) +void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + if ((a_Killer != nullptr) && (a_Killer->IsPlayer() || a_Killer->IsA("cWolf"))) + { + unsigned int LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_BLAZE_ROD); + } +} + + + + + void cBlaze::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Super::Tick(a_Dt, a_Chunk); @@ -84,6 +84,3 @@ void cBlaze::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) ResetAttackCooldown(); } } - - - diff --git a/src/Mobs/Blaze.h b/src/Mobs/Blaze.h index 6f1d240a9..9ebc1ffcf 100644 --- a/src/Mobs/Blaze.h +++ b/src/Mobs/Blaze.h @@ -18,11 +18,13 @@ public: CLASS_PROTODEF(cBlaze) - virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - virtual bool Attack(std::chrono::milliseconds a_Dt) override; - private: + + virtual bool Attack(std::chrono::milliseconds a_Dt) override; + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual bool IsNetherNative(void) override { return true; } + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + /** Specifies whether or not the blaze has started shooting fireballs. */ bool m_IsCharging; diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp index 3b20bea28..39fc2e99b 100644 --- a/src/Mobs/Ghast.cpp +++ b/src/Mobs/Ghast.cpp @@ -22,21 +22,6 @@ cGhast::cGhast(void) : -void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - unsigned int LootingLevel = 0; - if (a_Killer != nullptr) - { - LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); - } - AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); - AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); -} - - - - - bool cGhast::Attack(std::chrono::milliseconds a_Dt) { if ((GetTarget() != nullptr) && (m_AttackCoolDownTicksLeft == 0) && (!m_IsCharging)) @@ -71,6 +56,21 @@ bool cGhast::DoTakeDamage(TakeDamageInfo & a_TDI) +void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + unsigned int LootingLevel = 0; + if (a_Killer != nullptr) + { + LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting); + } + AddRandomDropItem(a_Drops, 0, 2 + LootingLevel, E_ITEM_GUNPOWDER); + AddRandomDropItem(a_Drops, 0, 1 + LootingLevel, E_ITEM_GHAST_TEAR); +} + + + + + void cGhast::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) { Super::Tick(a_Dt, a_Chunk); @@ -113,5 +113,3 @@ void cGhast::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) AddSpeed(SpeedVector); } } - - diff --git a/src/Mobs/Ghast.h b/src/Mobs/Ghast.h index 8161b93bf..755ec3b89 100644 --- a/src/Mobs/Ghast.h +++ b/src/Mobs/Ghast.h @@ -18,14 +18,16 @@ public: CLASS_PROTODEF(cGhast) - virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; - virtual bool Attack(std::chrono::milliseconds a_Dt) override; - virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; - bool IsCharging(void) const { return m_IsCharging; } private: + + virtual bool Attack(std::chrono::milliseconds a_Dt) override; + virtual bool DoTakeDamage(TakeDamageInfo & a_TDI) override; + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual bool IsNetherNative(void) override { return true; } + virtual void Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; + /** Specifies whether or not the ghast has started shooting a fireball. */ bool m_IsCharging; @@ -36,7 +38,3 @@ private: Only used while m_IsCharging is true. */ int m_TicksUntilShot; } ; - - - - diff --git a/src/Mobs/MagmaCube.cpp b/src/Mobs/MagmaCube.cpp index e84577433..45dbbc519 100644 --- a/src/Mobs/MagmaCube.cpp +++ b/src/Mobs/MagmaCube.cpp @@ -24,19 +24,6 @@ cMagmaCube::cMagmaCube(int a_Size) : -void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) -{ - UNUSED(a_Killer); - if (GetSize() > 1) - { - AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); - } -} - - - - - AString cMagmaCube::GetSizeName(int a_Size) { if (a_Size == 1) @@ -45,3 +32,16 @@ AString cMagmaCube::GetSizeName(int a_Size) } return ""; } + + + + + +void cMagmaCube::GetDrops(cItems & a_Drops, cEntity * a_Killer) +{ + UNUSED(a_Killer); + if (GetSize() > 1) + { + AddRandomUncommonDropItem(a_Drops, 25.0f, E_ITEM_MAGMA_CREAM); + } +} diff --git a/src/Mobs/MagmaCube.h b/src/Mobs/MagmaCube.h index 3a7d25055..07794cc5a 100644 --- a/src/Mobs/MagmaCube.h +++ b/src/Mobs/MagmaCube.h @@ -18,19 +18,17 @@ public: CLASS_PROTODEF(cMagmaCube) - virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; int GetSize(void) const { return m_Size; } /** Returns the text describing the slime's size, as used by the client's resource subsystem for sounds. Returns either "big" or "small". */ static AString GetSizeName(int a_Size); -protected: +private: + + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual bool IsNetherNative(void) override { return true; } /** Size of the MagmaCube, with 1 being the smallest */ int m_Size; } ; - - - - diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index d99f2cddc..dc77dc0f8 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -979,6 +979,15 @@ void cMonster::GetMonsterConfig(const AString & a_Name) +bool cMonster::IsNetherNative(void) +{ + return false; +} + + + + + bool cMonster::IsUndead(void) { return false; diff --git a/src/Mobs/Monster.h b/src/Mobs/Monster.h index 410754663..0127ec4ce 100644 --- a/src/Mobs/Monster.h +++ b/src/Mobs/Monster.h @@ -108,6 +108,10 @@ public: /** Reads the monster configuration for the specified monster name and assigns it to this object. */ void GetMonsterConfig(const AString & a_Name); + /** Returns whether this mob spawns in the Nether in Vanilla. + This is a fixed value and is not affected by custom mob spawning settings. */ + virtual bool IsNetherNative(void); + /** Returns whether this mob is undead (skeleton, zombie, etc.) */ virtual bool IsUndead(void); diff --git a/src/Mobs/WitherSkeleton.h b/src/Mobs/WitherSkeleton.h index 41e55e073..8aa7574df 100644 --- a/src/Mobs/WitherSkeleton.h +++ b/src/Mobs/WitherSkeleton.h @@ -18,12 +18,10 @@ public: CLASS_PROTODEF(cWitherSkeleton) +private: + virtual bool Attack(std::chrono::milliseconds a_Dt) override; virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual bool IsNetherNative(void) override { return true; } virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - } ; - - - - diff --git a/src/Mobs/ZombiePigman.cpp b/src/Mobs/ZombiePigman.cpp index 60d5ab9f1..755f585ab 100644 --- a/src/Mobs/ZombiePigman.cpp +++ b/src/Mobs/ZombiePigman.cpp @@ -38,16 +38,6 @@ void cZombiePigman::GetDrops(cItems & a_Drops, cEntity * a_Killer) -void cZombiePigman::SpawnOn(cClientHandle & a_ClientHandle) -{ - Super::SpawnOn(a_ClientHandle); - a_ClientHandle.SendEntityEquipment(*this, 0, cItem(E_ITEM_GOLD_SWORD)); -} - - - - - void cZombiePigman::KilledBy(TakeDamageInfo & a_TDI) { Super::KilledBy(a_TDI); @@ -62,3 +52,9 @@ void cZombiePigman::KilledBy(TakeDamageInfo & a_TDI) + +void cZombiePigman::SpawnOn(cClientHandle & a_ClientHandle) +{ + Super::SpawnOn(a_ClientHandle); + a_ClientHandle.SendEntityEquipment(*this, 0, cItem(E_ITEM_GOLD_SWORD)); +} diff --git a/src/Mobs/ZombiePigman.h b/src/Mobs/ZombiePigman.h index ccc07e9a2..93535a3ce 100644 --- a/src/Mobs/ZombiePigman.h +++ b/src/Mobs/ZombiePigman.h @@ -17,13 +17,11 @@ public: CLASS_PROTODEF(cZombiePigman) +private: + virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = nullptr) override; + virtual bool IsUndead(void) override { return true; } + virtual bool IsNetherNative(void) override { return true; } virtual void KilledBy(TakeDamageInfo & a_TDI) override; virtual void SpawnOn(cClientHandle & a_ClientHandle) override; - - virtual bool IsUndead(void) override { return true; } } ; - - - - diff --git a/tests/Generating/Stubs.cpp b/tests/Generating/Stubs.cpp index d3669c498..e2fc2e7cc 100644 --- a/tests/Generating/Stubs.cpp +++ b/tests/Generating/Stubs.cpp @@ -954,9 +954,18 @@ void cMonster::CheckEventSeePlayer(class cChunk & a_Chunk) +bool cMonster::IsNetherNative(void) +{ + return false; +} + + + + + bool cMonster::IsUndead(void) { - return true; + return false; }