diff options
author | Tiger Wang <ziwei.tiger@outlook.com> | 2021-01-02 14:50:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-02 14:50:34 +0100 |
commit | 16aeb84cd35996a6b41f10cbc48a677eeccc911c (patch) | |
tree | ae877926559d59a534bbf3c22651e6df7ffe8d71 /src/Mobs/Monster.cpp | |
parent | Fix version typo in CMakeLists.txt (#5098) (diff) | |
download | cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.gz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.bz2 cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.lz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.xz cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.tar.zst cuberite-16aeb84cd35996a6b41f10cbc48a677eeccc911c.zip |
Diffstat (limited to 'src/Mobs/Monster.cpp')
-rw-r--r-- | src/Mobs/Monster.cpp | 44 |
1 files changed, 10 insertions, 34 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index 048393e67..7e8e7eba3 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -135,17 +135,15 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A -cMonster::~cMonster() +void cMonster::OnRemoveFromWorld(cWorld & a_World) { - ASSERT(GetTarget() == nullptr); -} - - - + SetTarget(nullptr); // Tell them we're no longer targeting them. + if (m_LovePartner != nullptr) + { + m_LovePartner->ResetLoveMode(); + } -void cMonster::OnRemoveFromWorld(cWorld & a_World) -{ if (IsLeashed()) { cEntity * LeashedTo = GetLeashedTo(); @@ -165,20 +163,6 @@ void cMonster::OnRemoveFromWorld(cWorld & a_World) -void cMonster::Destroyed() -{ - SetTarget(nullptr); // Tell them we're no longer targeting them. - if (m_LovePartner != nullptr) - { - m_LovePartner->ResetLoveMode(); - } - Super::Destroyed(); -} - - - - - void cMonster::SpawnOn(cClientHandle & a_Client) { a_Client.SendSpawnMob(*this); @@ -762,22 +746,14 @@ void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) const auto MyHeadPosition = GetPosition().addedY(GetHeight()); // Enumerate all players within sight: - m_World->ForEachEntityInBox({ GetPosition(), m_SightDistance * 2.0 }, [this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cEntity & a_Entity) + m_World->ForEachPlayer([this, &TargetPlayer, &ClosestDistance, MyHeadPosition](cPlayer & a_Player) { - if (!a_Entity.IsPlayer()) - { - // Continue iteration: - return false; - } - - const auto Player = static_cast<cPlayer *>(&a_Entity); - - if (!Player->CanMobsTarget()) + if (!a_Player.CanMobsTarget()) { return false; } - const auto TargetHeadPosition = a_Entity.GetPosition().addedY(a_Entity.GetHeight()); + const auto TargetHeadPosition = a_Player.GetPosition().addedY(a_Player.GetHeight()); const auto TargetDistance = (TargetHeadPosition - MyHeadPosition).SqrLength(); // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. @@ -786,7 +762,7 @@ void cMonster::CheckEventSeePlayer(cChunk & a_Chunk) cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetHeadPosition, cLineBlockTracer::losAirWaterLava) ) { - TargetPlayer = Player; + TargetPlayer = &a_Player; ClosestDistance = TargetDistance; } |