summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-12 23:30:32 +0200
committermadmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2012-06-12 23:30:32 +0200
commit223967b80d783df1be2df5f74ddf198f373fbc57 (patch)
tree6bf155fc8cfbdf635b6ef40d4e7ab200029de6d9
parentUpdated the crafting recipes architecture to better support crafting hooks. Removed the old recipe file and implementation altogether. (diff)
downloadcuberite-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 '')
-rw-r--r--source/Bindings.cpp369
-rw-r--r--source/Bindings.h2
-rw-r--r--source/CraftingRecipes.cpp23
-rw-r--r--source/CraftingRecipes.h17
-rw-r--r--source/cCraftingWindow.cpp6
-rw-r--r--source/cPlugin.h11
-rw-r--r--source/cPluginManager.cpp124
-rw-r--r--source/cPluginManager.h79
-rw-r--r--source/cPlugin_NewLua.cpp69
-rw-r--r--source/cPlugin_NewLua.h4
-rw-r--r--source/cSurvivalInventory.cpp6
11 files changed, 637 insertions, 73 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 56f27fd32..5fa802a88 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 06/12/12 21:57:04.
+** Generated automatically by tolua++-1.0.92 on 06/12/12 23:23:39.
*/
#ifndef __cplusplus
@@ -7713,6 +7713,120 @@ static int tolua_AllToLua_cPlugin_OnChunkGenerating00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: OnPreCrafting of class cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnPreCrafting00
+static int tolua_AllToLua_cPlugin_OnPreCrafting00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnPreCrafting'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnPreCrafting'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnCraftingNoRecipe of class cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnCraftingNoRecipe00
+static int tolua_AllToLua_cPlugin_OnCraftingNoRecipe00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnCraftingNoRecipe'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnCraftingNoRecipe'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: OnPostCrafting of class cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnPostCrafting00
+static int tolua_AllToLua_cPlugin_OnPostCrafting00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnPostCrafting'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnPostCrafting'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: GetName of class cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_GetName00
static int tolua_AllToLua_cPlugin_GetName00(lua_State* tolua_S)
@@ -8149,6 +8263,45 @@ public:
return ( bool ) cPlugin:: OnChunkGenerating(a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
};
+ bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnPreCrafting", tolua_AllToLua_cPlugin_OnPreCrafting00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin:: OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ };
+ bool OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnCraftingNoRecipe", tolua_AllToLua_cPlugin_OnCraftingNoRecipe00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin:: OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ };
+ };
+ bool OnPostCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnPostCrafting", tolua_AllToLua_cPlugin_OnPostCrafting00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin:: OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ };
void cPlugin__OnDisable( void ) {
return ( void )cPlugin::OnDisable();
@@ -8195,6 +8348,15 @@ public:
bool cPlugin__OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin::OnChunkGenerating(a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
+ bool cPlugin__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin::OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ bool cPlugin__OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin::OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ };
+ bool cPlugin__OnPostCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin::OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ };
Lua__cPlugin( void ): cPlugin(){};
};
@@ -8757,6 +8919,120 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00(lua_State* t
}
#endif //#ifndef TOLUA_DISABLE
+/* method: cPlugin__OnPreCrafting of class Lua__cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnPreCrafting00
+static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnPreCrafting00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnPreCrafting'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin__OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin__OnPreCrafting'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin__OnCraftingNoRecipe of class Lua__cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnCraftingNoRecipe00
+static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnCraftingNoRecipe00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnCraftingNoRecipe'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin__OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin__OnCraftingNoRecipe'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: cPlugin__OnPostCrafting of class Lua__cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnPostCrafting00
+static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnPostCrafting00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"const cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"const cCraftingGrid",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,4,"cCraftingRecipe",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,2,0));
+ const cCraftingGrid* a_Grid = ((const cCraftingGrid*) tolua_tousertype(tolua_S,3,0));
+ cCraftingRecipe* a_Recipe = ((cCraftingRecipe*) tolua_tousertype(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnPostCrafting'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin__OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin__OnPostCrafting'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: new of class Lua__cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_new00
static int tolua_AllToLua_Lua__cPlugin_new00(lua_State* tolua_S)
@@ -9154,6 +9430,45 @@ public:
return ( bool ) cPlugin_NewLua:: OnChunkGenerating(a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
};
+ bool OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnPreCrafting", tolua_AllToLua_cPlugin_OnPreCrafting00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ };
+ bool OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnCraftingNoRecipe", tolua_AllToLua_cPlugin_OnCraftingNoRecipe00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ };
+ };
+ bool OnPostCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ if (push_method("OnPostCrafting", tolua_AllToLua_cPlugin_OnPostCrafting00)) {
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Grid, "const cCraftingGrid");
+ tolua_pushusertype(lua_state, (void*)a_Recipe, "cCraftingRecipe");
+ ToluaBase::dbcall(lua_state, 4, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ };
void cPlugin_NewLua__OnDisable( void ) {
return ( void )cPlugin_NewLua::OnDisable();
@@ -9203,6 +9518,15 @@ public:
bool cPlugin_NewLua__OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin_NewLua::OnChunkGenerating(a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
+ bool cPlugin_NewLua__OnPreCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin_NewLua::OnPreCrafting(a_Player,a_Grid,a_Recipe);
+ };
+ bool cPlugin_NewLua__OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin_NewLua::OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
+ };
+ bool cPlugin_NewLua__OnPostCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
+ return ( bool )cPlugin_NewLua::OnPostCrafting(a_Player,a_Grid,a_Recipe);
+ };
};
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
@@ -17920,13 +18244,13 @@ static int tolua_AllToLua_cCraftingGrid_SetItem00(lua_State* tolua_S)
int x = ((int) tolua_tonumber(tolua_S,2,0));
int y = ((int) tolua_tonumber(tolua_S,3,0));
ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,4,0));
- short a_ItemHealth = ((short) tolua_tonumber(tolua_S,5,0));
- int a_ItemCount = ((int) tolua_tonumber(tolua_S,6,0));
+ int a_ItemCount = ((int) tolua_tonumber(tolua_S,5,0));
+ short a_ItemHealth = ((short) tolua_tonumber(tolua_S,6,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetItem'", NULL);
#endif
{
- self->SetItem(x,y,a_ItemType,a_ItemHealth,a_ItemCount);
+ self->SetItem(x,y,a_ItemType,a_ItemCount,a_ItemHealth);
}
}
return 0;
@@ -18247,13 +18571,13 @@ static int tolua_AllToLua_cCraftingRecipe_SetResult00(lua_State* tolua_S)
{
cCraftingRecipe* self = (cCraftingRecipe*) tolua_tousertype(tolua_S,1,0);
ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,0));
- short a_ItemHealth = ((short) tolua_tonumber(tolua_S,3,0));
- int a_ItemCount = ((int) tolua_tonumber(tolua_S,4,0));
+ int a_ItemCount = ((int) tolua_tonumber(tolua_S,3,0));
+ short a_ItemHealth = ((short) tolua_tonumber(tolua_S,4,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetResult'", NULL);
#endif
{
- self->SetResult(a_ItemType,a_ItemHealth,a_ItemCount);
+ self->SetResult(a_ItemType,a_ItemCount,a_ItemHealth);
}
}
return 0;
@@ -18316,13 +18640,13 @@ static int tolua_AllToLua_cCraftingRecipe_SetIngredient00(lua_State* tolua_S)
int x = ((int) tolua_tonumber(tolua_S,2,0));
int y = ((int) tolua_tonumber(tolua_S,3,0));
ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,4,0));
- short a_ItemHealth = ((short) tolua_tonumber(tolua_S,5,0));
- int a_ItemCount = ((int) tolua_tonumber(tolua_S,6,0));
+ int a_ItemCount = ((int) tolua_tonumber(tolua_S,5,0));
+ short a_ItemHealth = ((short) tolua_tonumber(tolua_S,6,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetIngredient'", NULL);
#endif
{
- self->SetIngredient(x,y,a_ItemType,a_ItemHealth,a_ItemCount);
+ self->SetIngredient(x,y,a_ItemType,a_ItemCount,a_ItemHealth);
}
}
return 0;
@@ -19295,6 +19619,25 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_endmodule(tolua_S);
tolua_cclass(tolua_S,"cPluginManager","cPluginManager","",NULL);
tolua_beginmodule(tolua_S,"cPluginManager");
+ tolua_constant(tolua_S,"HOOK_TICK",cPluginManager::HOOK_TICK);
+ tolua_constant(tolua_S,"HOOK_CHAT",cPluginManager::HOOK_CHAT);
+ tolua_constant(tolua_S,"HOOK_COLLECT_ITEM",cPluginManager::HOOK_COLLECT_ITEM);
+ tolua_constant(tolua_S,"HOOK_BLOCK_DIG",cPluginManager::HOOK_BLOCK_DIG);
+ tolua_constant(tolua_S,"HOOK_BLOCK_PLACE",cPluginManager::HOOK_BLOCK_PLACE);
+ tolua_constant(tolua_S,"HOOK_DISCONNECT",cPluginManager::HOOK_DISCONNECT);
+ tolua_constant(tolua_S,"HOOK_HANDSHAKE",cPluginManager::HOOK_HANDSHAKE);
+ tolua_constant(tolua_S,"HOOK_LOGIN",cPluginManager::HOOK_LOGIN);
+ tolua_constant(tolua_S,"HOOK_PLAYER_SPAWN",cPluginManager::HOOK_PLAYER_SPAWN);
+ tolua_constant(tolua_S,"HOOK_PLAYER_JOIN",cPluginManager::HOOK_PLAYER_JOIN);
+ tolua_constant(tolua_S,"HOOK_PLAYER_MOVE",cPluginManager::HOOK_PLAYER_MOVE);
+ tolua_constant(tolua_S,"HOOK_TAKE_DAMAGE",cPluginManager::HOOK_TAKE_DAMAGE);
+ tolua_constant(tolua_S,"HOOK_KILLED",cPluginManager::HOOK_KILLED);
+ tolua_constant(tolua_S,"HOOK_CHUNK_GENERATED",cPluginManager::HOOK_CHUNK_GENERATED);
+ tolua_constant(tolua_S,"HOOK_CHUNK_GENERATING",cPluginManager::HOOK_CHUNK_GENERATING);
+ tolua_constant(tolua_S,"HOOK_BLOCK_TO_DROPS",cPluginManager::HOOK_BLOCK_TO_DROPS);
+ tolua_constant(tolua_S,"HOOK_PRE_CRAFTING",cPluginManager::HOOK_PRE_CRAFTING);
+ tolua_constant(tolua_S,"HOOK_CRAFTING_NO_RECIPE",cPluginManager::HOOK_CRAFTING_NO_RECIPE);
+ tolua_constant(tolua_S,"HOOK_POST_CRAFTING",cPluginManager::HOOK_POST_CRAFTING);
tolua_constant(tolua_S,"E_PLUGIN_TICK",cPluginManager::E_PLUGIN_TICK);
tolua_constant(tolua_S,"E_PLUGIN_CHAT",cPluginManager::E_PLUGIN_CHAT);
tolua_constant(tolua_S,"E_PLUGIN_COLLECT_ITEM",cPluginManager::E_PLUGIN_COLLECT_ITEM);
@@ -19344,6 +19687,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"OnKilled",tolua_AllToLua_cPlugin_OnKilled00);
tolua_function(tolua_S,"OnChunkGenerated",tolua_AllToLua_cPlugin_OnChunkGenerated00);
tolua_function(tolua_S,"OnChunkGenerating",tolua_AllToLua_cPlugin_OnChunkGenerating00);
+ tolua_function(tolua_S,"OnPreCrafting",tolua_AllToLua_cPlugin_OnPreCrafting00);
+ tolua_function(tolua_S,"OnCraftingNoRecipe",tolua_AllToLua_cPlugin_OnCraftingNoRecipe00);
+ tolua_function(tolua_S,"OnPostCrafting",tolua_AllToLua_cPlugin_OnPostCrafting00);
tolua_function(tolua_S,"GetName",tolua_AllToLua_cPlugin_GetName00);
tolua_function(tolua_S,"SetName",tolua_AllToLua_cPlugin_SetName00);
tolua_function(tolua_S,"GetVersion",tolua_AllToLua_cPlugin_GetVersion00);
@@ -19378,6 +19724,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"cPlugin__OnKilled",tolua_AllToLua_Lua__cPlugin_cPlugin__OnKilled00);
tolua_function(tolua_S,"cPlugin__OnChunkGenerated",tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerated00);
tolua_function(tolua_S,"cPlugin__OnChunkGenerating",tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00);
+ tolua_function(tolua_S,"cPlugin__OnPreCrafting",tolua_AllToLua_Lua__cPlugin_cPlugin__OnPreCrafting00);
+ tolua_function(tolua_S,"cPlugin__OnCraftingNoRecipe",tolua_AllToLua_Lua__cPlugin_cPlugin__OnCraftingNoRecipe00);
+ tolua_function(tolua_S,"cPlugin__OnPostCrafting",tolua_AllToLua_Lua__cPlugin_cPlugin__OnPostCrafting00);
tolua_function(tolua_S,"new",tolua_AllToLua_Lua__cPlugin_new00);
tolua_function(tolua_S,"new_local",tolua_AllToLua_Lua__cPlugin_new00_local);
tolua_function(tolua_S,".call",tolua_AllToLua_Lua__cPlugin_new00_local);
diff --git a/source/Bindings.h b/source/Bindings.h
index f3691a252..a65d01ff1 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 06/12/12 21:57:04.
+** Generated automatically by tolua++-1.0.92 on 06/12/12 23:23:39.
*/
/* Exported function */
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);
}
diff --git a/source/CraftingRecipes.h b/source/CraftingRecipes.h
index 3d55a3476..8e4422b1c 100644
--- a/source/CraftingRecipes.h
+++ b/source/CraftingRecipes.h
@@ -14,6 +14,13 @@
+// fwd: cPlayer.h
+class cPlayer;
+
+
+
+
+
class cCraftingGrid // tolua_export
{ // tolua_export
public:
@@ -26,7 +33,7 @@ public:
int GetWidth (void) const {return m_Width; }
int GetHeight(void) const {return m_Height; }
cItem & GetItem (int x, int y) const;
- void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount);
+ void SetItem (int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth);
void SetItem (int x, int y, const cItem & a_Item);
void Clear (void);
@@ -65,15 +72,15 @@ public:
int GetIngredientsHeight(void) const {return m_Ingredients.GetHeight(); }
cItem & GetIngredient (int x, int y) const {return m_Ingredients.GetItem(x, y); }
const cItem & GetResult (void) const {return m_Result; }
- void SetResult (ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount);
+ void SetResult (ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth);
void SetResult (const cItem & a_Item)
{
m_Result = a_Item;
}
- void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, short a_ItemHealth, int a_ItemCount)
+ void SetIngredient (int x, int y, ENUM_ITEM_ID a_ItemType, int a_ItemCount, short a_ItemHealth)
{
- m_Ingredients.SetItem(x, y, a_ItemType, a_ItemHealth, a_ItemCount);
+ m_Ingredients.SetItem(x, y, a_ItemType, a_ItemCount, a_ItemHealth);
}
void SetIngredient (int x, int y, const cItem & a_Item)
@@ -108,7 +115,7 @@ public:
~cCraftingRecipes();
/// Returns the recipe for current crafting grid. Doesn't modify the grid. Clears a_Recipe if no recipe found.
- void GetRecipe(const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe);
+ void GetRecipe(const cPlayer * a_Player, const cCraftingGrid & a_CraftingGrid, cCraftingRecipe & a_Recipe);
protected:
diff --git a/source/cCraftingWindow.cpp b/source/cCraftingWindow.cpp
index c84121a06..570f1ed9a 100644
--- a/source/cCraftingWindow.cpp
+++ b/source/cCraftingWindow.cpp
@@ -73,7 +73,7 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
cCraftingGrid Grid(GetSlots() + 1, 3, 3);
cCraftingRecipe Recipe(Grid);
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
if ((a_ClickPacket->m_SlotNum == 0) && !bDontCook)
{
@@ -84,10 +84,10 @@ void cCraftingWindow::Clicked( cPacket_WindowClick* a_ClickPacket, cPlayer & a_P
Grid.CopyToItems(GetSlots() + 1);
// Get the recipe for the new grid contents:
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(&a_Player, Grid, Recipe);
}
*GetSlot(0) = Recipe.GetResult();
- LOGD("You cooked: %i x %i !!", GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
+ LOGD("%s cooked: %i x %i !!", a_Player.GetName().c_str(), GetSlot(0)->m_ItemID, GetSlot(0)->m_ItemCount );
}
SendWholeWindow( a_Player.GetClientHandle() );
a_Player.GetInventory().SendWholeInventory( a_Player.GetClientHandle() );
diff --git a/source/cPlugin.h b/source/cPlugin.h
index 737c0c382..ec7baaab3 100644
--- a/source/cPlugin.h
+++ b/source/cPlugin.h
@@ -1,3 +1,4 @@
+
#pragma once
class cPacket_BlockPlace;
@@ -17,6 +18,13 @@ class cWorld;
class cLuaChunk;
struct TakeDamageInfo;
+// fwd: cPlayer.h
+class cPlayer;
+
+// fwd: CraftingRecipes.h
+class cCraftingGrid;
+class cCraftingRecipe;
+
@@ -51,6 +59,9 @@ public:
virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ) { (void)a_Killed; (void)a_Killer; return false; }
virtual void OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) {}
virtual bool OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) { return false; }
+ virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
+ virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
+ virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) {return false; }
// Accessors
const char* GetName() const { return m_Name.c_str(); }
diff --git a/source/cPluginManager.cpp b/source/cPluginManager.cpp
index ff2fdfb62..0f3269cf7 100644
--- a/source/cPluginManager.cpp
+++ b/source/cPluginManager.cpp
@@ -187,43 +187,51 @@ void cPluginManager::Tick(float a_Dt)
-bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
+bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
{
HookMap::iterator Plugins = m_Hooks.find( a_Hook );
// Special case for chat hook, since you can also bind commands (bound commands don't use chat hook)
- if( a_Hook == E_PLUGIN_CHAT )
+ if (a_Hook == HOOK_CHAT)
{
- if( a_NumArgs != 2 ) return false;
+ if (a_NumArgs != 2)
+ {
+ return false;
+ }
va_list argptr;
va_start( argptr, a_NumArgs);
- const char* Message = va_arg(argptr, const char* );
- cPlayer* Player = va_arg(argptr, cPlayer* );
+ const char * Message = va_arg(argptr, const char* );
+ cPlayer * Player = va_arg(argptr, cPlayer * );
va_end (argptr);
- if( m_LuaCommandBinder->HandleCommand( std::string( Message ), Player ) )
+ if (m_LuaCommandBinder->HandleCommand( std::string( Message ), Player))
+ {
return true;
+ }
- if( Plugins != m_Hooks.end() )
+ if (Plugins == m_Hooks.end())
{
- for( PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr )
+ return false;
+ }
+
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnChat(Message, Player))
{
- if( (*itr)->OnChat( Message, Player ) )
- return true;
+ return true;
}
}
-
return false;
}
- if( Plugins == m_Hooks.end() )
+ if (Plugins == m_Hooks.end())
{
return false;
}
switch( a_Hook )
{
- case E_PLUGIN_COLLECT_ITEM:
+ case HOOK_COLLECT_ITEM:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -239,7 +247,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_BLOCK_DIG:
+ case HOOK_BLOCK_DIG:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -256,7 +264,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_BLOCK_PLACE:
+ case HOOK_BLOCK_PLACE:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -272,7 +280,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_DISCONNECT:
+ case HOOK_DISCONNECT:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -288,7 +296,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_LOGIN:
+ case HOOK_LOGIN:
{
if( a_NumArgs != 1 ) break;
va_list argptr;
@@ -303,7 +311,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_PLAYER_JOIN:
+ case HOOK_PLAYER_JOIN:
{
if( a_NumArgs != 1 ) break;
va_list argptr;
@@ -318,7 +326,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_PLAYER_MOVE:
+ case HOOK_PLAYER_MOVE:
{
if( a_NumArgs != 1 ) break;
va_list argptr;
@@ -332,7 +340,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_TAKE_DAMAGE:
+ case HOOK_TAKE_DAMAGE:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -347,7 +355,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_KILLED:
+ case HOOK_KILLED:
{
if( a_NumArgs != 2 ) break;
va_list argptr;
@@ -363,7 +371,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_CHUNK_GENERATED:
+ case HOOK_CHUNK_GENERATED:
{
if (a_NumArgs != 3)
{
@@ -382,7 +390,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
break;
}
- case E_PLUGIN_CHUNK_GENERATING:
+ case HOOK_CHUNK_GENERATING:
{
if (a_NumArgs != 3)
{
@@ -394,10 +402,12 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
int ChunkZ = va_arg(argptr, int);
cLuaChunk * LuaChunk = va_arg(argptr, cLuaChunk *);
va_end (argptr);
- for( PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr )
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
- if( (*itr)->OnChunkGenerating(ChunkX, ChunkZ, LuaChunk) )
+ if ((*itr)->OnChunkGenerating(ChunkX, ChunkZ, LuaChunk))
+ {
return true;
+ }
}
break;
}
@@ -405,6 +415,7 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
default:
{
LOGWARNING("cPluginManager: Calling Unknown hook: %i", a_Hook );
+ ASSERT(!"Calling an unknown hook");
break;
}
} // switch (a_Hook)
@@ -415,6 +426,69 @@ bool cPluginManager::CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... )
+bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_PRE_CRAFTING);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnPreCrafting(a_Player, a_Grid, a_Recipe))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cPluginManager::CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_CRAFTING_NO_RECIPE);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnCraftingNoRecipe(a_Player, a_Grid, a_Recipe))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
+bool cPluginManager::CallHookPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_POST_CRAFTING);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnPostCrafting(a_Player, a_Grid, a_Recipe))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
cPlugin* cPluginManager::GetPlugin( const char* a_Plugin ) const
{
for( PluginList::const_iterator itr = m_Plugins.begin(); itr != m_Plugins.end(); ++itr )
diff --git a/source/cPluginManager.h b/source/cPluginManager.h
index 8d0a82a39..bf891d085 100644
--- a/source/cPluginManager.h
+++ b/source/cPluginManager.h
@@ -5,6 +5,18 @@ struct lua_State;
class cLuaCommandBinder;
class cPlugin;
class cPlugin_Lua;
+
+// fwd: cPlayer.h
+class cPlayer;
+
+// fwd: CraftingRecipes.h
+class cCraftingGrid;
+class cCraftingRecipe;
+
+
+
+
+
class cPluginManager //tolua_export
{ //tolua_export
public: //tolua_export
@@ -12,29 +24,52 @@ public: //tolua_export
// Called each tick
virtual void Tick(float a_Dt);
- enum PluginHook // tolua_export
- { // tolua_export
- E_PLUGIN_TICK, // tolua_export
- E_PLUGIN_CHAT, // tolua_export
- E_PLUGIN_COLLECT_ITEM, // tolua_export
- E_PLUGIN_BLOCK_DIG, // tolua_export
- E_PLUGIN_BLOCK_PLACE, // tolua_export
- E_PLUGIN_DISCONNECT, // tolua_export
- E_PLUGIN_HANDSHAKE, // tolua_export
- E_PLUGIN_LOGIN, // tolua_export
- E_PLUGIN_PLAYER_SPAWN, // tolua_export
- E_PLUGIN_PLAYER_JOIN, // tolua_export
- E_PLUGIN_PLAYER_MOVE, // tolua_export
- E_PLUGIN_TAKE_DAMAGE, // tolua_export
- E_PLUGIN_KILLED, // tolua_export
- E_PLUGIN_CHUNK_GENERATED, // tolua_export
- E_PLUGIN_CHUNK_GENERATING, // tolua_export
- E_PLUGIN_BLOCK_TO_DROPS, // tolua_export
- }; // tolua_export
+ // tolua_begin
+ enum PluginHook
+ {
+ HOOK_TICK,
+ HOOK_CHAT,
+ HOOK_COLLECT_ITEM,
+ HOOK_BLOCK_DIG,
+ HOOK_BLOCK_PLACE,
+ HOOK_DISCONNECT,
+ HOOK_HANDSHAKE,
+ HOOK_LOGIN,
+ HOOK_PLAYER_SPAWN,
+ HOOK_PLAYER_JOIN,
+ HOOK_PLAYER_MOVE,
+ HOOK_TAKE_DAMAGE,
+ HOOK_KILLED,
+ HOOK_CHUNK_GENERATED,
+ HOOK_CHUNK_GENERATING,
+ HOOK_BLOCK_TO_DROPS,
+ HOOK_PRE_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
+ HOOK_CRAFTING_NO_RECIPE, /// cPlayer, cCraftingGrid, cCraftingRecipe
+ HOOK_POST_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
+
+ // E_PLUGIN_ names are obsolete, but are kept for compatibility reasons
+ E_PLUGIN_TICK = HOOK_TICK,
+ E_PLUGIN_CHAT = HOOK_CHAT,
+ E_PLUGIN_COLLECT_ITEM = HOOK_COLLECT_ITEM,
+ E_PLUGIN_BLOCK_DIG = HOOK_BLOCK_DIG,
+ E_PLUGIN_BLOCK_PLACE = HOOK_BLOCK_PLACE,
+ E_PLUGIN_DISCONNECT = HOOK_DISCONNECT,
+ E_PLUGIN_HANDSHAKE = HOOK_HANDSHAKE,
+ E_PLUGIN_LOGIN = HOOK_LOGIN,
+ E_PLUGIN_PLAYER_SPAWN = HOOK_PLAYER_SPAWN,
+ E_PLUGIN_PLAYER_JOIN = HOOK_PLAYER_JOIN,
+ E_PLUGIN_PLAYER_MOVE = HOOK_PLAYER_MOVE,
+ E_PLUGIN_TAKE_DAMAGE = HOOK_TAKE_DAMAGE,
+ E_PLUGIN_KILLED = HOOK_KILLED,
+ E_PLUGIN_CHUNK_GENERATED = HOOK_CHUNK_GENERATED,
+ E_PLUGIN_CHUNK_GENERATING = HOOK_CHUNK_GENERATING,
+ E_PLUGIN_BLOCK_TO_DROPS = HOOK_BLOCK_TO_DROPS,
+ };
+ // tolua_end
static cPluginManager * GetPluginManager(); //tolua_export
- typedef std::list< cPlugin* > PluginList;
+ typedef std::list< cPlugin * > PluginList;
cPlugin* GetPlugin( const char* a_Plugin ) const; //tolua_export
const PluginList & GetAllPlugins() const; // >> EXPORTED IN MANUALBINDINGS <<
@@ -47,6 +82,10 @@ public: //tolua_export
unsigned int GetNumPlugins() const; //tolua_export
bool CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... );
+
+ bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
+ bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
+ bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
void RemoveHooks( cPlugin* a_Plugin );
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export
diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp
index fc07b266e..8efca5338 100644
--- a/source/cPlugin_NewLua.cpp
+++ b/source/cPlugin_NewLua.cpp
@@ -384,6 +384,75 @@ bool cPlugin_NewLua::OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk *
+bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ cCSLock Lock(m_CriticalSection);
+ if (!PushFunction("OnPreCrafting"))
+ return false;
+
+ tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
+ tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
+ tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
+
+ if (!CallFunction(3, 1, "OnPreCrafting"))
+ {
+ return false;
+ }
+
+ bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
+ return bRetVal;
+}
+
+
+
+
+
+bool cPlugin_NewLua::OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ cCSLock Lock(m_CriticalSection);
+ if (!PushFunction("OnCraftingNoRecipe"))
+ return false;
+
+ tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
+ tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
+ tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
+
+ if (!CallFunction(3, 1, "OnCraftingNoRecipe"))
+ {
+ return false;
+ }
+
+ bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
+ return bRetVal;
+}
+
+
+
+
+
+bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
+{
+ cCSLock Lock(m_CriticalSection);
+ if (!PushFunction("OnPostCrafting"))
+ return false;
+
+ tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
+ tolua_pushusertype(m_LuaState, (void *)a_Grid, "cCraftingGrid");
+ tolua_pushusertype(m_LuaState, (void *)a_Recipe, "cCraftingRecipe");
+
+ if (!CallFunction(3, 1, "OnPostCrafting"))
+ {
+ return false;
+ }
+
+ bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
+ return bRetVal;
+}
+
+
+
+
+
cWebPlugin_Lua* cPlugin_NewLua::CreateWebPlugin(lua_State* a_LuaState)
{
cCSLock Lock( m_CriticalSection );
diff --git a/source/cPlugin_NewLua.h b/source/cPlugin_NewLua.h
index 096d5667f..6ecdada11 100644
--- a/source/cPlugin_NewLua.h
+++ b/source/cPlugin_NewLua.h
@@ -40,6 +40,10 @@ public: //tolua_export
virtual void OnChunkGenerated(cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating( int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
+ virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
+ virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
+ virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
+
lua_State* GetLuaState() { return m_LuaState; }
cWebPlugin_Lua* CreateWebPlugin(lua_State* a_LuaState); //tolua_export
diff --git a/source/cSurvivalInventory.cpp b/source/cSurvivalInventory.cpp
index cd7b96ad8..4a573572d 100644
--- a/source/cSurvivalInventory.cpp
+++ b/source/cSurvivalInventory.cpp
@@ -74,7 +74,7 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket )
cCraftingGrid Grid(m_Slots + c_CraftOffset + 1, 2, 2);
cCraftingRecipe Recipe(Grid);
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe);
if ((Packet->m_SlotNum == 0) && !bDontCook)
{
@@ -85,10 +85,10 @@ void cSurvivalInventory::Clicked( cPacket* a_ClickPacket )
Grid.CopyToItems(m_Slots + c_CraftOffset + 1);
// Get the recipe for the new grid contents:
- cRoot::Get()->GetCraftingRecipes()->GetRecipe(Grid, Recipe);
+ cRoot::Get()->GetCraftingRecipes()->GetRecipe(m_Owner, Grid, Recipe);
}
m_Slots[c_CraftOffset] = Recipe.GetResult();
- LOGD("You cooked: %i x %i !!", m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount );
+ LOGD("%s cooked: %i x %i !!", m_Owner->GetName().c_str(), m_Slots[c_CraftOffset].m_ItemID, m_Slots[c_CraftOffset].m_ItemCount );
SendWholeInventory( m_Owner->GetClientHandle() );
}
SendSlot( 0 );