summaryrefslogtreecommitdiffstats
path: root/src/Entities/Pickup.cpp
diff options
context:
space:
mode:
authorLane Kolbly <lane@rscheme.org>2017-07-12 12:13:27 +0200
committerLukas Pioch <lukas@zgow.de>2017-07-12 12:13:27 +0200
commit793acd267f4a5801e2aa9e9dca7cf51c5a595a02 (patch)
tree0e2740c09bfbbff7fb297f990ecca1b0090ddcc3 /src/Entities/Pickup.cpp
parentIf entity is a player, send relmove packets. (diff)
downloadcuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar.gz
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar.bz2
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar.lz
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar.xz
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.tar.zst
cuberite-793acd267f4a5801e2aa9e9dca7cf51c5a595a02.zip
Diffstat (limited to '')
-rw-r--r--src/Entities/Pickup.cpp16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Entities/Pickup.cpp b/src/Entities/Pickup.cpp
index 5f64d6fbe..0c6c8feab 100644
--- a/src/Entities/Pickup.cpp
+++ b/src/Entities/Pickup.cpp
@@ -40,8 +40,9 @@ public:
Vector3d EntityPos = a_Entity->GetPosition();
double Distance = (EntityPos - m_Position).Length();
- cItem & Item = static_cast<cPickup *>(a_Entity)->GetItem();
- if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem()))
+ cPickup * OtherPickup = static_cast<cPickup *>(a_Entity);
+ cItem & Item = OtherPickup->GetItem();
+ if ((Distance < 1.2) && Item.IsEqual(m_Pickup->GetItem()) && OtherPickup->CanCombine())
{
short CombineCount = Item.m_ItemCount;
if ((CombineCount + m_Pickup->GetItem().m_ItemCount) > Item.GetMaxStackSize())
@@ -66,6 +67,9 @@ public:
a_Entity->GetWorld()->BroadcastEntityRelMove(*a_Entity, static_cast<char>(DiffX), static_cast<char>(DiffY), static_cast<char>(DiffZ));
/* End of experimental animation */
a_Entity->Destroy();
+
+ // Reset the timer
+ m_Pickup->SetAge(0);
}
else
{
@@ -92,12 +96,14 @@ protected:
-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 */)
+cPickup::cPickup(double a_PosX, double a_PosY, double a_PosZ, const cItem & a_Item, bool IsPlayerCreated, float a_SpeedX, float a_SpeedY, float a_SpeedZ, int a_LifetimeTicks, bool a_CanCombine)
: cEntity(etPickup, a_PosX, a_PosY, a_PosZ, 0.2, 0.2)
, m_Timer(0)
, m_Item(a_Item)
, m_bCollected(false)
, m_bIsPlayerCreated(IsPlayerCreated)
+ , m_bCanCombine(a_CanCombine)
+ , m_Lifetime(cTickTime(a_LifetimeTicks))
{
SetGravity(-16.0f);
SetAirDrag(0.02f);
@@ -165,7 +171,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
// Try to combine the pickup with adjacent same-item pickups:
- if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize()) && IsOnGround()) // Don't combine if already full or not on ground
+ if ((m_Item.m_ItemCount < m_Item.GetMaxStackSize()) && IsOnGround() && CanCombine()) // Don't combine if already full or not on ground
{
// By using a_Chunk's ForEachEntity() instead of cWorld's, pickups don't combine across chunk boundaries.
// That is a small price to pay for not having to traverse the entire world for each entity.
@@ -188,7 +194,7 @@ void cPickup::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
}
}
- if (m_Timer > std::chrono::minutes(5)) // 5 minutes
+ if (m_Timer > m_Lifetime)
{
Destroy(true);
return;