From 1c60680fbac2f06823dba123241adc607363a25b Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Wed, 13 Jun 2012 17:37:23 +0000 Subject: Added a BlockToPickup hook for modifying pickups when a player breaks a block. git-svn-id: http://mc-server.googlecode.com/svn/trunk@602 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cPlugin_NewLua.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'source/cPlugin_NewLua.cpp') 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 #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 ); -- cgit v1.2.3