Addeed OnSpawningEntity, OnSpawnedEntity, OnSpawningMonster, OnSpawnedMonster hooks.
As requested in FS 418.
This commit is contained in:
parent
be7a6d7a66
commit
3f4abe8c95
@ -45,6 +45,10 @@ function Initialize(Plugin)
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_SPAWNED_ENTITY);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_SPAWNED_MONSTER);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_SPAWNING_ENTITY);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_SPAWNING_MONSTER);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATED_SIGN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATING_SIGN);
|
||||
@ -358,6 +362,38 @@ end
|
||||
|
||||
|
||||
|
||||
function OnSpawnedEntity(...)
|
||||
LogHook("OnSpawnedEntity", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnSpawnedMonster(...)
|
||||
LogHook("OnSpawnedMonster", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnSpawningEntity(...)
|
||||
LogHook("OnSpawningEntity", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnSpawningMonster(...)
|
||||
LogHook("OnSpawningMonster", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnUpdatedSign(...)
|
||||
LogHook("OnUpdatedSign", unpack(arg));
|
||||
end
|
||||
|
@ -59,6 +59,7 @@ $cfile "Generating/ChunkDesc.h"
|
||||
$cfile "CraftingRecipes.h"
|
||||
$cfile "UI/Window.h"
|
||||
$cfile "LuaWindow.h"
|
||||
$cfile "Mobs/Monster.h"
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/07/13 12:06:03.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/08/13 09:04:23.
|
||||
*/
|
||||
|
||||
#ifndef __cplusplus
|
||||
@ -59,6 +59,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
|
||||
#include "CraftingRecipes.h"
|
||||
#include "UI/Window.h"
|
||||
#include "LuaWindow.h"
|
||||
#include "Mobs/Monster.h"
|
||||
|
||||
/* function to release collected object via destructor */
|
||||
#ifdef __cplusplus
|
||||
@ -203,6 +204,7 @@ static void tolua_reg_types (lua_State* tolua_S)
|
||||
{
|
||||
tolua_usertype(tolua_S,"TakeDamageInfo");
|
||||
tolua_usertype(tolua_S,"cPlugin_NewLua");
|
||||
tolua_usertype(tolua_S,"cMonster");
|
||||
tolua_usertype(tolua_S,"cCraftingGrid");
|
||||
tolua_usertype(tolua_S,"cCraftingRecipe");
|
||||
tolua_usertype(tolua_S,"cPlugin");
|
||||
@ -8256,10 +8258,11 @@ static int tolua_AllToLua_cPlayer_Initialize00(lua_State* tolua_S)
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Initialize'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->Initialize(a_World);
|
||||
bool tolua_ret = (bool) self->Initialize(a_World);
|
||||
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'Initialize'.",&tolua_err);
|
||||
@ -10087,12 +10090,15 @@ static int tolua_AllToLua_cPlayer_SetSprint00(lua_State* tolua_S)
|
||||
|
||||
class Lua__cPlayer : public cPlayer, public ToluaBase {
|
||||
public:
|
||||
void Initialize( cWorld* a_World) {
|
||||
bool Initialize( cWorld* a_World) {
|
||||
if (push_method("Initialize", tolua_AllToLua_cPlayer_Initialize00)) {
|
||||
tolua_pushusertype(lua_state, (void*)a_World, "cWorld");
|
||||
ToluaBase::dbcall(lua_state, 2, 0);
|
||||
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 ( void ) cPlayer:: Initialize(a_World);
|
||||
return ( bool ) cPlayer:: Initialize(a_World);
|
||||
};
|
||||
};
|
||||
void MoveTo( const Vector3d& a_NewPos) {
|
||||
@ -10296,8 +10302,8 @@ public:
|
||||
};
|
||||
};
|
||||
|
||||
void cPlayer__Initialize( cWorld* a_World) {
|
||||
return ( void )cPlayer::Initialize(a_World);
|
||||
bool cPlayer__Initialize( cWorld* a_World) {
|
||||
return ( bool )cPlayer::Initialize(a_World);
|
||||
};
|
||||
void cPlayer__MoveTo( const Vector3d& a_NewPos) {
|
||||
return ( void )cPlayer::MoveTo(a_NewPos);
|
||||
@ -10415,10 +10421,11 @@ static int tolua_AllToLua_Lua__cPlayer_cPlayer__Initialize00(lua_State* tolua_S)
|
||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlayer__Initialize'", NULL);
|
||||
#endif
|
||||
{
|
||||
self->cPlayer__Initialize(a_World);
|
||||
bool tolua_ret = (bool) self->cPlayer__Initialize(a_World);
|
||||
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 1;
|
||||
#ifndef TOLUA_RELEASE
|
||||
tolua_lerror:
|
||||
tolua_error(tolua_S,"#ferror in function 'cPlayer__Initialize'.",&tolua_err);
|
||||
@ -29527,6 +29534,10 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_constant(tolua_S,"HOOK_PLAYER_USING_ITEM",cPluginManager::HOOK_PLAYER_USING_ITEM);
|
||||
tolua_constant(tolua_S,"HOOK_POST_CRAFTING",cPluginManager::HOOK_POST_CRAFTING);
|
||||
tolua_constant(tolua_S,"HOOK_PRE_CRAFTING",cPluginManager::HOOK_PRE_CRAFTING);
|
||||
tolua_constant(tolua_S,"HOOK_SPAWNED_ENTITY",cPluginManager::HOOK_SPAWNED_ENTITY);
|
||||
tolua_constant(tolua_S,"HOOK_SPAWNED_MONSTER",cPluginManager::HOOK_SPAWNED_MONSTER);
|
||||
tolua_constant(tolua_S,"HOOK_SPAWNING_ENTITY",cPluginManager::HOOK_SPAWNING_ENTITY);
|
||||
tolua_constant(tolua_S,"HOOK_SPAWNING_MONSTER",cPluginManager::HOOK_SPAWNING_MONSTER);
|
||||
tolua_constant(tolua_S,"HOOK_TAKE_DAMAGE",cPluginManager::HOOK_TAKE_DAMAGE);
|
||||
tolua_constant(tolua_S,"HOOK_TICK",cPluginManager::HOOK_TICK);
|
||||
tolua_constant(tolua_S,"HOOK_UPDATED_SIGN",cPluginManager::HOOK_UPDATED_SIGN);
|
||||
@ -30341,6 +30352,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
|
||||
tolua_function(tolua_S,"GetContents",tolua_AllToLua_cLuaWindow_GetContents00);
|
||||
tolua_variable(tolua_S,"__cItemGrid__cListener__",tolua_get_cLuaWindow___cItemGrid__cListener__,NULL);
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cMonster","cMonster","cPawn",NULL);
|
||||
tolua_beginmodule(tolua_S,"cMonster");
|
||||
tolua_endmodule(tolua_S);
|
||||
tolua_cclass(tolua_S,"cLineBlockTracer","cLineBlockTracer","",NULL);
|
||||
tolua_beginmodule(tolua_S,"cLineBlockTracer");
|
||||
tolua_endmodule(tolua_S);
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
** Lua binding: AllToLua
|
||||
** Generated automatically by tolua++-1.0.92 on 08/07/13 12:06:04.
|
||||
** Generated automatically by tolua++-1.0.92 on 08/08/13 09:04:23.
|
||||
*/
|
||||
|
||||
/* Exported function */
|
||||
|
@ -129,14 +129,22 @@ const char * cEntity::GetParentClass(void) const
|
||||
|
||||
|
||||
|
||||
void cEntity::Initialize(cWorld * a_World)
|
||||
bool cEntity::Initialize(cWorld * a_World)
|
||||
{
|
||||
if (cPluginManager::Get()->CallHookSpawningEntity(*a_World, *this))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGD("Initializing entity #%d (%s) at {%.02f, %.02f, %.02f}",
|
||||
m_UniqueID, GetClass(), m_Pos.x, m_Pos.y, m_Pos.z
|
||||
);
|
||||
m_IsInitialized = true;
|
||||
m_World = a_World;
|
||||
m_World->AddEntity(this);
|
||||
|
||||
cPluginManager::Get()->CallHookSpawnedEntity(*a_World, *this);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -107,7 +107,8 @@ public:
|
||||
cEntity(eEntityType a_EntityType, double a_X, double a_Y, double a_Z, double a_Width, double a_Height);
|
||||
virtual ~cEntity();
|
||||
|
||||
virtual void Initialize(cWorld * a_World);
|
||||
/// Spawns the entity in the world; returns true if spawned, false if not (plugin disallowed)
|
||||
virtual bool Initialize(cWorld * a_World);
|
||||
|
||||
// tolua_begin
|
||||
|
||||
|
@ -22,10 +22,14 @@ cFallingBlock::cFallingBlock(const Vector3i & a_BlockPosition, BLOCKTYPE a_Block
|
||||
|
||||
|
||||
|
||||
void cFallingBlock::Initialize(cWorld * a_World)
|
||||
bool cFallingBlock::Initialize(cWorld * a_World)
|
||||
{
|
||||
super::Initialize(a_World);
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
if (super::Initialize(a_World))
|
||||
{
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ public:
|
||||
NIBBLETYPE GetBlockMeta(void) const { return m_BlockMeta; }
|
||||
|
||||
// cEntity overrides:
|
||||
virtual void Initialize(cWorld * a_World) override;
|
||||
virtual bool Initialize(cWorld * a_World) override;
|
||||
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
|
||||
|
@ -396,6 +396,19 @@ void cLuaState::PushObject(cEntity * a_Entity)
|
||||
|
||||
|
||||
|
||||
void cLuaState::PushObject(cMonster * a_Monster)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
ASSERT(m_NumCurrentFunctionArgs >= 0); // A function must be pushed to stack first
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_Monster, "cMonster");
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void cLuaState::PushObject(cItem * a_Item)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
@ -36,6 +36,7 @@ extern "C"
|
||||
class cWorld;
|
||||
class cPlayer;
|
||||
class cEntity;
|
||||
class cMonster;
|
||||
class cItem;
|
||||
class cItems;
|
||||
class cClientHandle;
|
||||
@ -145,6 +146,7 @@ public:
|
||||
void PushObject(cWorld * a_World);
|
||||
void PushObject(cPlayer * a_Player);
|
||||
void PushObject(cEntity * a_Entity);
|
||||
void PushObject(cMonster * a_Monster);
|
||||
void PushObject(cItem * a_Item);
|
||||
void PushObject(cItems * a_Items);
|
||||
void PushObject(cClientHandle * a_ClientHandle);
|
||||
|
@ -22,10 +22,14 @@ cMinecart::cMinecart(ePayload a_Payload, double a_X, double a_Y, double a_Z) :
|
||||
|
||||
|
||||
|
||||
void cMinecart::Initialize(cWorld * a_World)
|
||||
bool cMinecart::Initialize(cWorld * a_World)
|
||||
{
|
||||
super::Initialize(a_World);
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
if (super::Initialize(a_World))
|
||||
{
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
} ;
|
||||
|
||||
// cEntity overrides:
|
||||
virtual void Initialize(cWorld * a_World) override;
|
||||
virtual bool Initialize(cWorld * a_World) override;
|
||||
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
|
||||
|
@ -41,10 +41,14 @@ cPickup::cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem
|
||||
|
||||
|
||||
|
||||
void cPickup::Initialize(cWorld * a_World)
|
||||
bool cPickup::Initialize(cWorld * a_World)
|
||||
{
|
||||
super::Initialize(a_World);
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
if (super::Initialize(a_World))
|
||||
{
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
|
||||
cPickup(int a_MicroPosX, int a_MicroPosY, int a_MicroPosZ, const cItem & a_Item, float a_SpeedX = 0.f, float a_SpeedY = 0.f, float a_SpeedZ = 0.f); // tolua_export
|
||||
|
||||
virtual void Initialize(cWorld * a_World) override;
|
||||
virtual bool Initialize(cWorld * a_World) override;
|
||||
|
||||
cItem & GetItem(void) {return m_Item; } // tolua_export
|
||||
const cItem & GetItem(void) const {return m_Item; }
|
||||
|
@ -121,10 +121,14 @@ cPlayer::~cPlayer(void)
|
||||
|
||||
|
||||
|
||||
void cPlayer::Initialize(cWorld * a_World)
|
||||
bool cPlayer::Initialize(cWorld * a_World)
|
||||
{
|
||||
super::Initialize(a_World);
|
||||
GetWorld()->AddPlayer(this);
|
||||
if (super::Initialize(a_World))
|
||||
{
|
||||
GetWorld()->AddPlayer(this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
cPlayer(cClientHandle * a_Client, const AString & a_PlayerName);
|
||||
virtual ~cPlayer();
|
||||
|
||||
virtual void Initialize(cWorld * a_World); // tolua_export
|
||||
virtual bool Initialize(cWorld * a_World); // tolua_export
|
||||
|
||||
virtual void SpawnOn(cClientHandle & a_Client) override;
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "Player.h"
|
||||
#include "World.h"
|
||||
#include "CommandOutput.h"
|
||||
#include "Mobs/Monster.h"
|
||||
|
||||
|
||||
|
||||
@ -478,6 +479,50 @@ bool cPlugin::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Gr
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
UNUSED(a_World);
|
||||
UNUSED(a_Entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
UNUSED(a_World);
|
||||
UNUSED(a_Monster);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnSpawningEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
UNUSED(a_World);
|
||||
UNUSED(a_Entity);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnSpawningMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
UNUSED(a_World);
|
||||
UNUSED(a_Monster);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin::OnTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TakeDamageInfo)
|
||||
{
|
||||
UNUSED(a_Receiver);
|
||||
|
@ -80,6 +80,10 @@ public:
|
||||
virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
|
||||
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster);
|
||||
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
virtual bool OnSpawningMonster (cWorld & a_World, cMonster & a_Monster);
|
||||
virtual bool OnTakeDamage (cEntity & a_Receiver, TakeDamageInfo & a_TakeDamageInfo);
|
||||
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player);
|
||||
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
|
||||
|
@ -888,6 +888,88 @@ bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCrafti
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNED_ENTITY);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnSpawnedEntity(a_World, a_Entity))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNED_MONSTER);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnSpawnedMonster(a_World, a_Monster))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookSpawningEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNING_ENTITY);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnSpawningEntity(a_World, a_Entity))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookSpawningMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_SPAWNING_MONSTER);
|
||||
if (Plugins == m_Hooks.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||
{
|
||||
if ((*itr)->OnSpawningMonster(a_World, a_Monster))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPluginManager::CallHookTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
|
||||
{
|
||||
HookMap::iterator Plugins = m_Hooks.find(HOOK_TAKE_DAMAGE);
|
||||
|
@ -15,9 +15,12 @@ class cWorld;
|
||||
// fwd: ChunkDesc.h
|
||||
class cChunkDesc;
|
||||
|
||||
// fwd: Entityes/Entity.h
|
||||
// fwd: Entities/Entity.h
|
||||
class cEntity;
|
||||
|
||||
// fwd: Mobs/Monster.h
|
||||
class cMonster;
|
||||
|
||||
// fwd: Player.h
|
||||
class cPlayer;
|
||||
|
||||
@ -82,6 +85,10 @@ public: // tolua_export
|
||||
HOOK_PLAYER_USING_ITEM,
|
||||
HOOK_POST_CRAFTING,
|
||||
HOOK_PRE_CRAFTING,
|
||||
HOOK_SPAWNED_ENTITY,
|
||||
HOOK_SPAWNED_MONSTER,
|
||||
HOOK_SPAWNING_ENTITY,
|
||||
HOOK_SPAWNING_MONSTER,
|
||||
HOOK_TAKE_DAMAGE,
|
||||
HOOK_TICK,
|
||||
HOOK_UPDATED_SIGN,
|
||||
@ -116,8 +123,9 @@ public: // tolua_export
|
||||
void ReloadPlugins(); // tolua_export
|
||||
void AddHook( cPlugin* a_Plugin, PluginHook a_Hook ); // tolua_export
|
||||
|
||||
unsigned int GetNumPlugins() const; // tolua_export
|
||||
|
||||
unsigned int GetNumPlugins() const; // tolua_export
|
||||
|
||||
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
|
||||
bool CallHookBlockToPickups (cWorld * a_World, cEntity * a_Digger, int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cItems & a_Pickups);
|
||||
bool CallHookChat (cPlayer * a_Player, AString & a_Message);
|
||||
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
||||
@ -151,6 +159,10 @@ public: // tolua_export
|
||||
bool CallHookPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ);
|
||||
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
|
||||
bool CallHookSpawnedEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
bool CallHookSpawnedMonster (cWorld & a_World, cMonster & a_Monster);
|
||||
bool CallHookSpawningEntity (cWorld & a_World, cEntity & a_Entity);
|
||||
bool CallHookSpawningMonster (cWorld & a_World, cMonster & a_Monster);
|
||||
bool CallHookTakeDamage (cEntity & a_Receiver, TakeDamageInfo & a_TDI);
|
||||
bool CallHookUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player);
|
||||
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player);
|
||||
|
@ -1102,6 +1102,117 @@ bool cPlugin_NewLua::OnPreCrafting(const cPlayer * a_Player, const cCraftingGrid
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnSpawnedEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNED_ENTITY);
|
||||
ASSERT(FnName != NULL);
|
||||
if (!m_LuaState.PushFunction(FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_LuaState.PushObject(&a_World);
|
||||
m_LuaState.PushObject(&a_Entity);
|
||||
|
||||
if (!m_LuaState.CallFunction(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
||||
lua_pop(m_LuaState, 1);
|
||||
return bRetVal;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnSpawnedMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNED_MONSTER);
|
||||
ASSERT(FnName != NULL);
|
||||
if (!m_LuaState.PushFunction(FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_LuaState.PushObject(&a_World);
|
||||
m_LuaState.PushObject(&a_Monster);
|
||||
|
||||
if (!m_LuaState.CallFunction(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
||||
lua_pop(m_LuaState, 1);
|
||||
return bRetVal;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnSpawningEntity(cWorld & a_World, cEntity & a_Entity)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNING_ENTITY);
|
||||
ASSERT(FnName != NULL);
|
||||
if (!m_LuaState.PushFunction(FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_LuaState.PushObject(&a_World);
|
||||
m_LuaState.PushObject(&a_Entity);
|
||||
|
||||
if (!m_LuaState.CallFunction(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
||||
lua_pop(m_LuaState, 1);
|
||||
return bRetVal;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnSpawningMonster(cWorld & a_World, cMonster & a_Monster)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
const char * FnName = GetHookFnName(cPluginManager::HOOK_SPAWNING_MONSTER);
|
||||
ASSERT(FnName != NULL);
|
||||
if (!m_LuaState.PushFunction(FnName))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_LuaState.PushObject(&a_World);
|
||||
m_LuaState.PushObject(&a_Monster);
|
||||
|
||||
if (!m_LuaState.CallFunction(1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool bRetVal = (tolua_toboolean(m_LuaState, -1, 0) > 0);
|
||||
lua_pop(m_LuaState, 1);
|
||||
return bRetVal;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool cPlugin_NewLua::OnTakeDamage(cEntity & a_Receiver, TakeDamageInfo & a_TDI)
|
||||
{
|
||||
cCSLock Lock(m_CriticalSection);
|
||||
@ -1482,6 +1593,10 @@ const char * cPlugin_NewLua::GetHookFnName(cPluginManager::PluginHook a_Hook)
|
||||
case cPluginManager::HOOK_PLAYER_USING_ITEM: return "OnPlayerUsingItem";
|
||||
case cPluginManager::HOOK_POST_CRAFTING: return "OnPostCrafting";
|
||||
case cPluginManager::HOOK_PRE_CRAFTING: return "OnPreCrafting";
|
||||
case cPluginManager::HOOK_SPAWNED_ENTITY: return "OnSpawnedEntity";
|
||||
case cPluginManager::HOOK_SPAWNED_MONSTER: return "OnSpawnedMonster";
|
||||
case cPluginManager::HOOK_SPAWNING_ENTITY: return "OnSpawningEntity";
|
||||
case cPluginManager::HOOK_SPAWNING_MONSTER: return "OnSpawningMonster";
|
||||
case cPluginManager::HOOK_TAKE_DAMAGE: return "OnTakeDamage";
|
||||
case cPluginManager::HOOK_TICK: return "OnTick";
|
||||
case cPluginManager::HOOK_UPDATED_SIGN: return "OnUpdatedSign";
|
||||
|
@ -68,6 +68,10 @@ public:
|
||||
virtual bool OnPlayerUsingItem (cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
|
||||
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
|
||||
virtual bool OnSpawnedEntity (cWorld & a_World, cEntity & a_Entity) override;
|
||||
virtual bool OnSpawnedMonster (cWorld & a_World, cMonster & a_Monster) override;
|
||||
virtual bool OnSpawningEntity (cWorld & a_World, cEntity & a_Entity) override;
|
||||
virtual bool OnSpawningMonster (cWorld & a_World, cMonster & a_Monster) override;
|
||||
virtual bool OnTakeDamage (cEntity & a_Receiver, TakeDamageInfo & a_TakeDamageInfo) override;
|
||||
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player) override;
|
||||
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4, cPlayer * a_Player) override;
|
||||
|
@ -29,10 +29,14 @@ cTNTEntity::cTNTEntity(const Vector3d & a_Pos, float a_FuseTimeInSec) :
|
||||
|
||||
|
||||
|
||||
void cTNTEntity::Initialize(cWorld * a_World)
|
||||
bool cTNTEntity::Initialize(cWorld * a_World)
|
||||
{
|
||||
super::Initialize(a_World);
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
if (super::Initialize(a_World))
|
||||
{
|
||||
a_World->BroadcastSpawnEntity(*this);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,7 +20,7 @@ public:
|
||||
cTNTEntity(const Vector3d & a_Pos, float a_FuseTimeInSec);
|
||||
|
||||
// cEntity overrides:
|
||||
virtual void Initialize(cWorld * a_World) override;
|
||||
virtual bool Initialize(cWorld * a_World) override;
|
||||
virtual void SpawnOn(cClientHandle & a_ClientHandle) override;
|
||||
virtual void Tick(float a_Dt, cChunk & a_Chunk) override;
|
||||
|
||||
|
@ -2414,14 +2414,24 @@ int cWorld::SpawnMob(double a_PosX, double a_PosY, double a_PosZ, int a_EntityTy
|
||||
|
||||
default:
|
||||
{
|
||||
LOGWARNING("cWorld::SpawnMob(): Unhandled entity type: %d. Not spawning.", a_EntityType);
|
||||
LOGWARNING("%s: Unhandled entity type: %d. Not spawning.", __FUNCTION__, a_EntityType);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Monster->SetPosition(a_PosX, a_PosY, a_PosZ);
|
||||
Monster->SetHealth(Monster->GetMaxHealth());
|
||||
Monster->Initialize(this);
|
||||
if (cPluginManager::Get()->CallHookSpawningMonster(*this, *Monster))
|
||||
{
|
||||
delete Monster;
|
||||
return -1;
|
||||
}
|
||||
if (!Monster->Initialize(this))
|
||||
{
|
||||
delete Monster;
|
||||
return -1;
|
||||
}
|
||||
BroadcastSpawnEntity(*Monster);
|
||||
cPluginManager::Get()->CallHookSpawnedMonster(*this, *Monster);
|
||||
return Monster->GetUniqueID();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user