1
0

Renamed HOOK_WEATHER_CHANGE to HOOK_WEATHER_CHANGED, added the glue code for it to actually work

git-svn-id: http://mc-server.googlecode.com/svn/trunk@610 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com 2012-06-14 19:20:31 +00:00
parent 0f39e9b10b
commit e1b5f0af04
8 changed files with 152 additions and 7 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 06/14/12 19:28:15.
** Generated automatically by tolua++-1.0.92 on 06/14/12 21:17:55.
*/
#ifndef __cplusplus
@ -8051,6 +8051,40 @@ static int tolua_AllToLua_cPlugin_OnBlockToPickup00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
/* method: OnWeatherChanged of class cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnWeatherChanged00
static int tolua_AllToLua_cPlugin_OnWeatherChanged00(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,"cWorld",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnWeatherChanged'", NULL);
#endif
{
bool tolua_ret = (bool) self->OnWeatherChanged(a_World);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'OnWeatherChanged'.",&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)
@ -8544,6 +8578,17 @@ public:
return ( bool ) cPlugin:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
};
bool OnWeatherChanged( cWorld* a_World) {
if (push_method("OnWeatherChanged", tolua_AllToLua_cPlugin_OnWeatherChanged00)) {
tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return ( bool ) cPlugin:: OnWeatherChanged(a_World);
};
};
void cPlugin__OnDisable( void ) {
return ( void )cPlugin::OnDisable();
@ -8601,6 +8646,9 @@ public:
};
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);
};
bool cPlugin__OnWeatherChanged( cWorld* a_World) {
return ( bool )cPlugin::OnWeatherChanged(a_World);
};
Lua__cPlugin( void ): cPlugin(){};
};
@ -9323,6 +9371,40 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnBlockToPickup00(lua_State* tol
}
#endif //#ifndef TOLUA_DISABLE
/* method: cPlugin__OnWeatherChanged of class Lua__cPlugin */
#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnWeatherChanged00
static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnWeatherChanged00(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,"cWorld",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
else
#endif
{
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
cWorld* a_World = ((cWorld*) tolua_tousertype(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnWeatherChanged'", NULL);
#endif
{
bool tolua_ret = (bool) self->cPlugin__OnWeatherChanged(a_World);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'cPlugin__OnWeatherChanged'.",&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)
@ -9777,6 +9859,17 @@ public:
return ( bool ) cPlugin_NewLua:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
};
bool OnWeatherChanged( cWorld* a_World) {
if (push_method("OnWeatherChanged", tolua_AllToLua_cPlugin_OnWeatherChanged00)) {
tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
ToluaBase::dbcall(lua_state, 2, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return ( bool ) cPlugin_NewLua:: OnWeatherChanged(a_World);
};
};
void cPlugin_NewLua__OnDisable( void ) {
return ( void )cPlugin_NewLua::OnDisable();
@ -9838,6 +9931,9 @@ public:
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);
};
bool cPlugin_NewLua__OnWeatherChanged( cWorld* a_World) {
return ( bool )cPlugin_NewLua::OnWeatherChanged(a_World);
};
};
/* method: tolua__set_instance of class Lua__cPlugin_NewLua */
@ -20740,7 +20836,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
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,"HOOK_WEATHER_CHANGE",cPluginManager::HOOK_WEATHER_CHANGE);
tolua_constant(tolua_S,"HOOK_WEATHER_CHANGED",cPluginManager::HOOK_WEATHER_CHANGED);
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);
@ -20794,6 +20890,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
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,"OnWeatherChanged",tolua_AllToLua_cPlugin_OnWeatherChanged00);
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);
@ -20832,6 +20929,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
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,"cPlugin__OnWeatherChanged",tolua_AllToLua_Lua__cPlugin_cPlugin__OnWeatherChanged00);
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);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 06/14/12 19:28:15.
** Generated automatically by tolua++-1.0.92 on 06/14/12 21:17:55.
*/
/* Exported function */

View File

@ -65,6 +65,7 @@ public:
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; }
virtual bool OnWeatherChanged (cWorld * a_World) {return false; }
// Accessors
const char* GetName() const { return m_Name.c_str(); }

View File

@ -512,6 +512,27 @@ bool cPluginManager::CallHookBlockToPickup(
bool cPluginManager::CallHookWeatherChanged(cWorld * a_World)
{
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)->OnWeatherChanged(a_World))
{
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 )

View File

@ -55,7 +55,7 @@ public: //tolua_export
HOOK_CRAFTING_NO_RECIPE, /// cPlayer, cCraftingGrid, cCraftingRecipe
HOOK_POST_CRAFTING, /// cPlayer, cCraftingGrid, cCraftingRecipe
HOOK_BLOCK_TO_PICKUP, /// BlockType, BlockMeta, cPlayer, cItem, cItems
HOOK_WEATHER_CHANGE,
HOOK_WEATHER_CHANGED,
// E_PLUGIN_ names are obsolete, but are kept for compatibility reasons
E_PLUGIN_TICK = HOOK_TICK,
@ -98,6 +98,7 @@ public: //tolua_export
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);
bool CallHookWeatherChanged (cWorld * a_World);
void RemoveHooks( cPlugin* a_Plugin );
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export

View File

@ -508,6 +508,29 @@ bool cPlugin_NewLua::OnBlockToPickup(
bool cPlugin_NewLua::OnWeatherChanged(cWorld * a_World)
{
cCSLock Lock(m_CriticalSection);
if (!PushFunction("OnWeatherChanged"))
{
return false;
}
tolua_pushusertype(m_LuaState, (void *)a_World, "cWorld");
if (!CallFunction(1, 1, "OnWeatherChanged"))
{
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 );

View File

@ -42,6 +42,7 @@ public: //tolua_export
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);
virtual bool OnWeatherChanged (cWorld * a_World) override;
lua_State* GetLuaState() { return m_LuaState; }

View File

@ -673,13 +673,13 @@ void cWorld::ChangeWeather()
void cWorld::TickWeather(float a_Dt)
{
if(m_WeatherInterval == 0)
if (m_WeatherInterval == 0)
{
ChangeWeather();
cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::HOOK_WEATHER_CHANGE, 0 );
cRoot::Get()->GetPluginManager()->CallHookWeatherChanged(this);
switch(GetWeather())
switch (GetWeather())
{
case eWeather_Sunny:
m_WeatherInterval = 14400 + (m_TickRand.randInt() % 4800); // 12 - 16 minutes