diff options
-rw-r--r-- | VC2008/MCServer.vcproj | 4 | ||||
-rw-r--r-- | source/AllToLua.pkg | 1 | ||||
-rw-r--r-- | source/Bindings.cpp | 465 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/LuaItems.h | 52 | ||||
-rw-r--r-- | source/cBlockToPickup.cpp | 50 | ||||
-rw-r--r-- | source/cBlockToPickup.h | 2 | ||||
-rw-r--r-- | source/cClientHandle.cpp | 6 | ||||
-rw-r--r-- | source/cPlugin.cpp | 2 | ||||
-rw-r--r-- | source/cPlugin.h | 31 | ||||
-rw-r--r-- | source/cPluginManager.cpp | 24 | ||||
-rw-r--r-- | source/cPluginManager.h | 4 | ||||
-rw-r--r-- | source/cPlugin_NewLua.cpp | 56 | ||||
-rw-r--r-- | source/cPlugin_NewLua.h | 29 |
14 files changed, 640 insertions, 88 deletions
diff --git a/VC2008/MCServer.vcproj b/VC2008/MCServer.vcproj index c4387bf7f..8b19068f9 100644 --- a/VC2008/MCServer.vcproj +++ b/VC2008/MCServer.vcproj @@ -1701,6 +1701,10 @@ >
</File>
<File
+ RelativePath="..\source\LuaItems.h"
+ >
+ </File>
+ <File
RelativePath="..\source\ManualBindings.cpp"
>
</File>
diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg index c6e0f0565..09c6b7a2d 100644 --- a/source/AllToLua.pkg +++ b/source/AllToLua.pkg @@ -47,3 +47,4 @@ $cfile "packets/cPacket_BlockDig.h" $cfile "packets/cPacket_BlockPlace.h"
$cfile "cLuaChunk.h"
$cfile "CraftingRecipes.h"
+$cfile "LuaItems.h"
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index ac7e66a57..e437f5d79 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/13/12 17:39:42.
+** Generated automatically by tolua++-1.0.92 on 06/13/12 19:36:04.
*/
#ifndef __cplusplus
@@ -57,6 +57,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S); #include "packets/cPacket_BlockPlace.h"
#include "cLuaChunk.h"
#include "CraftingRecipes.h"
+#include "LuaItems.h"
/* function to release collected object via destructor */
#ifdef __cplusplus
@@ -171,34 +172,38 @@ static int tolua_collect_Vector3d (lua_State* tolua_S) /* function to register type */
static void tolua_reg_types (lua_State* tolua_S)
{
+ tolua_usertype(tolua_S,"BLOCKTYPE");
tolua_usertype(tolua_S,"TakeDamageInfo");
+ tolua_usertype(tolua_S,"cLuaItems");
+ tolua_usertype(tolua_S,"cLuaChunk");
+ tolua_usertype(tolua_S,"cCraftingGrid");
tolua_usertype(tolua_S,"cCraftingRecipe");
tolua_usertype(tolua_S,"cPlugin");
- tolua_usertype(tolua_S,"cCraftingGrid");
- tolua_usertype(tolua_S,"cStringMap");
- tolua_usertype(tolua_S,"cLuaChunk");
- tolua_usertype(tolua_S,"Lua__cEntity");
+ tolua_usertype(tolua_S,"cEntity");
+ tolua_usertype(tolua_S,"NIBBLETYPE");
tolua_usertype(tolua_S,"Lua__cPacket_BlockDig");
+ tolua_usertype(tolua_S,"cTCPLink");
+ tolua_usertype(tolua_S,"Lua__cTCPLink");
tolua_usertype(tolua_S,"Json::Value");
- tolua_usertype(tolua_S,"cInventory");
+ tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"cRoot");
- tolua_usertype(tolua_S,"Lua__cTCPLink");
- tolua_usertype(tolua_S,"cPlugin_NewLua");
+ tolua_usertype(tolua_S,"cMCLogger");
+ tolua_usertype(tolua_S,"cGroup");
tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"cPlugin::CommandStruct");
tolua_usertype(tolua_S,"cPickup");
- tolua_usertype(tolua_S,"cGroup");
+ tolua_usertype(tolua_S,"cItems");
tolua_usertype(tolua_S,"cPacket_Login");
tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"cStep");
tolua_usertype(tolua_S,"cFurnaceRecipe");
- tolua_usertype(tolua_S,"cMCLogger");
- tolua_usertype(tolua_S,"cChatColor");
tolua_usertype(tolua_S,"cCuboid");
+ tolua_usertype(tolua_S,"cChatColor");
+ tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cPacket_PickupSpawn");
tolua_usertype(tolua_S,"Lua__cWebPlugin");
tolua_usertype(tolua_S,"Lua__cPawn");
- tolua_usertype(tolua_S,"Vector3i");
+ tolua_usertype(tolua_S,"cStairs");
tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"Vector3f");
tolua_usertype(tolua_S,"cPlugin_Lua");
@@ -207,27 +212,27 @@ static void tolua_reg_types (lua_State* tolua_S) tolua_usertype(tolua_S,"cPacket");
tolua_usertype(tolua_S,"cPacket_BlockDig");
tolua_usertype(tolua_S,"cWebAdmin");
- tolua_usertype(tolua_S,"cTCPLink");
- tolua_usertype(tolua_S,"cBlockEntity");
tolua_usertype(tolua_S,"cCraftingRecipes");
+ tolua_usertype(tolua_S,"cBlockEntity");
tolua_usertype(tolua_S,"cGroupManager");
- tolua_usertype(tolua_S,"Lua__cPlugin");
tolua_usertype(tolua_S,"Lua__cPickup");
+ tolua_usertype(tolua_S,"Lua__cPlugin");
+ tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"cPacket_BlockPlace");
tolua_usertype(tolua_S,"cLadder");
tolua_usertype(tolua_S,"cPluginManager");
- tolua_usertype(tolua_S,"cWebPlugin");
+ tolua_usertype(tolua_S,"HTTPFormData");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"Lua__cPlayer");
tolua_usertype(tolua_S,"HTTPRequest");
tolua_usertype(tolua_S,"cPawn");
tolua_usertype(tolua_S,"cPlayer");
tolua_usertype(tolua_S,"cTorch");
- tolua_usertype(tolua_S,"cEntity");
- tolua_usertype(tolua_S,"HTTPFormData");
- tolua_usertype(tolua_S,"cServer");
+ tolua_usertype(tolua_S,"cStringMap");
+ tolua_usertype(tolua_S,"cInventory");
tolua_usertype(tolua_S,"cWorld");
- tolua_usertype(tolua_S,"cStairs");
+ tolua_usertype(tolua_S,"cPlugin_NewLua");
+ tolua_usertype(tolua_S,"Lua__cEntity");
tolua_usertype(tolua_S,"Vector3d");
}
@@ -7304,7 +7309,7 @@ static int tolua_AllToLua_cPlugin_OnDisconnect00(lua_State* tolua_S) #endif
{
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
- std::string a_Reason = ((std::string) tolua_tocppstring(tolua_S,2,0));
+ const AString a_Reason = ((const AString) tolua_tocppstring(tolua_S,2,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnDisconnect'", NULL);
@@ -7312,9 +7317,10 @@ static int tolua_AllToLua_cPlugin_OnDisconnect00(lua_State* tolua_S) {
bool tolua_ret = (bool) self->OnDisconnect(a_Reason,a_Player);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_Reason);
}
}
- return 1;
+ return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'OnDisconnect'.",&tolua_err);
@@ -7827,6 +7833,48 @@ static int tolua_AllToLua_cPlugin_OnPostCrafting00(lua_State* tolua_S) }
#endif //#ifndef TOLUA_DISABLE
+/* method: OnBlockToPickup of class cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnBlockToPickup00
+static int tolua_AllToLua_cPlugin_OnBlockToPickup00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"BLOCKTYPE",0,&tolua_err)) ||
+ (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"NIBBLETYPE",0,&tolua_err)) ||
+ !tolua_isusertype(tolua_S,4,"const cPlayer",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,5,&tolua_err) || !tolua_isusertype(tolua_S,5,"const cItem",0,&tolua_err)) ||
+ (tolua_isvaluenil(tolua_S,6,&tolua_err) || !tolua_isusertype(tolua_S,6,"cItems",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,7,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
+ BLOCKTYPE a_BlockType = *((BLOCKTYPE*) tolua_tousertype(tolua_S,2,0));
+ NIBBLETYPE a_BlockMeta = *((NIBBLETYPE*) tolua_tousertype(tolua_S,3,0));
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,4,0));
+ const cItem* a_EquippedItem = ((const cItem*) tolua_tousertype(tolua_S,5,0));
+ cItems* a_Pickups = ((cItems*) tolua_tousertype(tolua_S,6,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnBlockToPickup'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,*a_EquippedItem,*a_Pickups);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'OnBlockToPickup'.",&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)
@@ -8132,7 +8180,7 @@ public: return ( bool ) cPlugin:: OnCollectItem(a_Pickup,a_Player);
};
};
- bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ bool OnDisconnect( const AString& a_Reason, cPlayer* a_Player) {
if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
tolua_pushcppstring(lua_state, (const char*)a_Reason);
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -8302,6 +8350,23 @@ public: return ( bool ) cPlugin:: OnPostCrafting(a_Player,a_Grid,a_Recipe);
};
};
+ bool OnBlockToPickup( BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
+ if (push_method("OnBlockToPickup", tolua_AllToLua_cPlugin_OnBlockToPickup00)) {
+ void* tolua_obj0 = (void*)new BLOCKTYPE(a_BlockType);
+ tolua_pushusertype_and_takeownership(lua_state, tolua_obj0, "BLOCKTYPE");
+ void* tolua_obj1 = (void*)new NIBBLETYPE(a_BlockMeta);
+ tolua_pushusertype_and_takeownership(lua_state, tolua_obj1, "NIBBLETYPE");
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)&a_EquippedItem, "const cItem");
+ tolua_pushusertype(lua_state, (void*)&a_Pickups, "cItems");
+ ToluaBase::dbcall(lua_state, 6, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
+ };
+ };
void cPlugin__OnDisable( void ) {
return ( void )cPlugin::OnDisable();
@@ -8312,7 +8377,7 @@ public: bool cPlugin__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
return ( bool )cPlugin::OnCollectItem(a_Pickup,a_Player);
};
- bool cPlugin__OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ bool cPlugin__OnDisconnect( const AString& a_Reason, cPlayer* a_Player) {
return ( bool )cPlugin::OnDisconnect(a_Reason,a_Player);
};
bool cPlugin__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
@@ -8357,6 +8422,9 @@ public: bool cPlugin__OnPostCrafting( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
return ( bool )cPlugin::OnPostCrafting(a_Player,a_Grid,a_Recipe);
};
+ bool cPlugin__OnBlockToPickup( BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
+ return ( bool )cPlugin::OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
+ };
Lua__cPlugin( void ): cPlugin(){};
};
@@ -8510,7 +8578,7 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnDisconnect00(lua_State* tolua_ #endif
{
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
- std::string a_Reason = ((std::string) tolua_tocppstring(tolua_S,2,0));
+ const AString a_Reason = ((const AString) tolua_tocppstring(tolua_S,2,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnDisconnect'", NULL);
@@ -8518,9 +8586,10 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnDisconnect00(lua_State* tolua_ {
bool tolua_ret = (bool) self->cPlugin__OnDisconnect(a_Reason,a_Player);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_Reason);
}
}
- return 1;
+ return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'cPlugin__OnDisconnect'.",&tolua_err);
@@ -9033,6 +9102,48 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnPostCrafting00(lua_State* tolu }
#endif //#ifndef TOLUA_DISABLE
+/* method: cPlugin__OnBlockToPickup of class Lua__cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnBlockToPickup00
+static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnBlockToPickup00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"BLOCKTYPE",0,&tolua_err)) ||
+ (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"NIBBLETYPE",0,&tolua_err)) ||
+ !tolua_isusertype(tolua_S,4,"const cPlayer",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,5,&tolua_err) || !tolua_isusertype(tolua_S,5,"const cItem",0,&tolua_err)) ||
+ (tolua_isvaluenil(tolua_S,6,&tolua_err) || !tolua_isusertype(tolua_S,6,"cItems",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,7,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
+ BLOCKTYPE a_BlockType = *((BLOCKTYPE*) tolua_tousertype(tolua_S,2,0));
+ NIBBLETYPE a_BlockMeta = *((NIBBLETYPE*) tolua_tousertype(tolua_S,3,0));
+ const cPlayer* a_Player = ((const cPlayer*) tolua_tousertype(tolua_S,4,0));
+ const cItem* a_EquippedItem = ((const cItem*) tolua_tousertype(tolua_S,5,0));
+ cItems* a_Pickups = ((cItems*) tolua_tousertype(tolua_S,6,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnBlockToPickup'", NULL);
+#endif
+ {
+ bool tolua_ret = (bool) self->cPlugin__OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,*a_EquippedItem,*a_Pickups);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'cPlugin__OnBlockToPickup'.",&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)
@@ -9299,7 +9410,7 @@ public: return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
};
};
- bool OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ bool OnDisconnect( const AString& a_Reason, cPlayer* a_Player) {
if (push_method("OnDisconnect", tolua_AllToLua_cPlugin_OnDisconnect00)) {
tolua_pushcppstring(lua_state, (const char*)a_Reason);
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
@@ -9469,6 +9580,23 @@ public: return ( bool ) cPlugin_NewLua:: OnPostCrafting(a_Player,a_Grid,a_Recipe);
};
};
+ bool OnBlockToPickup( BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
+ if (push_method("OnBlockToPickup", tolua_AllToLua_cPlugin_OnBlockToPickup00)) {
+ void* tolua_obj0 = (void*)new BLOCKTYPE(a_BlockType);
+ tolua_pushusertype_and_takeownership(lua_state, tolua_obj0, "BLOCKTYPE");
+ void* tolua_obj1 = (void*)new NIBBLETYPE(a_BlockMeta);
+ tolua_pushusertype_and_takeownership(lua_state, tolua_obj1, "NIBBLETYPE");
+ tolua_pushusertype(lua_state, (void*)a_Player, "const cPlayer");
+ tolua_pushusertype(lua_state, (void*)&a_EquippedItem, "const cItem");
+ tolua_pushusertype(lua_state, (void*)&a_Pickups, "cItems");
+ ToluaBase::dbcall(lua_state, 6, 1);
+ bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
+ lua_pop(lua_state, 1);
+ return tolua_ret;
+ } else {
+ return ( bool ) cPlugin_NewLua:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
+ };
+ };
void cPlugin_NewLua__OnDisable( void ) {
return ( void )cPlugin_NewLua::OnDisable();
@@ -9482,7 +9610,7 @@ public: bool cPlugin_NewLua__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnCollectItem(a_Pickup,a_Player);
};
- bool cPlugin_NewLua__OnDisconnect( std::string a_Reason, cPlayer* a_Player) {
+ bool cPlugin_NewLua__OnDisconnect( const AString& a_Reason, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnDisconnect(a_Reason,a_Player);
};
bool cPlugin_NewLua__OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player) {
@@ -9527,6 +9655,9 @@ public: 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);
};
+ bool cPlugin_NewLua__OnBlockToPickup( BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
+ return ( bool )cPlugin_NewLua::OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
+ };
};
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
@@ -19271,6 +19402,270 @@ static int tolua_AllToLua_cCraftingRecipe_Dump00(lua_State* tolua_S) }
#endif //#ifndef TOLUA_DISABLE
+/* method: Get of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Get00
+static int tolua_AllToLua_cLuaItems_Get00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ int a_Idx = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Get'", NULL);
+#endif
+ {
+ cItem& tolua_ret = (cItem&) self->Get(a_Idx);
+ tolua_pushusertype(tolua_S,(void*)&tolua_ret,"cItem");
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Get'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Set of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Set00
+static int tolua_AllToLua_cLuaItems_Set00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,3,&tolua_err) || !tolua_isusertype(tolua_S,3,"const cItem",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ int a_Idx = ((int) tolua_tonumber(tolua_S,2,0));
+ const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,3,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Set'", NULL);
+#endif
+ {
+ self->Set(a_Idx,*a_Item);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Set'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Add of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Add00
+static int tolua_AllToLua_cLuaItems_Add00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cItem",0,&tolua_err)) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ const cItem* a_Item = ((const cItem*) tolua_tousertype(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Add'", NULL);
+#endif
+ {
+ self->Add(*a_Item);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Add'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Delete of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Delete00
+static int tolua_AllToLua_cLuaItems_Delete00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ int a_Idx = ((int) tolua_tonumber(tolua_S,2,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Delete'", NULL);
+#endif
+ {
+ self->Delete(a_Idx);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Delete'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Clear of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Clear00
+static int tolua_AllToLua_cLuaItems_Clear00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Clear'", NULL);
+#endif
+ {
+ self->Clear();
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Clear'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Size of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Size00
+static int tolua_AllToLua_cLuaItems_Size00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,2,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Size'", NULL);
+#endif
+ {
+ int tolua_ret = (int) self->Size();
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ }
+ }
+ return 1;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Size'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Add of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Add01
+static int tolua_AllToLua_cLuaItems_Add01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,2,0));
+ char a_ItemCount = ((char) 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 'Add'", NULL);
+#endif
+ {
+ self->Add(a_ItemType,a_ItemCount,a_ItemHealth);
+ }
+ }
+ return 0;
+tolua_lerror:
+ return tolua_AllToLua_cLuaItems_Add00(tolua_S);
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Set of class cLuaItems */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cLuaItems_Set01
+static int tolua_AllToLua_cLuaItems_Set01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cLuaItems",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,5,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,6,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+ {
+ cLuaItems* self = (cLuaItems*) tolua_tousertype(tolua_S,1,0);
+ int a_Idx = ((int) tolua_tonumber(tolua_S,2,0));
+ ENUM_ITEM_ID a_ItemType = ((ENUM_ITEM_ID) (int) tolua_tonumber(tolua_S,3,0));
+ char a_ItemCount = ((char) tolua_tonumber(tolua_S,4,0));
+ short a_ItemHealth = ((short) tolua_tonumber(tolua_S,5,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Set'", NULL);
+#endif
+ {
+ self->Set(a_Idx,a_ItemType,a_ItemCount,a_ItemHealth);
+ }
+ }
+ return 0;
+tolua_lerror:
+ return tolua_AllToLua_cLuaItems_Set00(tolua_S);
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* Open function */
TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
{
@@ -20155,6 +20550,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) 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,"HOOK_BLOCK_TO_PICKUP",cPluginManager::HOOK_BLOCK_TO_PICKUP);
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);
@@ -20207,6 +20603,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) 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,"OnBlockToPickup",tolua_AllToLua_cPlugin_OnBlockToPickup00);
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);
@@ -20244,6 +20641,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) 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,"cPlugin__OnBlockToPickup",tolua_AllToLua_Lua__cPlugin_cPlugin__OnBlockToPickup00);
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);
@@ -20731,6 +21129,17 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"ConsumeIngredients",tolua_AllToLua_cCraftingRecipe_ConsumeIngredients00);
tolua_function(tolua_S,"Dump",tolua_AllToLua_cCraftingRecipe_Dump00);
tolua_endmodule(tolua_S);
+ tolua_cclass(tolua_S,"cLuaItems","cLuaItems","",NULL);
+ tolua_beginmodule(tolua_S,"cLuaItems");
+ tolua_function(tolua_S,"Get",tolua_AllToLua_cLuaItems_Get00);
+ tolua_function(tolua_S,"Set",tolua_AllToLua_cLuaItems_Set00);
+ tolua_function(tolua_S,"Add",tolua_AllToLua_cLuaItems_Add00);
+ tolua_function(tolua_S,"Delete",tolua_AllToLua_cLuaItems_Delete00);
+ tolua_function(tolua_S,"Clear",tolua_AllToLua_cLuaItems_Clear00);
+ tolua_function(tolua_S,"Size",tolua_AllToLua_cLuaItems_Size00);
+ tolua_function(tolua_S,"Add",tolua_AllToLua_cLuaItems_Add01);
+ tolua_function(tolua_S,"Set",tolua_AllToLua_cLuaItems_Set01);
+ tolua_endmodule(tolua_S);
tolua_endmodule(tolua_S);
return 1;
}
diff --git a/source/Bindings.h b/source/Bindings.h index 808fc8e69..21c409f72 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/13/12 17:39:42.
+** Generated automatically by tolua++-1.0.92 on 06/13/12 19:36:04.
*/
/* Exported function */
diff --git a/source/LuaItems.h b/source/LuaItems.h new file mode 100644 index 000000000..28ceb0d24 --- /dev/null +++ b/source/LuaItems.h @@ -0,0 +1,52 @@ +
+// LuaItems.h
+
+// Interfaces to the cLuaItems class representing a wrapper class that allows Lua to access and manipulate cItems
+
+
+
+
+
+#pragma once
+
+#include "cItem.h"
+
+
+
+
+
+// tolua_begin
+class cLuaItems
+{
+public:
+ // tolua_end
+ // The constructor is not to be Lua-exported, Lua cannot make use of this object
+ cLuaItems(cItems & a_Items) :
+ m_Items(a_Items)
+ {
+ }
+
+ // tolua_begin
+ cItem & Get (int a_Idx) {return m_Items[a_Idx]; }
+ void Set (int a_Idx, const cItem & a_Item) {m_Items[a_Idx] = a_Item; }
+ void Add (const cItem & a_Item) {m_Items.push_back(a_Item); }
+ void Delete(int a_Idx) {m_Items.erase(m_Items.begin() + a_Idx); }
+ void Clear (void) {m_Items.clear(); }
+ int Size (void) {return m_Items.size(); }
+
+ void Add (ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
+ {
+ m_Items.push_back(cItem(a_ItemType, a_ItemCount, a_ItemHealth));
+ }
+
+ void Set (int a_Idx, ENUM_ITEM_ID a_ItemType, char a_ItemCount, short a_ItemHealth)
+ {
+ m_Items[a_Idx] = cItem(a_ItemType, a_ItemCount, a_ItemHealth);
+ }
+protected:
+ cItems & m_Items;
+} ;
+// tolua_end
+
+
+
diff --git a/source/cBlockToPickup.cpp b/source/cBlockToPickup.cpp index d758ea255..ceda2b115 100644 --- a/source/cBlockToPickup.cpp +++ b/source/cBlockToPickup.cpp @@ -23,7 +23,7 @@ static void AddRandomDrop(cItems & a_Drops, MTRand & r1, int a_OneInNChance, ENU -void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENUM_ITEM_ID a_UsedItemID, cItems & a_Drops)
+void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cItem & a_UsedItem, cItems & a_Drops)
{
MTRand r1;
@@ -101,7 +101,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Coal ore requires a pickaxe:
case E_BLOCK_COAL_ORE:
{
- if (ItemCategory::IsPickaxe(a_UsedItemID))
+ if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
{
a_Drops.push_back(cItem(E_ITEM_COAL, 1));
}
@@ -112,9 +112,9 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_IRON_ORE:
{
if (
- (a_UsedItemID == E_ITEM_STONE_PICKAXE) ||
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem(E_ITEM_IRON_ORE, 1));
@@ -127,8 +127,8 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_DIAMOND_ORE:
{
if (
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
@@ -139,7 +139,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Obsidian require a diamond pickaxe:
case E_BLOCK_OBSIDIAN:
{
- if (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ if (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
{
a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
}
@@ -151,8 +151,8 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_REDSTONE_ORE:
{
if (
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem(E_ITEM_REDSTONE_DUST, 4 + (short)r1.randInt(1)));
@@ -164,10 +164,10 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_LAPIS_ORE:
{
if (
- (a_UsedItemID == E_ITEM_STONE_PICKAXE) ||
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_GOLD_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_GOLD_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem(E_ITEM_DYE, 4 + (short)r1.randInt(4), E_META_DYE_BLUE));
@@ -184,9 +184,9 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_LAPIS_BLOCK:
{
if (
- (a_UsedItemID == E_ITEM_STONE_PICKAXE) ||
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_STONE_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
@@ -198,8 +198,8 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_DIAMOND_BLOCK:
{
if (
- (a_UsedItemID == E_ITEM_IRON_PICKAXE) ||
- (a_UsedItemID == E_ITEM_DIAMOND_PICKAXE)
+ (a_UsedItem.m_ItemID == E_ITEM_IRON_PICKAXE) ||
+ (a_UsedItem.m_ItemID == E_ITEM_DIAMOND_PICKAXE)
)
{
a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
@@ -220,7 +220,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU case E_BLOCK_SANDSTONE:
case E_BLOCK_STONE_PRESSURE_PLATE:
{
- if (ItemCategory::IsPickaxe(a_UsedItemID))
+ if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
{
a_Drops.push_back(cItem((ENUM_ITEM_ID)a_BlockType, 1));
}
@@ -231,7 +231,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Stone requires a pickaxe to drop cobblestone:
case E_BLOCK_STONE:
{
- if (ItemCategory::IsPickaxe(a_UsedItemID))
+ if (ItemCategory::IsPickaxe(a_UsedItem.m_ItemID))
{
a_Drops.push_back(cItem(E_ITEM_COBBLESTONE, 1));
}
@@ -242,7 +242,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Snow requires a shovel to harvest:
case E_BLOCK_SNOW:
{
- if (ItemCategory::IsShovel(a_UsedItemID))
+ if (ItemCategory::IsShovel(a_UsedItem.m_ItemID))
{
a_Drops.push_back(cItem(E_ITEM_SNOWBALL, 1));
}
@@ -253,7 +253,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Leaves require shears for harvesting and have a chance of dropping a sapling and a red apple:
case E_BLOCK_LEAVES:
{
- if (a_UsedItemID == E_ITEM_SHEARS)
+ if (a_UsedItem.m_ItemID == E_ITEM_SHEARS)
{
a_Drops.push_back(cItem(E_ITEM_LEAVES, 1));
}
@@ -282,7 +282,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Vines drop only with shears, otherwise they are destroyed
case E_BLOCK_VINES:
{
- if (a_UsedItemID == E_ITEM_SHEARS)
+ if (a_UsedItem.m_ItemID == E_ITEM_SHEARS)
{
a_Drops.push_back(cItem(E_ITEM_VINES, 1));
}
@@ -293,7 +293,7 @@ void cBlockToPickup::ToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENU // Snow drops only when using a shovel
case E_BLOCK_SNOW_BLOCK:
{
- if (ItemCategory::IsShovel(a_UsedItemID))
+ if (ItemCategory::IsShovel(a_UsedItem.m_ItemID))
{
a_Drops.push_back(cItem(E_ITEM_SNOWBALL, 4, 0)); return;
}
diff --git a/source/cBlockToPickup.h b/source/cBlockToPickup.h index 315d75b33..195f96bf6 100644 --- a/source/cBlockToPickup.h +++ b/source/cBlockToPickup.h @@ -16,7 +16,7 @@ class cBlockToPickup // tolua_export { // tolua_export
public:
/// For a given block and tool, returns the list of drops generated
- static void ToPickup(BLOCKTYPE a_BlockID, NIBBLETYPE a_BlockMeta, ENUM_ITEM_ID a_UsedItemID, cItems & a_Drops); // tolua_export
+ static void ToPickup(BLOCKTYPE a_BlockID, NIBBLETYPE a_BlockMeta, const cItem & a_UsedItem, cItems & a_Drops); // tolua_export
/// Returns true if the tool used for the block is the right one for the job. cClientHandle uses this to determine whether to decrease tool durability twice as much
static bool IsRightTool(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, ENUM_ITEM_ID a_UsedTool); // tolua_export
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp index a48dd31ec..a005e8b25 100644 --- a/source/cClientHandle.cpp +++ b/source/cClientHandle.cpp @@ -817,8 +817,10 @@ void cClientHandle::HandleBlockDig(cPacket_BlockDig * a_Packet) cItems PickupItems;
if (bBroken && !(m_Player->GetGameMode() == 1)) // broken
{
- // TODO: Allow plugins to change the dropped objects
- cBlockToPickup::ToPickup(OldBlock, OldMeta, m_Player->GetInventory().GetEquippedItem().m_ItemID, PickupItems);
+ cBlockToPickup::ToPickup(OldBlock, OldMeta, m_Player->GetInventory().GetEquippedItem(), PickupItems);
+
+ // Allow plugins to change the dropped objects:
+ cRoot::Get()->GetPluginManager()->CallHookBlockToPickup(OldBlock, OldMeta, m_Player, m_Player->GetInventory().GetEquippedItem(), PickupItems);
}
int pX = a_Packet->m_PosX;
diff --git a/source/cPlugin.cpp b/source/cPlugin.cpp index 51c67f2be..aa8dab01e 100644 --- a/source/cPlugin.cpp +++ b/source/cPlugin.cpp @@ -43,7 +43,7 @@ bool cPlugin::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player ) return false;
}
-bool cPlugin::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
+bool cPlugin::OnDisconnect(const AString & a_Reason, cPlayer* a_Player )
{
(void)a_Reason;
(void)a_Player;
diff --git a/source/cPlugin.h b/source/cPlugin.h index ec7baaab3..4c72b300e 100644 --- a/source/cPlugin.h +++ b/source/cPlugin.h @@ -1,6 +1,8 @@ #pragma once
+#include "cItem.h"
+
class cPacket_BlockPlace;
class cPacket_PickupSpawn;
class cPacket_EntityEquipment;
@@ -46,23 +48,24 @@ public: * On all these functions, return true if you want to override default behavior
* You can also return false, so default behavior is used, but with changed PacketData
**/
- virtual bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player );
- virtual bool OnDisconnect( std::string a_Reason, cPlayer* a_Player );
- virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player );
- virtual bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) { (void)a_PacketData; (void)a_Player; (void)a_PickupItem; return false; }
- virtual bool OnChat( const char* a_Chat, cPlayer* a_Player );
- virtual bool OnLogin( cPacket_Login* a_PacketData );
- virtual void OnPlayerSpawn( cPlayer* a_Player );
- virtual bool OnPlayerJoin( cPlayer* a_Player );
- virtual void OnPlayerMove( cPlayer* a_Player ) { (void)a_Player; }
- virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) { (void)a_Pawn; (void)a_TakeDamageInfo; }
- 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 OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player );
+ virtual bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player );
+ virtual bool OnBlockPlace (cPacket_BlockPlace* a_PacketData, cPlayer* a_Player );
+ virtual bool OnBlockDig (cPacket_BlockDig * a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) { (void)a_PacketData; (void)a_Player; (void)a_PickupItem; return false; }
+ virtual bool OnChat (const char * a_Chat, cPlayer* a_Player );
+ virtual bool OnLogin (cPacket_Login* a_PacketData );
+ virtual void OnPlayerSpawn (cPlayer* a_Player );
+ virtual bool OnPlayerJoin (cPlayer* a_Player );
+ virtual void OnPlayerMove (cPlayer* a_Player ) { (void)a_Player; }
+ virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) { (void)a_Pawn; (void)a_TakeDamageInfo; }
+ 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; }
-
+ virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups) {return false; }
+
// Accessors
const char* GetName() const { return m_Name.c_str(); }
void SetName( const char* a_Name ) { m_Name = a_Name; }
diff --git a/source/cPluginManager.cpp b/source/cPluginManager.cpp index 0f3269cf7..19518bc9b 100644 --- a/source/cPluginManager.cpp +++ b/source/cPluginManager.cpp @@ -489,6 +489,30 @@ bool cPluginManager::CallHookPostCrafting(const cPlayer * a_Player, const cCraft +bool cPluginManager::CallHookBlockToPickup(
+ BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
+ const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups
+)
+{
+ 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)->OnBlockToPickup(a_BlockType, a_BlockMeta, a_Player, a_EquippedItem, a_Pickups))
+ {
+ 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 bf891d085..0a98ccd58 100644 --- a/source/cPluginManager.h +++ b/source/cPluginManager.h @@ -1,6 +1,8 @@ #pragma once
+#include "cItem.h"
+
struct lua_State;
class cLuaCommandBinder;
class cPlugin;
@@ -46,6 +48,7 @@ public: //tolua_export HOOK_PRE_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
HOOK_CRAFTING_NO_RECIPE, /// cPlayer, cCraftingGrid, cCraftingRecipe
HOOK_POST_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
+ HOOK_BLOCK_TO_PICKUP, /// BlockType, BlockMeta, cPlayer, cItem, cItems
// E_PLUGIN_ names are obsolete, but are kept for compatibility reasons
E_PLUGIN_TICK = HOOK_TICK,
@@ -86,6 +89,7 @@ public: //tolua_export 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);
+ bool CallHookBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
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 8efca5338..ae79ebd3c 100644 --- a/source/cPlugin_NewLua.cpp +++ b/source/cPlugin_NewLua.cpp @@ -5,6 +5,7 @@ #include "cPlugin_NewLua.h"
#include "cMCLogger.h"
#include "cWebPlugin_Lua.h"
+#include "LuaItems.h"
extern "C"
{
@@ -21,14 +22,26 @@ extern "C" #include <dirent.h>
#endif
+
+
+
+
extern bool report_errors(lua_State* lua, int status);
+
+
+
+
cPlugin_NewLua::cPlugin_NewLua( const char* a_PluginName )
: m_LuaState( 0 )
{
m_Directory = a_PluginName;
}
+
+
+
+
cPlugin_NewLua::~cPlugin_NewLua()
{
cCSLock Lock( m_CriticalSection );
@@ -45,6 +58,10 @@ cPlugin_NewLua::~cPlugin_NewLua() }
}
+
+
+
+
bool cPlugin_NewLua::Initialize()
{
cCSLock Lock( m_CriticalSection );
@@ -115,6 +132,10 @@ bool cPlugin_NewLua::Initialize() return bSuccess;
}
+
+
+
+
void cPlugin_NewLua::OnDisable()
{
cCSLock Lock( m_CriticalSection );
@@ -124,6 +145,10 @@ void cPlugin_NewLua::OnDisable() CallFunction(0, 0, "OnDisable");
}
+
+
+
+
void cPlugin_NewLua::Tick(float a_Dt)
{
cCSLock Lock( m_CriticalSection );
@@ -159,7 +184,7 @@ bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player ) -bool cPlugin_NewLua::OnDisconnect( std::string a_Reason, cPlayer* a_Player )
+bool cPlugin_NewLua::OnDisconnect(const AString & a_Reason, cPlayer* a_Player )
{
cCSLock Lock( m_CriticalSection );
if( !PushFunction("OnDisconnect") )
@@ -453,6 +478,35 @@ bool cPlugin_NewLua::OnPostCrafting(const cPlayer * a_Player, const cCraftingGri +bool cPlugin_NewLua::OnBlockToPickup(
+ BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
+ const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups
+)
+{
+ cLuaItems Pickups(a_Pickups);
+ cCSLock Lock(m_CriticalSection);
+ if (!PushFunction("OnBlockToPickup"))
+ return false;
+
+ tolua_pushnumber (m_LuaState, a_BlockType);
+ tolua_pushnumber (m_LuaState, a_BlockMeta);
+ tolua_pushusertype(m_LuaState, (void *)a_Player, "cPlayer");
+ tolua_pushusertype(m_LuaState, (void *)&a_EquippedItem, "cItem");
+ tolua_pushusertype(m_LuaState, (void *)&Pickups, "cLuaItems");
+
+ if (!CallFunction(5, 1, "OnBlockToPickup"))
+ {
+ 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 6ecdada11..d6bb50637 100644 --- a/source/cPlugin_NewLua.h +++ b/source/cPlugin_NewLua.h @@ -25,24 +25,23 @@ public: //tolua_export virtual void Tick(float a_Dt); //tolua_export
- virtual bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player ) override;
- virtual bool OnDisconnect( std::string a_Reason, cPlayer* a_Player ) override;
- virtual bool OnBlockPlace( cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ) override;
- virtual bool OnBlockDig( cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) override;
- virtual bool OnChat( const char* a_Chat, cPlayer* a_Player ) override;
- virtual bool OnLogin( cPacket_Login* a_PacketData ) override;
- virtual void OnPlayerSpawn( cPlayer* a_Player ) override;
- virtual bool OnPlayerJoin( cPlayer* a_Player ) override;
- virtual void OnPlayerMove( cPlayer* a_Player ) override;
- virtual void OnTakeDamage( cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
- virtual bool OnKilled( cPawn* a_Killed, cEntity* a_Killer ) override;
-
- 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 OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
+ virtual bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
+ virtual bool OnBlockPlace (cPacket_BlockPlace* a_PacketData, cPlayer* a_Player ) override;
+ virtual bool OnBlockDig (cPacket_BlockDig* a_PacketData, cPlayer* a_Player, cItem* a_PickupItem ) override;
+ virtual bool OnChat (const char* a_Chat, cPlayer* a_Player ) override;
+ virtual bool OnLogin (cPacket_Login* a_PacketData ) override;
+ virtual void OnPlayerSpawn (cPlayer* a_Player ) override;
+ virtual bool OnPlayerJoin (cPlayer* a_Player ) override;
+ virtual void OnPlayerMove (cPlayer* a_Player ) override;
+ virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
+ virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
+ 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;
+ virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
lua_State* GetLuaState() { return m_LuaState; }
|