summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Mobs/Chicken.cpp23
-rw-r--r--src/Mobs/Chicken.h4
-rw-r--r--src/Mobs/Cow.cpp27
-rw-r--r--src/Mobs/Cow.h7
-rw-r--r--src/Mobs/Mooshroom.cpp28
-rw-r--r--src/Mobs/Mooshroom.h8
-rw-r--r--src/Mobs/PassiveMonster.cpp16
-rw-r--r--src/Mobs/PassiveMonster.h2
-rw-r--r--src/Mobs/Pig.cpp28
-rw-r--r--src/Mobs/Pig.h5
-rw-r--r--src/Mobs/Sheep.cpp23
-rw-r--r--src/Mobs/Sheep.h6
12 files changed, 25 insertions, 152 deletions
diff --git a/src/Mobs/Chicken.cpp b/src/Mobs/Chicken.cpp
index 52c8d3788..90d56d1de 100644
--- a/src/Mobs/Chicken.cpp
+++ b/src/Mobs/Chicken.cpp
@@ -41,29 +41,6 @@ void cChicken::Tick(float a_Dt, cChunk & a_Chunk)
{
m_EggDropTimer++;
}
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
- if (a_Closest_Player != NULL)
- {
- if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_SEEDS)
- {
- if (!IsBegging())
- {
- m_IsBegging = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
- PlayerPos.y++;
- m_FinalDestination = PlayerPos;
- }
- else
- {
- if (IsBegging())
- {
- m_IsBegging = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
}
diff --git a/src/Mobs/Chicken.h b/src/Mobs/Chicken.h
index b9cff40d4..a4c1d6b9e 100644
--- a/src/Mobs/Chicken.h
+++ b/src/Mobs/Chicken.h
@@ -19,13 +19,11 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
- bool IsBegging (void) const { return m_IsBegging; }
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_SEEDS); }
private:
-
int m_EggDropTimer;
- bool m_IsBegging;
} ;
diff --git a/src/Mobs/Cow.cpp b/src/Mobs/Cow.cpp
index 4063f034d..d8e905217 100644
--- a/src/Mobs/Cow.cpp
+++ b/src/Mobs/Cow.cpp
@@ -41,30 +41,3 @@ void cCow::OnRightClicked(cPlayer & a_Player)
}
}
-void cCow::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
- if (a_Closest_Player != NULL)
- {
- if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
- {
- if (!IsBegging())
- {
- m_IsBegging = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
- PlayerPos.y++;
- m_FinalDestination = PlayerPos;
- }
- else
- {
- if (IsBegging())
- {
- m_IsBegging = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
-}
diff --git a/src/Mobs/Cow.h b/src/Mobs/Cow.h
index b001ea856..973171ab5 100644
--- a/src/Mobs/Cow.h
+++ b/src/Mobs/Cow.h
@@ -19,13 +19,8 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
- bool IsBegging (void) const { return m_IsBegging; }
-
-private:
-
- bool m_IsBegging;
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
} ;
diff --git a/src/Mobs/Mooshroom.cpp b/src/Mobs/Mooshroom.cpp
index 60721f0ee..00ba339a6 100644
--- a/src/Mobs/Mooshroom.cpp
+++ b/src/Mobs/Mooshroom.cpp
@@ -30,32 +30,4 @@ void cMooshroom::GetDrops(cItems & a_Drops, cEntity * a_Killer)
}
-void cMooshroom::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
- if (a_Closest_Player != NULL)
- {
- if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
- {
- if (!IsBegging())
- {
- m_IsBegging = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
- PlayerPos.y++;
- m_FinalDestination = PlayerPos;
- }
- else
- {
- if (IsBegging())
- {
- m_IsBegging = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
-}
-
diff --git a/src/Mobs/Mooshroom.h b/src/Mobs/Mooshroom.h
index c288f68a9..c94301098 100644
--- a/src/Mobs/Mooshroom.h
+++ b/src/Mobs/Mooshroom.h
@@ -18,14 +18,8 @@ public:
CLASS_PROTODEF(cMooshroom);
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
-
- bool IsBegging (void) const { return m_IsBegging; }
-
-private:
-
- bool m_IsBegging;
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
} ;
diff --git a/src/Mobs/PassiveMonster.cpp b/src/Mobs/PassiveMonster.cpp
index d774d3170..903761a95 100644
--- a/src/Mobs/PassiveMonster.cpp
+++ b/src/Mobs/PassiveMonster.cpp
@@ -3,7 +3,7 @@
#include "PassiveMonster.h"
#include "../World.h"
-
+#include "../Entities/Player.h"
@@ -39,6 +39,20 @@ void cPassiveMonster::Tick(float a_Dt, cChunk & a_Chunk)
{
CheckEventLostPlayer();
}
+ cItem FollowedItem = GetFollowedItem();
+ if (FollowedItem.IsEmpty())
+ {
+ return;
+ }
+ cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
+ if (a_Closest_Player != NULL)
+ {
+ if (a_Closest_Player->GetEquippedItem().m_ItemType == FollowedItem.m_ItemType)
+ {
+ Vector3d PlayerPos = a_Closest_Player->GetPosition();
+ MoveToPosition(PlayerPos);
+ }
+ }
}
diff --git a/src/Mobs/PassiveMonster.h b/src/Mobs/PassiveMonster.h
index 14a6be6b1..7da5d71bc 100644
--- a/src/Mobs/PassiveMonster.h
+++ b/src/Mobs/PassiveMonster.h
@@ -20,6 +20,8 @@ public:
/// When hit by someone, run away
virtual void DoTakeDamage(TakeDamageInfo & a_TDI) override;
+ virtual const cItem GetFollowedItem(void) const { return cItem(); }
+
} ;
diff --git a/src/Mobs/Pig.cpp b/src/Mobs/Pig.cpp
index b6d11d856..d8f3dda37 100644
--- a/src/Mobs/Pig.cpp
+++ b/src/Mobs/Pig.cpp
@@ -71,33 +71,5 @@ void cPig::OnRightClicked(cPlayer & a_Player)
}
}
-void cPig::Tick(float a_Dt, cChunk & a_Chunk)
-{
- super::Tick(a_Dt, a_Chunk);
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
- if (a_Closest_Player != NULL)
- {
- if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_CARROT)
- {
- if (!IsBegging())
- {
- m_IsBegging = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
- PlayerPos.y++;
- m_FinalDestination = PlayerPos;
- }
- else
- {
- if (IsBegging())
- {
- m_IsBegging = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
-}
-
diff --git a/src/Mobs/Pig.h b/src/Mobs/Pig.h
index f42a4f412..d434324c1 100644
--- a/src/Mobs/Pig.h
+++ b/src/Mobs/Pig.h
@@ -19,14 +19,13 @@ public:
virtual void GetDrops(cItems & a_Drops, cEntity * a_Killer = NULL) override;
virtual void OnRightClicked(cPlayer & a_Player) override;
- virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
+
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_CARROT); }
bool IsSaddled(void) const { return m_bIsSaddled; }
- bool IsBegging (void) const { return m_IsBegging; }
private:
- bool m_IsBegging;
bool m_bIsSaddled;
} ;
diff --git a/src/Mobs/Sheep.cpp b/src/Mobs/Sheep.cpp
index c8ff8f5c8..4761103e5 100644
--- a/src/Mobs/Sheep.cpp
+++ b/src/Mobs/Sheep.cpp
@@ -95,29 +95,6 @@ void cSheep::Tick(float a_Dt, cChunk & a_Chunk)
m_TimeToStopEating = 40;
}
}
- cPlayer * a_Closest_Player = m_World->FindClosestPlayer(GetPosition(), (float)m_SightDistance);
- if (a_Closest_Player != NULL)
- {
- if (a_Closest_Player->GetEquippedItem().m_ItemType == E_ITEM_WHEAT)
- {
- if (!IsBegging())
- {
- m_IsBegging = true;
- m_World->BroadcastEntityMetadata(*this);
- }
- Vector3d PlayerPos = a_Closest_Player->GetPosition();
- PlayerPos.y++;
- m_FinalDestination = PlayerPos;
- }
- else
- {
- if (IsBegging())
- {
- m_IsBegging = false;
- m_World->BroadcastEntityMetadata(*this);
- }
- }
- }
}
}
diff --git a/src/Mobs/Sheep.h b/src/Mobs/Sheep.h
index 322b31dd9..402e8e61c 100644
--- a/src/Mobs/Sheep.h
+++ b/src/Mobs/Sheep.h
@@ -21,13 +21,13 @@ public:
virtual void OnRightClicked(cPlayer & a_Player) override;
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
- bool IsBegging(void) const { return m_IsBegging; }
+ virtual const cItem GetFollowedItem(void) const override { return cItem(E_ITEM_WHEAT); }
+
bool IsSheared(void) const { return m_IsSheared; }
int GetFurColor(void) const { return m_WoolColor; }
private:
-
- bool m_IsBegging;
+
bool m_IsSheared;
int m_WoolColor;
int m_TimeToStopEating;