summaryrefslogtreecommitdiffstats
path: root/source/cInventory.cpp
diff options
context:
space:
mode:
authorlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-01 05:55:17 +0100
committerlapayo94@gmail.com <lapayo94@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-01-01 05:55:17 +0100
commitd7068b35a85f0c0248a5533240087747d02e1a17 (patch)
tree7d40a34bdda09c0fbccc9e8052043709cfd88d7b /source/cInventory.cpp
parentChests, furnaces and dispensers face the correct way now. (diff)
downloadcuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar.gz
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar.bz2
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar.lz
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar.xz
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.tar.zst
cuberite-d7068b35a85f0c0248a5533240087747d02e1a17.zip
Diffstat (limited to 'source/cInventory.cpp')
-rw-r--r--source/cInventory.cpp232
1 files changed, 74 insertions, 158 deletions
diff --git a/source/cInventory.cpp b/source/cInventory.cpp
index 18862b78b..9236a2387 100644
--- a/source/cInventory.cpp
+++ b/source/cInventory.cpp
@@ -18,8 +18,6 @@ cInventory::~cInventory()
{
delete [] m_Slots;
delete m_EquippedItem;
- if( GetWindow() ) GetWindow()->Close( *m_Owner );
- CloseWindow();
}
cInventory::cInventory(cPlayer* a_Owner)
@@ -37,155 +35,6 @@ cInventory::cInventory(cPlayer* a_Owner)
m_EquippedItem = new cItem();
m_EquippedSlot = 0;
-
- if( !GetWindow() )
- {
- cWindow* Window = new cWindow( this, false );
- Window->SetSlots( m_Slots, c_NumSlots );
- Window->SetWindowID( 0 );
- OpenWindow( Window );
- }
-}
-
-void cInventory::Clear()
-{
- for(unsigned int i = 0; i < c_NumSlots; i++)
- m_Slots[i].Empty();
-}
-
-cItem* cInventory::GetSlotsForType( int a_Type )
-{
- switch( a_Type )
- {
- case -1:
- return m_MainSlots;
- case -2:
- return m_CraftSlots;
- case -3:
- return m_ArmorSlots;
- }
- return 0;
-}
-
-int cInventory::GetSlotCountForType( int a_Type )
-{
- switch( a_Type )
- {
- case -1:
- return 36;
- case -2:
- case -3:
- return 4;
- }
- return 0;
-}
-
-void cInventory::Clicked( cPacket_WindowClick* a_ClickPacket )
-{
- bool bDontCook = false;
- if( GetWindow() )
- {
- // Override for craft result slot
- if( a_ClickPacket->m_SlotNum == (short)c_CraftOffset )
- {
- LOG("In craft slot: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount );
- cItem* DraggingItem = GetWindow()->GetDraggingItem();
- if( DraggingItem->IsEmpty() )
- {
- *DraggingItem = m_Slots[c_CraftOffset];
- m_Slots[c_CraftOffset].Empty();
- }
- else if( DraggingItem->Equals( m_Slots[c_CraftOffset] ) )
- {
- if( DraggingItem->m_ItemCount + m_Slots[c_CraftOffset].m_ItemCount <= 64 )
- {
- DraggingItem->m_ItemCount += m_Slots[c_CraftOffset].m_ItemCount;
- m_Slots[0].Empty();
- }
- else
- {
- bDontCook = true;
- }
- }
- else
- {
- bDontCook = true;
- }
- LOG("Dragging Dish %i", DraggingItem->m_ItemCount );
- }
- else
- {
- GetWindow()->Clicked( a_ClickPacket, *m_Owner );
- }
- }
- else
- {
- LOG("No Inventory window! WTF");
- }
-
- if( a_ClickPacket->m_SlotNum >= (short)c_CraftOffset && a_ClickPacket->m_SlotNum < (short)(c_CraftOffset+c_CraftSlots+1) )
- {
- cItem CookedItem;
- if( a_ClickPacket->m_SlotNum == 0 && !bDontCook )
- {
- CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2, true );
- }
- else
- {
- CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2 );
- }
- m_Slots[c_CraftOffset] = CookedItem;
- LOG("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount );
- SendWholeInventory( m_Owner->GetClientHandle() );
- }
- SendSlot( 0 );
-}
-
-bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ )
-{
- // Fill already present stacks
- if( a_Mode < 2 )
- {
- for(int i = 0; i < a_Size; i++)
- {
- if( m_Slots[i + a_Offset].m_ItemID == a_Item.m_ItemID && m_Slots[i + a_Offset].m_ItemCount < 64 )
- {
- int NumFree = 64 - m_Slots[i + a_Offset].m_ItemCount;
- if( NumFree >= a_Item.m_ItemCount )
- {
-
- //printf("1. Adding %i items ( free: %i )\n", a_Item.m_ItemCount, NumFree );
- m_Slots[i + a_Offset].m_ItemCount += a_Item.m_ItemCount;
- a_Item.m_ItemCount = 0;
- a_bChangedSlots[i + a_Offset] = true;
- break;
- }
- else
- {
- //printf("2. Adding %i items\n", NumFree );
- m_Slots[i + a_Offset].m_ItemCount += (char)NumFree;
- a_Item.m_ItemCount -= (char)NumFree;
- a_bChangedSlots[i + a_Offset] = true;
- }
- }
- }
- }
-
- if( a_Mode > 0 )
- {
- // If we got more left, find first empty slot
- for(int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++)
- {
- if( m_Slots[i + a_Offset].m_ItemID == -1 )
- {
- m_Slots[i + a_Offset] = a_Item;
- a_Item.m_ItemCount = 0;
- a_bChangedSlots[i + a_Offset] = true;
- }
- }
- }
-
- return true;
}
bool cInventory::AddItem( cItem & a_Item )
@@ -274,6 +123,40 @@ bool cInventory::RemoveItem( cItem & a_Item )
return false;
}
+void cInventory::Clear()
+{
+ for(unsigned int i = 0; i < c_NumSlots; i++)
+ m_Slots[i].Empty();
+}
+
+cItem* cInventory::GetSlotsForType( int a_Type )
+{
+ switch( a_Type )
+ {
+ case -1:
+ return m_MainSlots;
+ case -2:
+ return m_CraftSlots;
+ case -3:
+ return m_ArmorSlots;
+ }
+ return 0;
+}
+
+int cInventory::GetSlotCountForType( int a_Type )
+{
+ switch( a_Type )
+ {
+ case -1:
+ return 36;
+ case -2:
+ case -3:
+ return 4;
+ }
+ return 0;
+}
+
+
cItem* cInventory::GetSlot( int a_SlotNum )
{
if( a_SlotNum < 0 || a_SlotNum >= (short)c_NumSlots ) return 0;
@@ -328,18 +211,51 @@ void cInventory::SendSlot( int a_SlotNum )
}
}
-void cInventory::DrawInventory()
+bool cInventory::AddToBar( cItem & a_Item, const int a_Offset, const int a_Size, bool* a_bChangedSlots, int a_Mode /* = 0 */ )
{
- printf("%i %i %i %i\n", m_ArmorSlots[0].m_ItemCount, m_ArmorSlots[1].m_ItemCount, m_CraftSlots[0].m_ItemCount, m_CraftSlots[1].m_ItemCount );
- printf("%i %i %i %i\n", m_ArmorSlots[2].m_ItemCount, m_ArmorSlots[3].m_ItemCount, m_CraftSlots[2].m_ItemCount, m_CraftSlots[3].m_ItemCount );
- for(int y = 0; y < 4; y++)
+ // Fill already present stacks
+ if( a_Mode < 2 )
+ {
+ for(int i = 0; i < a_Size; i++)
+ {
+ if( m_Slots[i + a_Offset].m_ItemID == a_Item.m_ItemID && m_Slots[i + a_Offset].m_ItemCount < 64 && m_Slots[i + a_Offset].m_ItemHealth == a_Item.m_ItemHealth )
+ {
+ int NumFree = 64 - m_Slots[i + a_Offset].m_ItemCount;
+ if( NumFree >= a_Item.m_ItemCount )
+ {
+
+ //printf("1. Adding %i items ( free: %i )\n", a_Item.m_ItemCount, NumFree );
+ m_Slots[i + a_Offset].m_ItemCount += a_Item.m_ItemCount;
+ a_Item.m_ItemCount = 0;
+ a_bChangedSlots[i + a_Offset] = true;
+ break;
+ }
+ else
+ {
+ //printf("2. Adding %i items\n", NumFree );
+ m_Slots[i + a_Offset].m_ItemCount += (char)NumFree;
+ a_Item.m_ItemCount -= (char)NumFree;
+ a_bChangedSlots[i + a_Offset] = true;
+ }
+ }
+ }
+ }
+
+ if( a_Mode > 0 )
{
- for(int x = 0; x < 9; x++)
+ // If we got more left, find first empty slot
+ for(int i = 0; i < a_Size && a_Item.m_ItemCount > 0; i++)
{
- printf("%i ", m_MainSlots[x + y*9].m_ItemCount );
+ if( m_Slots[i + a_Offset].m_ItemID == -1 )
+ {
+ m_Slots[i + a_Offset] = a_Item;
+ a_Item.m_ItemCount = 0;
+ a_bChangedSlots[i + a_Offset] = true;
+ }
}
- printf("\n");
}
+
+ return true;
}
void cInventory::SaveToJson(Json::Value & a_Value)