1
0

Changed inheritance a bit

* cBlockEntityWithItems now inherits from cBlockEntityWindowOwner
This commit is contained in:
Tiger Wang 2014-02-12 22:01:22 +00:00
parent 91ebb6cef0
commit f97ce30151
8 changed files with 55 additions and 34 deletions

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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,35 +220,52 @@ 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()))
{
m_bFoundPickupsAbove = true;
m_Contents.ChangeSlotCount(i, ((cPickup *)a_Entity)->GetItem().m_ItemCount);
a_Entity->Destroy();
return false;
}
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())
{
//LOGINFO("Pickup was empty!");
a_Pickup->Destroy(); // Kill pickup if all items were added
}
return true;
}
}
return false;
}
bool FoundPickupsAbove(void) const
{
return m_bFoundPickupsAbove;
}
protected:
Vector3i m_Pos;
const Vector3i m_Pos;
bool m_bFoundPickupsAbove;
cItemGrid & m_Contents;
};

View File

@ -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;

View File

@ -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;
}