summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/HopperEntity.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-12 23:01:22 +0100
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-02-12 23:01:22 +0100
commitf97ce3015171fcc6f6c5316810d19eb37c89c5f7 (patch)
tree9be0de9fb745d726242b0137a70665d88cb88ecb /src/BlockEntities/HopperEntity.cpp
parentMade player jump reset less ambiguous (diff)
downloadcuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar.gz
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar.bz2
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar.lz
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar.xz
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.tar.zst
cuberite-f97ce3015171fcc6f6c5316810d19eb37c89c5f7.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/HopperEntity.cpp53
1 files changed, 35 insertions, 18 deletions
diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp
index 2d07ce6c7..b2fe7ee99 100644
--- a/src/BlockEntities/HopperEntity.cpp
+++ b/src/BlockEntities/HopperEntity.cpp
@@ -198,10 +198,10 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
public cEntityCallback
{
public:
- cHopperPickupSearchCallback(Vector3i a_Pos, cItemGrid & a_Contents) :
+ cHopperPickupSearchCallback(const Vector3i a_Pos, cItemGrid & a_Contents) :
m_Pos(a_Pos),
- m_Contents(a_Contents),
- m_bFoundPickupsAbove(false)
+ m_bFoundPickupsAbove(false),
+ m_Contents(a_Contents)
{
}
@@ -220,25 +220,42 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
if (Distance < 0.5)
{
- for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
+ if (TrySuckPickupIn((cPickup *)a_Entity))
{
- if (m_Contents.IsSlotEmpty(i))
- {
- m_bFoundPickupsAbove = true;
- m_Contents.SetSlot(i, ((cPickup *)a_Entity)->GetItem());
- a_Entity->Destroy(); // Kill pickup
- return false; // Don't break enumeration
- }
- else if (m_Contents.GetSlot(i).IsEqual(((cPickup *)a_Entity)->GetItem()))
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+ bool TrySuckPickupIn(cPickup * a_Pickup)
+ {
+ for (int i = 0; i < ContentsWidth * ContentsHeight; i++)
+ {
+ if (m_Contents.IsSlotEmpty(i))
+ {
+ m_bFoundPickupsAbove = true;
+ m_Contents.SetSlot(i, a_Pickup->GetItem());
+ a_Pickup->Destroy(); // Kill pickup
+ return true;
+ }
+ else if (m_Contents.GetSlot(i).IsEqual(a_Pickup->GetItem()) && !m_Contents.GetSlot(i).IsFullStack())
+ {
+ m_bFoundPickupsAbove = true;
+ LOGINFO("Previous counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount);
+ int PreviousCount = m_Contents.GetSlot(i).m_ItemCount;
+ a_Pickup->GetItem().m_ItemCount -= m_Contents.ChangeSlotCount(i, a_Pickup->GetItem().m_ItemCount) - PreviousCount; // Set count to however many items were added
+ LOGINFO("After counts, pickup: %i, hopper: %i", (int)a_Pickup->GetItem().m_ItemCount, (int)m_Contents.GetSlot(i).m_ItemCount);
+
+ if (a_Pickup->GetItem().IsEmpty())
{
- m_bFoundPickupsAbove = true;
- m_Contents.ChangeSlotCount(i, ((cPickup *)a_Entity)->GetItem().m_ItemCount);
- a_Entity->Destroy();
- return false;
+ //LOGINFO("Pickup was empty!");
+ a_Pickup->Destroy(); // Kill pickup if all items were added
}
+ return true;
}
}
-
return false;
}
@@ -248,7 +265,7 @@ bool cHopperEntity::MovePickupsIn(cChunk & a_Chunk, Int64 a_CurrentTick)
}
protected:
- Vector3i m_Pos;
+ const Vector3i m_Pos;
bool m_bFoundPickupsAbove;
cItemGrid & m_Contents;
};