summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/Bindings.cpp71
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cChunk.cpp16
-rw-r--r--source/cChunk.h2
-rw-r--r--source/cChunkMap.cpp16
-rw-r--r--source/cChunkMap.h3
-rw-r--r--source/cClientHandle.cpp13
-rw-r--r--source/cClientHandle.h1
-rw-r--r--source/cPickup.cpp25
-rw-r--r--source/cPlugin.cpp4
-rw-r--r--source/cPlugin.h2
-rw-r--r--source/cPluginManager.cpp37
-rw-r--r--source/cPluginManager.h7
-rw-r--r--source/cPlugin_NewLua.cpp17
-rw-r--r--source/cPlugin_NewLua.h2
-rw-r--r--source/cPlugin_Squirrel.cpp11
-rw-r--r--source/cPlugin_Squirrel.h17
-rw-r--r--source/cWorld.cpp9
-rw-r--r--source/cWorld.h1
19 files changed, 175 insertions, 81 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index a143eac8e..f1f051ef5 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/24/12 09:56:22.
+** Generated automatically by tolua++-1.0.92 on 08/24/12 10:55:13.
*/
#ifndef __cplusplus
@@ -7879,16 +7879,16 @@ static int tolua_AllToLua_cPlugin_OnChunkGenerating00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
-/* method: OnCollectItem of class cPlugin */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnCollectItem00
-static int tolua_AllToLua_cPlugin_OnCollectItem00(lua_State* tolua_S)
+/* method: OnCollectPickup of class cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cPlugin_OnCollectPickup00
+static int tolua_AllToLua_cPlugin_OnCollectPickup00(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,"cPickup",0,&tolua_err) ||
- !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPickup",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
@@ -7896,20 +7896,20 @@ static int tolua_AllToLua_cPlugin_OnCollectItem00(lua_State* tolua_S)
#endif
{
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
- cPickup* a_Pickup = ((cPickup*) tolua_tousertype(tolua_S,2,0));
- cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+ cPickup* a_Pickup = ((cPickup*) tolua_tousertype(tolua_S,3,0));
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnCollectItem'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnCollectPickup'", NULL);
#endif
{
- bool tolua_ret = (bool) self->OnCollectItem(a_Pickup,a_Player);
+ bool tolua_ret = (bool) self->OnCollectPickup(a_Player,a_Pickup);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'OnCollectItem'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'OnCollectPickup'.",&tolua_err);
return 0;
#endif
}
@@ -8793,16 +8793,16 @@ public:
return ( bool ) cPlugin:: OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
};
- bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
- tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ bool OnCollectPickup( cPlayer* a_Player, cPickup* a_Pickup) {
+ if (push_method("OnCollectPickup", tolua_AllToLua_cPlugin_OnCollectPickup00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
ToluaBase::dbcall(lua_state, 3, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin:: OnCollectItem(a_Pickup,a_Player);
+ return ( bool ) cPlugin:: OnCollectPickup(a_Player,a_Pickup);
};
};
bool OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
@@ -8997,8 +8997,8 @@ public:
bool cPlugin__OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin::OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
- bool cPlugin__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- return ( bool )cPlugin::OnCollectItem(a_Pickup,a_Player);
+ bool cPlugin__OnCollectPickup( cPlayer* a_Player, cPickup* a_Pickup) {
+ return ( bool )cPlugin::OnCollectPickup(a_Player,a_Pickup);
};
bool cPlugin__OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
return ( bool )cPlugin::OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
@@ -9390,16 +9390,16 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00(lua_State* t
}
#endif //#ifndef TOLUA_DISABLE
-/* method: cPlugin__OnCollectItem of class Lua__cPlugin */
-#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectItem00
-static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectItem00(lua_State* tolua_S)
+/* method: cPlugin__OnCollectPickup of class Lua__cPlugin */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectPickup00
+static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectPickup00(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,"cPickup",0,&tolua_err) ||
- !tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
+ !tolua_isusertype(tolua_S,3,"cPickup",0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
@@ -9407,20 +9407,20 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectItem00(lua_State* tolua
#endif
{
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
- cPickup* a_Pickup = ((cPickup*) tolua_tousertype(tolua_S,2,0));
- cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
+ cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
+ cPickup* a_Pickup = ((cPickup*) tolua_tousertype(tolua_S,3,0));
#ifndef TOLUA_RELEASE
- if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnCollectItem'", NULL);
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnCollectPickup'", NULL);
#endif
{
- bool tolua_ret = (bool) self->cPlugin__OnCollectItem(a_Pickup,a_Player);
+ bool tolua_ret = (bool) self->cPlugin__OnCollectPickup(a_Player,a_Pickup);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
}
}
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
- tolua_error(tolua_S,"#ferror in function 'cPlugin__OnCollectItem'.",&tolua_err);
+ tolua_error(tolua_S,"#ferror in function 'cPlugin__OnCollectPickup'.",&tolua_err);
return 0;
#endif
}
@@ -10315,16 +10315,16 @@ public:
return ( bool ) cPlugin_NewLua:: OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
};
- bool OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- if (push_method("OnCollectItem", tolua_AllToLua_cPlugin_OnCollectItem00)) {
- tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
+ bool OnCollectPickup( cPlayer* a_Player, cPickup* a_Pickup) {
+ if (push_method("OnCollectPickup", tolua_AllToLua_cPlugin_OnCollectPickup00)) {
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
+ tolua_pushusertype(lua_state, (void*)a_Pickup, "cPickup");
ToluaBase::dbcall(lua_state, 3, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
- return ( bool ) cPlugin_NewLua:: OnCollectItem(a_Pickup,a_Player);
+ return ( bool ) cPlugin_NewLua:: OnCollectPickup(a_Player,a_Pickup);
};
};
bool OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
@@ -10522,8 +10522,8 @@ public:
bool cPlugin_NewLua__OnChunkGenerating( cWorld* a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk* a_pLuaChunk) {
return ( bool )cPlugin_NewLua::OnChunkGenerating(a_World,a_ChunkX,a_ChunkZ,a_pLuaChunk);
};
- bool cPlugin_NewLua__OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player) {
- return ( bool )cPlugin_NewLua::OnCollectItem(a_Pickup,a_Player);
+ bool cPlugin_NewLua__OnCollectPickup( cPlayer* a_Player, cPickup* a_Pickup) {
+ return ( bool )cPlugin_NewLua::OnCollectPickup(a_Player,a_Pickup);
};
bool cPlugin_NewLua__OnCraftingNoRecipe( const cPlayer* a_Player, const cCraftingGrid* a_Grid, cCraftingRecipe* a_Recipe) {
return ( bool )cPlugin_NewLua::OnCraftingNoRecipe(a_Player,a_Grid,a_Recipe);
@@ -21373,6 +21373,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_beginmodule(tolua_S,"cPluginManager");
tolua_constant(tolua_S,"HOOK_TICK",cPluginManager::HOOK_TICK);
tolua_constant(tolua_S,"HOOK_CHAT",cPluginManager::HOOK_CHAT);
+ tolua_constant(tolua_S,"HOOK_COLLECT_PICKUP",cPluginManager::HOOK_COLLECT_PICKUP);
tolua_constant(tolua_S,"HOOK_COLLECT_ITEM",cPluginManager::HOOK_COLLECT_ITEM);
tolua_constant(tolua_S,"HOOK_BLOCK_DIG",cPluginManager::HOOK_BLOCK_DIG);
tolua_constant(tolua_S,"HOOK_BLOCK_PLACE",cPluginManager::HOOK_BLOCK_PLACE);
@@ -21436,7 +21437,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"OnChat",tolua_AllToLua_cPlugin_OnChat00);
tolua_function(tolua_S,"OnChunkGenerated",tolua_AllToLua_cPlugin_OnChunkGenerated00);
tolua_function(tolua_S,"OnChunkGenerating",tolua_AllToLua_cPlugin_OnChunkGenerating00);
- tolua_function(tolua_S,"OnCollectItem",tolua_AllToLua_cPlugin_OnCollectItem00);
+ tolua_function(tolua_S,"OnCollectPickup",tolua_AllToLua_cPlugin_OnCollectPickup00);
tolua_function(tolua_S,"OnCraftingNoRecipe",tolua_AllToLua_cPlugin_OnCraftingNoRecipe00);
tolua_function(tolua_S,"OnDisconnect",tolua_AllToLua_cPlugin_OnDisconnect00);
tolua_function(tolua_S,"OnKilled",tolua_AllToLua_cPlugin_OnKilled00);
@@ -21477,7 +21478,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"cPlugin__OnChat",tolua_AllToLua_Lua__cPlugin_cPlugin__OnChat00);
tolua_function(tolua_S,"cPlugin__OnChunkGenerated",tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerated00);
tolua_function(tolua_S,"cPlugin__OnChunkGenerating",tolua_AllToLua_Lua__cPlugin_cPlugin__OnChunkGenerating00);
- tolua_function(tolua_S,"cPlugin__OnCollectItem",tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectItem00);
+ tolua_function(tolua_S,"cPlugin__OnCollectPickup",tolua_AllToLua_Lua__cPlugin_cPlugin__OnCollectPickup00);
tolua_function(tolua_S,"cPlugin__OnCraftingNoRecipe",tolua_AllToLua_Lua__cPlugin_cPlugin__OnCraftingNoRecipe00);
tolua_function(tolua_S,"cPlugin__OnDisconnect",tolua_AllToLua_Lua__cPlugin_cPlugin__OnDisconnect00);
tolua_function(tolua_S,"cPlugin__OnKilled",tolua_AllToLua_Lua__cPlugin_cPlugin__OnKilled00);
diff --git a/source/Bindings.h b/source/Bindings.h
index 32fdaa629..1119dd642 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 08/24/12 09:56:22.
+** Generated automatically by tolua++-1.0.92 on 08/24/12 10:55:13.
*/
/* Exported function */
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index e528edf24..2c97b5955 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -1930,6 +1930,22 @@ void cChunk::BroadcastSpawn(cEntity & a_Entity, const cClientHandle * a_Exclude)
+void cChunk::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ for (cClientHandleList::iterator itr = m_LoadedByClient.begin(); itr != m_LoadedByClient.end(); ++itr )
+ {
+ if (*itr == a_Exclude)
+ {
+ continue;
+ }
+ (*itr)->SendCollectPickup(a_Pickup, a_Player);
+ } // for itr - LoadedByClient[]
+}
+
+
+
+
+
void cChunk::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
// We can operate on entity pointers, we're inside the ChunkMap's CS lock which guards the list
diff --git a/source/cChunk.h b/source/cChunk.h
index 3f821e8ff..707ea5840 100644
--- a/source/cChunk.h
+++ b/source/cChunk.h
@@ -42,6 +42,7 @@ class cChestEntity;
class cFurnaceEntity;
class cBlockArea;
class cPawn;
+class cPickup;
typedef std::list<cClientHandle *> cClientHandleList;
typedef cItemCallback<cEntity> cEntityCallback;
@@ -188,6 +189,7 @@ public:
void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL);
void BroadcastSpawn (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);
+ void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
void SendBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, cClientHandle & a_Client);
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index b8e8b05c6..c5a770871 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -451,6 +451,22 @@ void cChunkMap::BroadcastSpawn(cEntity & a_Entity, const cClientHandle * a_Exclu
+void cChunkMap::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ cCSLock Lock(m_CSLayers);
+ cChunkPtr Chunk = GetChunkNoGen(a_Pickup.GetChunkX(), a_Pickup.GetChunkY(), a_Pickup.GetChunkZ());
+ if (Chunk == NULL)
+ {
+ return;
+ }
+ // It's perfectly legal to broadcast packets even to invalid chunks!
+ Chunk->BroadcastCollectPickup(a_Pickup, a_Player, a_Exclude);
+}
+
+
+
+
+
void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSLayers);
diff --git a/source/cChunkMap.h b/source/cChunkMap.h
index f2fc9685a..54b65a019 100644
--- a/source/cChunkMap.h
+++ b/source/cChunkMap.h
@@ -21,6 +21,7 @@ class cPlayer;
class cChestEntity;
class cFurnaceEntity;
class cPawn;
+class cPickup;
typedef std::list<cClientHandle *> cClientHandleList;
typedef cChunk * cChunkPtr;
@@ -77,6 +78,8 @@ public:
void BroadcastSpawn(cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
+
/// Broadcasts the block entity, if it is at the coords specified, to all clients except a_Exclude
void BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude);
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 5c63cce57..90672a1ec 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -46,6 +46,7 @@
#include "packets/cPacket_BlockDig.h"
#include "packets/cPacket_BlockPlace.h"
#include "packets/cPacket_Chat.h"
+#include "packets/cPacket_CollectItem.h"
#include "packets/cPacket_CreativeInventoryAction.h"
#include "packets/cPacket_DestroyEntity.h"
#include "packets/cPacket_Disconnect.h"
@@ -1895,6 +1896,18 @@ void cClientHandle::SendUpdateSign(
+void cClientHandle::SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player)
+{
+ cPacket_CollectItem ci;
+ ci.m_CollectedID = a_Pickup.GetUniqueID();
+ ci.m_CollectorID = a_Player.GetUniqueID();
+ Send(ci);
+}
+
+
+
+
+
void cClientHandle::CheckIfWorldDownloaded(void)
{
if (m_State != csDownloadingWorld)
diff --git a/source/cClientHandle.h b/source/cClientHandle.h
index ae2bea6c5..0dc0c2fd9 100644
--- a/source/cClientHandle.h
+++ b/source/cClientHandle.h
@@ -113,6 +113,7 @@ public:
void SendPickupSpawn(const cPickup & a_Pickup);
void SendSpawnMob (const cMonster & a_Mob);
void SendUpdateSign (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);
+ void SendCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player);
const AString & GetUsername(void) const; //tolua_export
diff --git a/source/cPickup.cpp b/source/cPickup.cpp
index dd0da9372..a9545e57d 100644
--- a/source/cPickup.cpp
+++ b/source/cPickup.cpp
@@ -17,8 +17,6 @@
#include "cRoot.h"
#include "cTracer.h"
-#include "packets/cPacket_CollectItem.h"
-
#include "Vector3d.h"
#include "Vector3f.h"
@@ -244,18 +242,25 @@ void cPickup::HandlePhysics(float a_Dt)
bool cPickup::CollectedBy( cPlayer* a_Dest )
{
- if(m_bCollected) return false; // It's already collected!
+ if (m_bCollected)
+ {
+ return false; // It's already collected!
+ }
+
// 800 is to long
- if(m_Timer < 500.f) return false; // Not old enough
+ if (m_Timer < 500.f)
+ {
+ return false; // Not old enough
+ }
- if( cRoot::Get()->GetPluginManager()->CallHook( cPluginManager::E_PLUGIN_COLLECT_ITEM, 2, this, a_Dest ) ) return false;
+ if (cRoot::Get()->GetPluginManager()->CallHookCollectPickup(a_Dest, *this))
+ {
+ return false;
+ }
- if( a_Dest->GetInventory().AddItem( *m_Item ) )
+ if (a_Dest->GetInventory().AddItem(*m_Item))
{
- cPacket_CollectItem CollectItem;
- CollectItem.m_CollectedID = m_UniqueID;
- CollectItem.m_CollectorID = a_Dest->GetUniqueID();
- cRoot::Get()->GetServer()->Broadcast( CollectItem );
+ m_World->BroadcastCollectPickup(*this, *a_Dest);
m_bCollected = true;
m_Timer = 0;
diff --git a/source/cPlugin.cpp b/source/cPlugin.cpp
index 2b3825d2a..4bdebc859 100644
--- a/source/cPlugin.cpp
+++ b/source/cPlugin.cpp
@@ -118,10 +118,10 @@ bool cPlugin::OnChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cL
-bool cPlugin::OnCollectItem(cPickup * a_Pickup, cPlayer * a_Player)
+bool cPlugin::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup)
{
- UNUSED(a_Pickup);
UNUSED(a_Player);
+ UNUSED(a_Pickup);
return false;
}
diff --git a/source/cPlugin.h b/source/cPlugin.h
index 5c8befdec..f040ba823 100644
--- a/source/cPlugin.h
+++ b/source/cPlugin.h
@@ -54,7 +54,7 @@ public:
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message);
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk);
- virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player );
+ virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup);
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason);
virtual bool OnKilled (cPawn * a_Killed, cEntity* a_Killer );
diff --git a/source/cPluginManager.cpp b/source/cPluginManager.cpp
index 041180818..788b5e429 100644
--- a/source/cPluginManager.cpp
+++ b/source/cPluginManager.cpp
@@ -198,22 +198,6 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
switch( a_Hook )
{
- case HOOK_COLLECT_ITEM:
- {
- if( a_NumArgs != 2 ) break;
- va_list argptr;
- va_start( argptr, a_NumArgs);
- cPickup* Pickup = va_arg(argptr, cPickup* );
- cPlayer* Player = va_arg(argptr, cPlayer* );
- va_end (argptr);
- for( PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr )
- {
- if( (*itr)->OnCollectItem( Pickup, Player ) )
- return true;
- }
- break;
- }
-
case HOOK_PLAYER_JOIN:
{
if( a_NumArgs != 1 ) break;
@@ -451,6 +435,27 @@ bool cPluginManager::CallHookChunkGenerating(cWorld * a_World, int a_ChunkX, int
+bool cPluginManager::CallHookCollectPickup(cPlayer * a_Player, cPickup & a_Pickup)
+{
+ HookMap::iterator Plugins = m_Hooks.find(HOOK_COLLECT_PICKUP);
+ if (Plugins == m_Hooks.end())
+ {
+ return false;
+ }
+ for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
+ {
+ if ((*itr)->OnCollectPickup(a_Player, &a_Pickup))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+
+
+
bool cPluginManager::CallHookPreCrafting(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_PRE_CRAFTING);
diff --git a/source/cPluginManager.h b/source/cPluginManager.h
index 7be7451a1..51d443945 100644
--- a/source/cPluginManager.h
+++ b/source/cPluginManager.h
@@ -22,6 +22,9 @@ class cPlayer;
class cCraftingGrid;
class cCraftingRecipe;
+// fwd: cPickup.h
+class cPickup;
+
@@ -38,7 +41,8 @@ public: //tolua_export
{
HOOK_TICK,
HOOK_CHAT,
- HOOK_COLLECT_ITEM,
+ HOOK_COLLECT_PICKUP,
+ HOOK_COLLECT_ITEM = HOOK_COLLECT_PICKUP, // OBSOLETE, use HOOK_COLLECT_PICKUP instead
HOOK_BLOCK_DIG,
HOOK_BLOCK_PLACE,
HOOK_DISCONNECT,
@@ -102,6 +106,7 @@ public: //tolua_export
bool CallHookBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
bool CallHookChat (cPlayer * a_Player, const AString & a_Message);
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_Chunk);
+ bool CallHookCollectPickup (cPlayer * a_Player, cPickup & a_Pickup);
bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookDisconnect (cPlayer * a_Player, const AString & a_Reason);
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
diff --git a/source/cPlugin_NewLua.cpp b/source/cPlugin_NewLua.cpp
index a80c8c987..7341a572b 100644
--- a/source/cPlugin_NewLua.cpp
+++ b/source/cPlugin_NewLua.cpp
@@ -159,20 +159,23 @@ void cPlugin_NewLua::Tick(float a_Dt)
-bool cPlugin_NewLua::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
+bool cPlugin_NewLua::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup)
{
- cCSLock Lock( m_CriticalSection );
- if( !PushFunction("OnCollectItem") )
+ cCSLock Lock(m_CriticalSection);
+ if (!PushFunction("OnCollectPickup"))
+ {
return false;
+ }
- tolua_pushusertype(m_LuaState, a_Pickup, "cPickup");
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
+ tolua_pushusertype(m_LuaState, a_Pickup, "cPickup");
- if( !CallFunction(2, 1, "OnCollectItem") )
+ if (!CallFunction(2, 1, "OnCollectPickup"))
+ {
return false;
+ }
- bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
- return bRetVal;
+ return (tolua_toboolean(m_LuaState, -1, 0) > 0);
}
diff --git a/source/cPlugin_NewLua.h b/source/cPlugin_NewLua.h
index 7ae38c1e5..ed40bf458 100644
--- a/source/cPlugin_NewLua.h
+++ b/source/cPlugin_NewLua.h
@@ -31,7 +31,7 @@ public: //tolua_export
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
- virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
+ virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup) override;
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
diff --git a/source/cPlugin_Squirrel.cpp b/source/cPlugin_Squirrel.cpp
index f0152f240..bfd5a7037 100644
--- a/source/cPlugin_Squirrel.cpp
+++ b/source/cPlugin_Squirrel.cpp
@@ -99,13 +99,16 @@ void cPlugin_Squirrel::Tick(float a_Dt)
-bool cPlugin_Squirrel::OnCollectItem( cPickup* a_Pickup, cPlayer* a_Player )
+bool cPlugin_Squirrel::OnCollectPickup(cPlayer * a_Player, cPickup * a_Pickup)
{
- cCSLock Lock( m_CriticalSection );
+ cCSLock Lock(m_CriticalSection);
- if(!m_Plugin->HasFunction("OnCollectItem")) return false;
+ if (!m_Plugin->HasFunction("OnCollectPickup"))
+ {
+ return false;
+ }
- return m_Plugin->GetFunction("OnCollectItem").Evaluate<bool>(a_Pickup, a_Player);
+ return m_Plugin->GetFunction("OnCollectPickup").Evaluate<bool>(a_Player, a_Pickup);
}
diff --git a/source/cPlugin_Squirrel.h b/source/cPlugin_Squirrel.h
index 631304a32..802faa76f 100644
--- a/source/cPlugin_Squirrel.h
+++ b/source/cPlugin_Squirrel.h
@@ -1,9 +1,16 @@
+
#pragma once
+
#include "cPlugin.h"
#include <sqrat.h>
#include "squirrelbindings/SquirrelObject.h"
-class cPlugin_Squirrel : public cPlugin
+
+
+
+
+class cPlugin_Squirrel :
+ public cPlugin
{
public:
cPlugin_Squirrel(const char* a_PluginName);
@@ -20,7 +27,7 @@ public:
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
- virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
+ virtual bool OnCollectPickup (cPlayer * a_Player, cPickup * a_Pickup) override;
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (cPlayer * a_Player, const AString & a_Reason) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
@@ -39,4 +46,8 @@ protected:
const char * m_PluginName;
cCriticalSection m_CriticalSection;
SquirrelObject *m_Plugin;
-}; \ No newline at end of file
+};
+
+
+
+
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 691d41889..232e3a44f 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -1399,6 +1399,15 @@ void cWorld::BroadcastSpawn(cEntity & a_Entity, const cClientHandle * a_Exclude)
+void cWorld::BroadcastCollectPickup(const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude)
+{
+ m_ChunkMap->BroadcastCollectPickup(a_Pickup, a_Player, a_Exclude);
+}
+
+
+
+
+
void cWorld::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude)
{
m_ChunkMap->BroadcastBlockEntity(a_BlockX, a_BlockY, a_BlockZ, a_Exclude);
diff --git a/source/cWorld.h b/source/cWorld.h
index 16d96eabf..4d474df2c 100644
--- a/source/cWorld.h
+++ b/source/cWorld.h
@@ -91,6 +91,7 @@ public:
void BroadcastEntityStatus (const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude = NULL);
void BroadcastMetadata (const cPawn & a_Pawn, const cClientHandle * a_Exclude = NULL);
void BroadcastSpawn (cEntity & a_Entity, const cClientHandle * a_Exclude = NULL);
+ void BroadcastCollectPickup (const cPickup & a_Pickup, const cPlayer & a_Player, const cClientHandle * a_Exclude = NULL);
/// If there is a block entity at the specified coods, sends it to all clients except a_Exclude
void BroadcastBlockEntity (int a_BlockX, int a_BlockY, int a_BlockZ, const cClientHandle * a_Exclude = NULL);