summaryrefslogtreecommitdiffstats
path: root/src/Items/ItemFishingRod.h
diff options
context:
space:
mode:
authorSTRWarrior <niels.breuker@hotmail.nl>2013-12-25 17:26:17 +0100
committerSTRWarrior <niels.breuker@hotmail.nl>2013-12-25 17:26:17 +0100
commit17a84111ceb1c1d28bc420eeae9262bc10b869b9 (patch)
tree0eabab76bc24bf4ca23832f4ae3468f9f3e8b005 /src/Items/ItemFishingRod.h
parentMerge pull request #469 from mc-server/Android_Update (diff)
downloadcuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar.gz
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar.bz2
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar.lz
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar.xz
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.tar.zst
cuberite-17a84111ceb1c1d28bc420eeae9262bc10b869b9.zip
Diffstat (limited to '')
-rw-r--r--src/Items/ItemFishingRod.h90
1 files changed, 64 insertions, 26 deletions
diff --git a/src/Items/ItemFishingRod.h b/src/Items/ItemFishingRod.h
index a427b1676..941ce3b71 100644
--- a/src/Items/ItemFishingRod.h
+++ b/src/Items/ItemFishingRod.h
@@ -15,6 +15,61 @@
+/////////////////////////////////////////////////////////////////////////////////////
+// cFloaterCallback
+class cFloaterCallback :
+ public cEntityCallback
+{
+public:
+ cFloaterCallback(void) :
+ m_CanPickup(false),
+ m_AttachedMobID(-1)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ m_CanPickup = ((cFloater *)a_Entity)->CanPickup();
+ m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ());
+ m_AttachedMobID = ((cFloater *)a_Entity)->GetAttachedMobID();
+ a_Entity->Destroy(true);
+ return true;
+ }
+
+ bool CanPickup(void) const { return m_CanPickup; }
+ bool IsAttached(void) const { return (m_AttachedMobID != -1); }
+ int GetAttachedMobID(void) const { return m_AttachedMobID; }
+ Vector3d GetPos(void) const { return m_Pos; }
+
+protected:
+ bool m_CanPickup;
+ int m_AttachedMobID;
+ Vector3d m_Pos;
+} ;
+
+////////////////////////////////////////////////////////////////////////////
+// cSweepEntityCallback
+class cSweepEntityCallback :
+ public cEntityCallback
+{
+public:
+ cSweepEntityCallback(Vector3d a_PlayerPos) :
+ m_PlayerPos(a_PlayerPos)
+ {
+ }
+
+ virtual bool Item(cEntity * a_Entity) override
+ {
+ Vector3d Speed = m_PlayerPos - a_Entity->GetPosition();
+ a_Entity->AddSpeed(Speed);
+ return true;
+ }
+
+protected:
+ Vector3d m_PlayerPos;
+} ;
+
+
class cItemFishingRodHandler :
public cItemHandler
@@ -36,33 +91,16 @@ public:
if (a_Player->IsFishing())
{
- class cFloaterCallback :
- public cEntityCallback
- {
- public:
- cFloaterCallback(void) :
- m_CanPickup(false)
- {
- }
-
- bool CanPickup(void) const { return m_CanPickup; }
- Vector3d GetPos(void) const { return m_Pos; }
-
- virtual bool Item(cEntity * a_Entity) override
- {
- m_CanPickup = ((cFloater *)a_Entity)->CanPickup();
- m_Pos = Vector3d(a_Entity->GetPosX(), a_Entity->GetPosY(), a_Entity->GetPosZ());
- a_Entity->Destroy(true);
- return true;
- }
- protected:
- bool m_CanPickup;
- Vector3d m_Pos;
- } Callbacks;
- a_World->DoWithEntityByID(a_Player->GetFloaterID(), Callbacks);
+ cFloaterCallback FloaterInfo;
+ a_World->DoWithEntityByID(a_Player->GetFloaterID(), FloaterInfo);
a_Player->SetIsFishing(false);
- if (Callbacks.CanPickup())
+ if (FloaterInfo.IsAttached())
+ {
+ cSweepEntityCallback SweepEntity(a_Player->GetPosition());
+ a_World->DoWithEntityByID(FloaterInfo.GetAttachedMobID(), SweepEntity);
+ }
+ else if (FloaterInfo.CanPickup())
{
cItems Drops;
int ItemCategory = a_World->GetTickRandomNumber(99);
@@ -173,7 +211,7 @@ public:
}
- Vector3d FloaterPos = Callbacks.GetPos();
+ Vector3d FloaterPos = FloaterInfo.GetPos();
Vector3d FlyDirection = a_Player->GetEyePosition() - FloaterPos;
a_World->SpawnItemPickups(Drops, FloaterPos.x, FloaterPos.y, FloaterPos.z, FlyDirection.x, FlyDirection.y + 1, FlyDirection.z);
}