summaryrefslogtreecommitdiffstats
path: root/source/cSurvivalInventory.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/cSurvivalInventory.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 '')
-rw-r--r--source/cSurvivalInventory.cpp90
1 files changed, 90 insertions, 0 deletions
diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp
new file mode 100644
index 000000000..1618e04ae
--- /dev/null
+++ b/source/cSurvivalInventory.cpp
@@ -0,0 +1,90 @@
+#include "cSurvivalInventory.h"
+#include <string> //memset
+#include "cPlayer.h"
+#include "cClientHandle.h"
+#include "cMCLogger.h"
+#include "cWindow.h"
+#include "cItem.h"
+#include "cRecipeChecker.h"
+#include "cRoot.h"
+#include "packets/cPacket_WindowClick.h"
+
+cSurvivalInventory::~cSurvivalInventory()
+{
+ if( GetWindow() ) GetWindow()->Close( *m_Owner );
+ CloseWindow();
+}
+
+cSurvivalInventory::cSurvivalInventory(cPlayer* a_Owner)
+ : cInventory(a_Owner)
+{
+ if( !GetWindow() )
+ {
+ cWindow* Window = new cWindow( this, false );
+ Window->SetSlots( m_Slots, c_NumSlots );
+ Window->SetWindowID( 0 );
+ OpenWindow( Window );
+ }
+}
+
+void cSurvivalInventory::Clicked( cPacket* a_ClickPacket )
+{
+ cPacket_WindowClick *Packet = reinterpret_cast<cPacket_WindowClick *>(a_ClickPacket);
+ bool bDontCook = false;
+ if( GetWindow() )
+ {
+ // Override for craft result slot
+ if( Packet->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( Packet, *m_Owner );
+ }
+ }
+ else
+ {
+ LOG("No Inventory window! WTF");
+ }
+
+ if( Packet->m_SlotNum >= (short)c_CraftOffset && Packet->m_SlotNum < (short)(c_CraftOffset+c_CraftSlots+1) )
+ {
+ cItem CookedItem;
+ if( Packet->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 );
+}