diff options
author | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-22 12:23:03 +0200 |
---|---|---|
committer | LogicParrot <LogicParrot@users.noreply.github.com> | 2017-08-22 19:55:30 +0200 |
commit | 80d9c26c12a5be619a757d0251525664bf7065a6 (patch) | |
tree | 66d4f553ae12fd90dd94ffde9b85f595319ba5cb /src/Mobs/Behaviors/BehaviorItemFollower.cpp | |
parent | Added check in cEntity::TickBurning for whether the entity is planning to change worlds. (#3943) (diff) | |
download | cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.gz cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.bz2 cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.lz cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.xz cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.tar.zst cuberite-80d9c26c12a5be619a757d0251525664bf7065a6.zip |
Diffstat (limited to 'src/Mobs/Behaviors/BehaviorItemFollower.cpp')
-rw-r--r-- | src/Mobs/Behaviors/BehaviorItemFollower.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Mobs/Behaviors/BehaviorItemFollower.cpp b/src/Mobs/Behaviors/BehaviorItemFollower.cpp new file mode 100644 index 000000000..7cc0f8dfc --- /dev/null +++ b/src/Mobs/Behaviors/BehaviorItemFollower.cpp @@ -0,0 +1,44 @@ +#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules + +#include "BehaviorItemFollower.h" +#include "../Monster.h" +#include "../../World.h" +#include "../../Entities/Player.h" + +iBehaviorItemFollower::~iBehaviorItemFollower() +{ + +} + +cBehaviorItemFollower::cBehaviorItemFollower(iBehaviorItemFollower * a_ParentInterface) : + m_ParentInterface(a_ParentInterface) +{ + m_Parent = dynamic_cast<cMonster *>(m_ParentInterface); + ASSERT(m_Parent != nullptr); +} + + + + + +bool cBehaviorItemFollower::ActiveTick() +{ + cWorld * World = m_Parent->GetWorld(); + cItems FollowedItems; + m_ParentInterface->GetFollowedItems(FollowedItems); + if (FollowedItems.Size() > 0) + { + cPlayer * a_Closest_Player = m_Parent->GetNearestPlayer(); + if (a_Closest_Player != nullptr) + { + cItem EquippedItem = a_Closest_Player->GetEquippedItem(); + if (FollowedItems.ContainsType(EquippedItem)) + { + Vector3d PlayerPos = a_Closest_Player->GetPosition(); + m_Parent->MoveToPosition(PlayerPos); + return true; // We took control of the monster, prevent other Behaviors from doing so + } + } + } + return false; +} |