diff options
author | Mattes D <github@xoft.cz> | 2017-05-11 14:34:36 +0200 |
---|---|---|
committer | worktycho <work.tycho@gmail.com> | 2017-05-11 14:34:36 +0200 |
commit | 2c3c1f15273835923d9bd4950a19ee88a95ee0f4 (patch) | |
tree | cda390aa07a202497271439c2b330643074239df /src/Mobs | |
parent | Exported cFallingBlock and cExpOrb (#3700) (diff) | |
download | cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.gz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.bz2 cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.lz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.xz cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.tar.zst cuberite-2c3c1f15273835923d9bd4950a19ee88a95ee0f4.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Mobs/AggressiveMonster.cpp | 17 | ||||
-rw-r--r-- | src/Mobs/Enderman.cpp | 20 |
2 files changed, 18 insertions, 19 deletions
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp index d8bdc4af5..fec14e6e9 100644 --- a/src/Mobs/AggressiveMonster.cpp +++ b/src/Mobs/AggressiveMonster.cpp @@ -5,7 +5,7 @@ #include "../World.h" #include "../Entities/Player.h" -#include "../Tracer.h" +#include "../LineBlockTracer.h" @@ -70,17 +70,20 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) CheckEventSeePlayer(a_Chunk); } - if (GetTarget() == nullptr) + auto target = GetTarget(); + if (target == nullptr) { return; } - cTracer LineOfSight(GetWorld()); + // TODO: Currently all mobs see through lava, but only Nether-native mobs should be able to. Vector3d MyHeadPosition = GetPosition() + Vector3d(0, GetHeight(), 0); - Vector3d AttackDirection(GetTarget()->GetPosition() + Vector3d(0, GetTarget()->GetHeight(), 0) - MyHeadPosition); - - - if (TargetIsInRange() && !LineOfSight.Trace(MyHeadPosition, AttackDirection, static_cast<int>(AttackDirection.Length())) && (GetHealth() > 0.0)) + Vector3d TargetPosition = target->GetPosition() + Vector3d(0, target->GetHeight(), 0); + if ( + TargetIsInRange() && + cLineBlockTracer::LineOfSightTrace(*GetWorld(), MyHeadPosition, TargetPosition, cLineBlockTracer::losAirWaterLava) && + (GetHealth() > 0.0) + ) { // Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls) Attack(a_Dt); diff --git a/src/Mobs/Enderman.cpp b/src/Mobs/Enderman.cpp index f58e2132c..3c0717f8f 100644 --- a/src/Mobs/Enderman.cpp +++ b/src/Mobs/Enderman.cpp @@ -3,7 +3,7 @@ #include "Enderman.h" #include "../Entities/Player.h" -#include "../Tracer.h" +#include "../LineBlockTracer.h" @@ -29,9 +29,8 @@ public: return false; } - Vector3d Direction = m_EndermanPos - a_Player->GetPosition(); - - // Don't check players who are more then SightDistance (64) blocks away + // Don't check players who are more than SightDistance (64) blocks away + auto Direction = m_EndermanPos - a_Player->GetPosition(); if (Direction.Length() > m_SightDistance) { return false; @@ -43,19 +42,16 @@ public: return false; } - - Vector3d LookVector = a_Player->GetLookVector(); - double dot = Direction.Dot(LookVector); - - // 0.09 rad ~ 5 degrees // If the player's crosshair is within 5 degrees of the enderman, it counts as looking - if (dot <= cos(0.09)) + auto LookVector = a_Player->GetLookVector(); + auto dot = Direction.Dot(LookVector); + if (dot <= cos(0.09)) // 0.09 rad ~ 5 degrees { return false; } - cTracer LineOfSight(a_Player->GetWorld()); - if (LineOfSight.Trace(m_EndermanPos, Direction, static_cast<int>(Direction.Length()))) + // TODO: Check if endermen are angered through water in Vanilla + if (!cLineBlockTracer::LineOfSightTrace(*a_Player->GetWorld(), m_EndermanPos, a_Player->GetPosition(), cLineBlockTracer::losAirWater)) { // No direct line of sight return false; |