diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-01-25 16:19:56 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2014-01-25 16:19:56 +0100 |
commit | d9707a92917308fcf29827e6ca5f577624418a1c (patch) | |
tree | 0f30520d1d91cc821b9db3c2744dbbbefe6a2df6 | |
parent | Mob bugfixes (diff) | |
download | cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar.gz cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar.bz2 cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar.lz cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar.xz cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.tar.zst cuberite-d9707a92917308fcf29827e6ca5f577624418a1c.zip |
-rw-r--r-- | src/Entities/Pickup.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp index 55c878b57..bfe162b69 100644 --- a/src/Entities/Pickup.cpp +++ b/src/Entities/Pickup.cpp @@ -17,6 +17,51 @@ +class cPickupCombiningCallback : + public cEntityCallback +{ +public: + cPickupCombiningCallback(Vector3d a_Position, cPickup * a_Pickup) : + m_Position(a_Position), + m_Pickup(a_Pickup), + m_FoundMatchingPickup(false) + { + } + + virtual bool Item(cEntity * a_Entity) override + { + if (!a_Entity->IsPickup() || (a_Entity->GetUniqueID() == m_Pickup->GetUniqueID()) || a_Entity->IsDestroyed()) + { + return false; + } + + Vector3d EntityPos = a_Entity->GetPosition(); + double Distance = (EntityPos - m_Position).Length(); + + if ((Distance < 1.2) && ((cPickup *)a_Entity)->GetItem().IsEqual(m_Pickup->GetItem())) + { + m_Pickup->GetItem().AddCount(((cPickup *)a_Entity)->GetItem().m_ItemCount); + a_Entity->Destroy(); + m_FoundMatchingPickup = true; + } + return false; + } + + inline bool FoundMatchingPickup() + { + return m_FoundMatchingPickup; + } + +protected: + bool m_FoundMatchingPickup; + + Vector3d m_Position; + cPickup * m_Pickup; +}; + + + + cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX /* = 0.f */, float a_SpeedY /* = 0.f */, float a_SpeedZ /* = 0.f */) : cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2) @@ -83,6 +128,16 @@ void cPickup::Tick(float a_Dt, cChunk & a_Chunk) return; } } + + if (!IsDestroyed()) // Don't try to combine if someone has tried to combine me + { + cPickupCombiningCallback PickupCombiningCallback(GetPosition(), this); + m_World->ForEachEntity(PickupCombiningCallback); // Not ForEachEntityInChunk, otherwise pickups don't combine across chunk boundaries + if (PickupCombiningCallback.FoundMatchingPickup()) + { + m_World->BroadcastEntityMetadata(*this); + } + } } } } |