summaryrefslogtreecommitdiffstats
path: root/src/Mobs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Mobs')
-rw-r--r--src/Mobs/Monster.cpp12
-rw-r--r--src/Mobs/Ocelot.cpp10
-rw-r--r--src/Mobs/PassiveMonster.cpp11
-rw-r--r--src/Mobs/Wolf.cpp13
4 files changed, 23 insertions, 23 deletions
diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp
index 3c202d693..5327da832 100644
--- a/src/Mobs/Monster.cpp
+++ b/src/Mobs/Monster.cpp
@@ -660,7 +660,7 @@ void cMonster::KilledBy(TakeDamageInfo & a_TDI)
}
if ((a_TDI.Attacker != nullptr) && (!IsBaby()))
{
- m_World->SpawnExperienceOrb(GetPosX(), GetPosY(), GetPosZ(), Reward);
+ m_World->SpawnSplitExperienceOrbs(GetPosX(), GetPosY(), GetPosZ(), Reward);
}
m_DestroyTimer = std::chrono::milliseconds(0);
}
@@ -712,13 +712,11 @@ void cMonster::OnRightClicked(cPlayer & a_Player)
// monster sez: Do I see the player
void cMonster::CheckEventSeePlayer(cChunk & a_Chunk)
{
- // TODO: Rewrite this to use cWorld's DoWithPlayers()
- cPlayer * Closest = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance), false);
-
- if (Closest != nullptr)
+ m_World->DoWithNearestPlayer(GetPosition(), static_cast<float>(m_SightDistance), [&](cPlayer & a_Player) -> bool
{
- EventSeePlayer(Closest, a_Chunk);
- }
+ EventSeePlayer(&a_Player, a_Chunk);
+ return true;
+ }, false);
}
diff --git a/src/Mobs/Ocelot.cpp b/src/Mobs/Ocelot.cpp
index 02af45a7d..855a11627 100644
--- a/src/Mobs/Ocelot.cpp
+++ b/src/Mobs/Ocelot.cpp
@@ -47,12 +47,11 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
{
if (m_CheckPlayerTickCount == 23)
{
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), 10, true);
- if (a_Closest_Player != nullptr)
+ m_World->DoWithNearestPlayer(GetPosition(), 10, [&](cPlayer & a_Player) -> bool
{
cItems Items;
GetBreedingItems(Items);
- if (Items.ContainsType(a_Closest_Player->GetEquippedItem().m_ItemType))
+ if (Items.ContainsType(a_Player.GetEquippedItem().m_ItemType))
{
if (!IsBegging())
{
@@ -60,7 +59,7 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_World->BroadcastEntityMetadata(*this);
}
- MoveToPosition(a_Closest_Player->GetPosition());
+ MoveToPosition(a_Player.GetPosition());
}
else
{
@@ -70,8 +69,9 @@ void cOcelot::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_World->BroadcastEntityMetadata(*this);
}
}
- }
+ return true;
+ }, true);
m_CheckPlayerTickCount = 0;
}
else
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index c9345662d..cd0f59153 100644
--- a/src/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
@@ -136,16 +136,17 @@ void cPassiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
GetFollowedItems(FollowedItems);
if (FollowedItems.Size() > 0)
{
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance));
- if (a_Closest_Player != nullptr)
+ m_World->DoWithNearestPlayer(GetPosition(), static_cast<float>(m_SightDistance), [&](cPlayer & a_Player) -> bool
{
- cItem EquippedItem = a_Closest_Player->GetEquippedItem();
+ cItem EquippedItem = a_Player.GetEquippedItem();
if (FollowedItems.ContainsType(EquippedItem))
{
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
+ Vector3d PlayerPos = a_Player.GetPosition();
MoveToPosition(PlayerPos);
}
- }
+
+ return true;
+ });
}
}
diff --git a/src/Mobs/Wolf.cpp b/src/Mobs/Wolf.cpp
index 401175bf0..74924ab11 100644
--- a/src/Mobs/Wolf.cpp
+++ b/src/Mobs/Wolf.cpp
@@ -271,10 +271,9 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (GetTarget() == nullptr)
{
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), static_cast<float>(m_SightDistance));
- if (a_Closest_Player != nullptr)
+ m_World->DoWithNearestPlayer(GetPosition(), static_cast<float>(m_SightDistance), [&](cPlayer & a_Player) -> bool
{
- switch (a_Closest_Player->GetEquippedItem().m_ItemType)
+ switch (a_Player.GetEquippedItem().m_ItemType)
{
case E_ITEM_BONE:
case E_ITEM_RAW_BEEF:
@@ -291,12 +290,12 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
m_World->BroadcastEntityMetadata(*this);
}
- m_FinalDestination = a_Closest_Player->GetPosition(); // So that we will look at a player holding food
+ m_FinalDestination = a_Player.GetPosition(); // So that we will look at a player holding food
// Don't move to the player if the wolf is sitting.
if (!IsSitting())
{
- MoveToPosition(a_Closest_Player->GetPosition());
+ MoveToPosition(a_Player.GetPosition());
}
break;
@@ -310,7 +309,9 @@ void cWolf::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
}
- }
+
+ return true;
+ });
}
else
{