diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-12 23:30:32 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-06-12 23:30:32 +0200 |
commit | 223967b80d783df1be2df5f74ddf198f373fbc57 (patch) | |
tree | 6bf155fc8cfbdf635b6ef40d4e7ab200029de6d9 /source/CraftingRecipes.cpp | |
parent | Updated the crafting recipes architecture to better support crafting hooks. Removed the old recipe file and implementation altogether. (diff) | |
download | cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar.gz cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar.bz2 cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar.lz cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar.xz cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.tar.zst cuberite-223967b80d783df1be2df5f74ddf198f373fbc57.zip |
Diffstat (limited to 'source/CraftingRecipes.cpp')
-rw-r--r-- | source/CraftingRecipes.cpp | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/source/CraftingRecipes.cpp b/source/CraftingRecipes.cpp index 5fb705296..d26f553e9 100644 --- a/source/CraftingRecipes.cpp +++ b/source/CraftingRecipes.cpp @@ -5,6 +5,8 @@ #include "Globals.h"
#include "CraftingRecipes.h"
+#include "cRoot.h"
+#include "cPluginManager.h"
@@ -80,7 +82,7 @@ cItem & cCraftingGrid::GetItem(int x, int y) const -void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount)
+void cCraftingGrid::SetItem(int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
{
// Accessible through scripting, must verify parameters:
if ((x < 0) || (x >= m_Width) || (y < 0) || (y >= m_Height))
@@ -223,7 +225,7 @@ void cCraftingRecipe::Clear(void) -void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount)
+void cCraftingRecipe::SetResult(ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
{
m_Result = cItem(a_ItemType, a_ItemCount, a_ItemHealth);
}
@@ -275,14 +277,21 @@ cCraftingRecipes::~cCraftingRecipes() -void cCraftingRecipes::GetRecipe(const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe)
+void cCraftingRecipes::GetRecipe(const cPlayer * a_Player, const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe)
{
- // TODO: Allow plugins to intercept recipes, add a pre-craft hook here
+ // Allow plugins to intercept recipes using a pre-craft hook:
+ if (cRoot::Get()->GetPluginManager()->CallHookPreCrafting(a_Player, &a_CraftingGrid, &a_Recipe))
+ {
+ return;
+ }
+
+ // Built-in recipes:
std::auto_ptr<cRecipe> Recipe(FindRecipe(a_CraftingGrid.GetItems(), a_CraftingGrid.GetWidth(), a_CraftingGrid.GetHeight()));
a_Recipe.Clear();
if (Recipe.get() == NULL)
{
- // TODO: Allow plugins to intercept recipes, add a post-craft hook here
+ // Allow plugins to intercept a no-recipe-found situation:
+ cRoot::Get()->GetPluginManager()->CallHookCraftingNoRecipe(a_Player, &a_CraftingGrid, &a_Recipe);
return;
}
for (cRecipeSlots::const_iterator itr = Recipe->m_Ingredients.begin(); itr != Recipe->m_Ingredients.end(); ++itr)
@@ -290,7 +299,9 @@ void cCraftingRecipes::GetRecipe(const cCraftingGrid & a_CraftingGrid, cCrafting a_Recipe.SetIngredient(itr->x, itr->y, itr->m_Item);
} // for itr
a_Recipe.SetResult(Recipe->m_Result);
- // TODO: Allow plugins to intercept recipes, add a post-craft hook here
+
+ // Allow plugins to intercept recipes after they are processed:
+ cRoot::Get()->GetPluginManager()->CallHookPostCrafting(a_Player, &a_CraftingGrid, &a_Recipe);
}
|