summaryrefslogtreecommitdiffstats
path: root/source/cCraftingWindow.cpp
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-04 14:08:20 +0200
commitb355bdeccecf727d30e48634df9b5d424db570bc (patch)
tree00489a1317e6ad22a28698f24bd9935160257789 /source/cCraftingWindow.cpp
parentFixed MSVC2010 projects for new zlib (diff)
downloadcuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.gz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.bz2
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.lz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.xz
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.tar.zst
cuberite-b355bdeccecf727d30e48634df9b5d424db570bc.zip
Diffstat (limited to 'source/cCraftingWindow.cpp')
-rw-r--r--source/cCraftingWindow.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp
index 71ffe96b3..94bc3cde8 100644
--- a/source/cCraftingWindow.cpp
+++ b/source/cCraftingWindow.cpp
@@ -4,6 +4,7 @@
#include "cCraftingWindow.h"
#include "cItem.h"
#include "cRecipeChecker.h"
+#include "CraftingRecipes.h"
#include "cPlayer.h"
#include "cClientHandle.h"
#include "cInventory.h"
@@ -13,6 +14,10 @@
#include "packets/cPacket_WindowClick.h"
#include "packets/cPacket_InventorySlot.h"
+
+
+
+
cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisible )
: cWindow( a_Owner, a_bInventoryVisible )
{
@@ -23,6 +28,10 @@ cCraftingWindow::cCraftingWindow( cWindowOwner* a_Owner, bool a_bInventoryVisibl
SetSlots( Slots, 10 );
}
+
+
+
+
void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_Player )
{
bool bDontCook = false;
@@ -59,25 +68,41 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
cWindow::Clicked( a_ClickPacket, a_Player );
}
- if( a_ClickPacket->m_SlotNum >= 0 && a_ClickPacket->m_SlotNum < 10 )
+ if ((a_ClickPacket->m_SlotNum >= 0) && (a_ClickPacket->m_SlotNum < 10))
{
cItem CookedItem;
- if( a_ClickPacket->m_SlotNum == 0 && !bDontCook )
+ if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook)
{
- CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3, true );
+ // Consume the ingredients from the crafting grid:
+ CookedItem = cRoot::Get()->GetCraftingRecipes()->Craft(GetSlots() + 1, 3, 3);
+ LOGD("New recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount);
+ // Upgrade the crafting result from the new crafting grid contents:
+ CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3);
+ if (CookedItem.IsEmpty())
+ {
+ // Fallback to the old recipes:
+ CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3, true );
+ LOGD("Old recipes crafted: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
+ }
}
else
{
- CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3 );
+ CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(GetSlots() + 1, 3, 3);
+ LOGD("New recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
+ if (CookedItem.IsEmpty())
+ {
+ // Fallback to the old recipes
+ CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( GetSlots()+1, 3, 3 );
+ LOGD("Old recipes offer: %i x %i", CookedItem.m_ItemID, CookedItem.m_ItemCount );
+ }
}
*GetSlot(0) = CookedItem;
LOG("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
}
SendWholeWindow( a_Player.GetClientHandle() );
a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
- //Separate packet for result =/ Don't know why
-
-
+
+ // Separate packet for result =/ Don't know why
cPacket_InventorySlot Packet;
Packet.m_WindowID = (char)GetWindowID();
Packet.m_SlotNum = 0;
@@ -85,9 +110,12 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
Packet.m_ItemCount = GetSlot(0)->m_ItemCount;
Packet.m_ItemUses = (char)GetSlot(0)->m_ItemHealth;
a_Player.GetClientHandle()->Send( Packet );
-
}
+
+
+
+
void cCraftingWindow::Close( cPlayer & a_Player )
{
// Start from slot 1, don't drop what's in the result slot
@@ -105,4 +133,8 @@ void cCraftingWindow::Close( cPlayer & a_Player )
Item->Empty();
}
cWindow::Close( a_Player );
-} \ No newline at end of file
+}
+
+
+
+