From 1a127f5510f654d47ee75b3121e52c50d3e7533b Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sun, 27 Jan 2013 02:00:33 +0000 Subject: Added the HOOK_BLOCK_TO_PICKUPS hook that fires when a block is dug up and should be converted to pickups. Note that cItems is used in the function signature but not yet exported in the API, TODO! git-svn-id: http://mc-server.googlecode.com/svn/trunk@1176 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Plugin_NewLua.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'source/Plugin_NewLua.cpp') diff --git a/source/Plugin_NewLua.cpp b/source/Plugin_NewLua.cpp index ef7c148be..0ddfb54f8 100644 --- a/source/Plugin_NewLua.cpp +++ b/source/Plugin_NewLua.cpp @@ -164,6 +164,39 @@ void cPlugin_NewLua::Tick(float a_Dt) +bool cPlugin_NewLua::OnBlockToPickups(cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups) +{ + cCSLock Lock(m_CriticalSection); + const char * FnName = GetHookFnName(cPluginManager::HOOK_BLOCK_TO_PICKUPS); + ASSERT(FnName != NULL); + if (!PushFunction(FnName)) + { + return false; + } + + tolua_pushusertype(m_LuaState, a_World, "cWorld"); + tolua_pushusertype(m_LuaState, a_Digger, "cEntity"); + tolua_pushnumber (m_LuaState, a_BlockX); + tolua_pushnumber (m_LuaState, a_BlockY); + tolua_pushnumber (m_LuaState, a_BlockZ); + tolua_pushnumber (m_LuaState, a_BlockType); + tolua_pushnumber (m_LuaState, a_BlockMeta); + tolua_pushusertype(m_LuaState, &a_Pickups, "cItems"); + + if (!CallFunction(8, 1, FnName)) + { + return false; + } + + bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0); + lua_pop(m_LuaState, 1); + return bRetVal; +} + + + + + bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message) { cCSLock Lock(m_CriticalSection); @@ -1154,6 +1187,7 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook) { switch (a_Hook) { + case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups"; case cPluginManager::HOOK_CHAT: return "OnChat"; case cPluginManager::HOOK_CHUNK_GENERATED: return "OnChunkGenerated"; case cPluginManager::HOOK_CHUNK_GENERATING: return "OnChunkGenerating"; -- cgit v1.2.3