summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/BlockEntities/BlockEntityWithItems.h7
-rw-r--r--src/BlockEntities/ChestEntity.h4
-rw-r--r--src/BlockEntities/DropSpenserEntity.h4
-rw-r--r--src/BlockEntities/EnderChestEntity.h4
-rw-r--r--src/BlockEntities/FurnaceEntity.h4
-rw-r--r--src/BlockEntities/HopperEntity.cpp53
-rw-r--r--src/BlockEntities/HopperEntity.h4
-rw-r--r--src/ItemGrid.cpp7
8 files changed, 54 insertions, 33 deletions
diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h
index bf6289a2f..918781a00 100644
--- a/src/BlockEntities/BlockEntityWithItems.h
+++ b/src/BlockEntities/BlockEntityWithItems.h
@@ -11,6 +11,7 @@
#include "BlockEntity.h"
#include "../ItemGrid.h"
+#include "../UI/WindowOwner.h"
@@ -22,6 +23,7 @@ class cBlockEntityWithItems :
// tolua_end
// tolua doesn't seem to support multiple inheritance?
, public cItemGrid::cListener
+ , public cBlockEntityWindowOwner
// tolua_begin
{
typedef cBlockEntity super;
@@ -77,6 +79,11 @@ protected:
ASSERT(a_Grid == &m_Contents);
if (m_World != NULL)
{
+ if (GetWindow() != NULL)
+ {
+ GetWindow()->BroadcastWholeWindow();
+ }
+
m_World->MarkChunkDirty(GetChunkX(), GetChunkZ());
}
}
diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h
index 1f5668f78..3167d64a0 100644
--- a/src/BlockEntities/ChestEntity.h
+++ b/src/BlockEntities/ChestEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -23,8 +22,7 @@ class cNBTData;
// tolua_begin
class cChestEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index f2f1eba36..47d3bd492 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -11,7 +11,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -31,8 +30,7 @@ class cServer;
// tolua_begin
class cDropSpenserEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h
index 0ee3cab3b..45beee45f 100644
--- a/src/BlockEntities/EnderChestEntity.h
+++ b/src/BlockEntities/EnderChestEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -23,8 +22,7 @@ class cNBTData;
// tolua_begin
class cEnderChestEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h
index b08187300..5e08ae37a 100644
--- a/src/BlockEntities/FurnaceEntity.h
+++ b/src/BlockEntities/FurnaceEntity.h
@@ -2,7 +2,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
#include "../FurnaceRecipe.h"
@@ -23,8 +22,7 @@ class cServer;
// tolua_begin
class cFurnaceEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
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;
};
diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h
index 2c8b301fe..6ef98f43a 100644
--- a/src/BlockEntities/HopperEntity.h
+++ b/src/BlockEntities/HopperEntity.h
@@ -10,7 +10,6 @@
#pragma once
#include "BlockEntityWithItems.h"
-#include "../UI/WindowOwner.h"
@@ -18,8 +17,7 @@
// tolua_begin
class cHopperEntity :
- public cBlockEntityWithItems,
- public cBlockEntityWindowOwner
+ public cBlockEntityWithItems
{
typedef cBlockEntityWithItems super;
diff --git a/src/ItemGrid.cpp b/src/ItemGrid.cpp
index e8b58695f..34a267bab 100644
--- a/src/ItemGrid.cpp
+++ b/src/ItemGrid.cpp
@@ -369,6 +369,13 @@ int cItemGrid::ChangeSlotCount(int a_SlotNum, int a_AddToCount)
}
m_Slots[a_SlotNum].m_ItemCount += a_AddToCount;
+
+ cItemHandler * Handler = cItemHandler::GetItemHandler(m_Slots[a_SlotNum].m_ItemType);
+ if (m_Slots[a_SlotNum].m_ItemCount > Handler->GetMaxStackSize())
+ {
+ m_Slots[a_SlotNum].m_ItemCount = Handler->GetMaxStackSize();
+ }
+
TriggerListeners(a_SlotNum);
return m_Slots[a_SlotNum].m_ItemCount;
}