From 5e6c7368592c0fbaa4d9d4320767d3cdcfd0261e Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Tue, 12 Jun 2012 20:03:46 +0000 Subject: Updated the crafting recipes architecture to better support crafting hooks. Removed the old recipe file and implementation altogether. git-svn-id: http://mc-server.googlecode.com/svn/trunk@597 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cSurvivalInventory.cpp | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'source/cSurvivalInventory.cpp') diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp index a39cc6b59..cd7b96ad8 100644 --- a/source/cSurvivalInventory.cpp +++ b/source/cSurvivalInventory.cpp @@ -6,7 +6,6 @@ #include "cClientHandle.h" #include "cWindow.h" #include "cItem.h" -#include "cRecipeChecker.h" #include "CraftingRecipes.h" #include "cRoot.h" #include "packets/cPacket_WindowClick.h" @@ -72,30 +71,24 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket ) if ((Packet->m_SlotNum >= (short)c_CraftOffset) && (Packet->m_SlotNum < (short)(c_CraftOffset + c_CraftSlots + 1))) { - cItem CookedItem; + cCraftingGrid Grid(m_Slots + c_CraftOffset + 1, 2, 2); + cCraftingRecipe Recipe(Grid); + + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); + if ((Packet->m_SlotNum == 0) && !bDontCook) { // Consume the items from the crafting grid: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Craft(m_Slots + c_CraftOffset + 1, 2, 2); - // Upgrade the crafting result from the new crafting grid contents: - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(m_Slots + c_CraftOffset + 1, 2, 2); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes: - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2, true ); - } - } - else - { - CookedItem = cRoot::Get()->GetCraftingRecipes()->Offer(m_Slots + c_CraftOffset + 1, 2, 2); - if (CookedItem.IsEmpty()) - { - // Fallback to the old recipes: - CookedItem = cRoot::Get()->GetRecipeChecker()->CookIngredients( m_Slots+c_CraftOffset+1, 2, 2 ); - } + Recipe.ConsumeIngredients(Grid); + + // Propagate grid back to m_Slots: + Grid.CopyToItems(m_Slots + c_CraftOffset + 1); + + // Get the recipe for the new grid contents: + cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe); } - m_Slots[c_CraftOffset] = CookedItem; - LOG("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); + m_Slots[c_CraftOffset] = Recipe.GetResult(); + LOGD("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount ); SendWholeInventory( m_Owner->GetClientHandle() ); } SendSlot( 0 ); -- cgit v1.2.3