Merge branch 'howaner/GlobalFixes'.
This commit is contained in:
commit
173fd0dd92
@ -1826,6 +1826,7 @@ cPluginManager.AddHook(cPluginManager.HOOK_CHAT, OnChatMessage);
|
|||||||
},
|
},
|
||||||
Constants =
|
Constants =
|
||||||
{
|
{
|
||||||
|
HOOK_BLOCK_SPREAD = { Notes = "Called when a block spreads based on world conditions" },
|
||||||
HOOK_BLOCK_TO_PICKUPS = { Notes = "Called when a block has been dug and is being converted to pickups. The server has provided the default pickups and the plugins may modify them." },
|
HOOK_BLOCK_TO_PICKUPS = { Notes = "Called when a block has been dug and is being converted to pickups. The server has provided the default pickups and the plugins may modify them." },
|
||||||
HOOK_CHAT = { Notes = "Called when a client sends a chat message that is not a command. The plugin may modify the chat message" },
|
HOOK_CHAT = { Notes = "Called when a client sends a chat message that is not a command. The plugin may modify the chat message" },
|
||||||
HOOK_CHUNK_AVAILABLE = { Notes = "Called when a chunk is loaded or generated and becomes available in the {{cWorld|world}}." },
|
HOOK_CHUNK_AVAILABLE = { Notes = "Called when a chunk is loaded or generated and becomes available in the {{cWorld|world}}." },
|
||||||
@ -2767,6 +2768,14 @@ end
|
|||||||
data provided with the explosions, such as the exploding {{cCreeper|creeper}} entity or the
|
data provided with the explosions, such as the exploding {{cCreeper|creeper}} entity or the
|
||||||
{{Vector3i|coords}} of the exploding bed.
|
{{Vector3i|coords}} of the exploding bed.
|
||||||
]],
|
]],
|
||||||
|
},
|
||||||
|
SpreadSource =
|
||||||
|
{
|
||||||
|
Include = "^ss.*",
|
||||||
|
TextBefore = [[
|
||||||
|
These constants are used to differentiate the various sources of spreads, such as grass growing.
|
||||||
|
They are used in the {{OnBlockSpread|HOOK_BLOCK_SPREAD}} hook.
|
||||||
|
]],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}, -- Globals
|
}, -- Globals
|
||||||
|
40
MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua
Normal file
40
MCServer/Plugins/APIDump/Hooks/OnBlockSpread.lua
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
return
|
||||||
|
{
|
||||||
|
HOOK_BLOCK_SPREAD =
|
||||||
|
{
|
||||||
|
CalledWhen = "Called when a block spreads based on world conditions",
|
||||||
|
DefaultFnName = "OnBlockSpread", -- also used as pagename
|
||||||
|
Desc = [[
|
||||||
|
This hook is called when a block spreads.</p>
|
||||||
|
<p>
|
||||||
|
The spread carries with it the type of its source - whether it's a block spreads.
|
||||||
|
It also carries the identification of the actual source. The exact type of the identification
|
||||||
|
depends on the source kind:
|
||||||
|
<table>
|
||||||
|
<tr><th>Source</th><th>Notes</th></tr>
|
||||||
|
<tr><td>ssFireSpread</td><td>Fire spreading</td></tr>
|
||||||
|
<tr><td>ssGrassSpread</td><td>Grass spreading</td></tr>
|
||||||
|
<tr><td>ssMushroomSpread</td><td>Mushroom spreading</td></tr>
|
||||||
|
<tr><td>ssMycelSpread</td><td>Mycel spreading</td></tr>
|
||||||
|
<tr><td>ssVineSpread</td><td>Vine spreading</td></tr>
|
||||||
|
</table></p>
|
||||||
|
]],
|
||||||
|
Params =
|
||||||
|
{
|
||||||
|
{ Name = "World", Type = "{{cWorld}}", Notes = "The world in which the block resides" },
|
||||||
|
{ Name = "BlockX", Type = "number", Notes = "X-coord of the block" },
|
||||||
|
{ Name = "BlockY", Type = "number", Notes = "Y-coord of the block" },
|
||||||
|
{ Name = "BlockZ", Type = "number", Notes = "Z-coord of the block" },
|
||||||
|
{ Name = "Source", Type = "eSpreadSource", Notes = "Source of the spread. See the table above." },
|
||||||
|
},
|
||||||
|
Returns = [[
|
||||||
|
If the function returns false or no value, the next plugin's callback is called, and finally
|
||||||
|
MCServer will process the spread. If the function
|
||||||
|
returns true, no other callback is called for this event and the spread will not occur.
|
||||||
|
]],
|
||||||
|
}, -- HOOK_BLOCK_SPREAD
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -46,6 +46,7 @@ public:
|
|||||||
* On all these functions, return true if you want to override default behavior and not call other plugins on that callback.
|
* On all these functions, return true if you want to override default behavior and not call other plugins on that callback.
|
||||||
* You can also return false, so default behavior is used.
|
* You can also return false, so default behavior is used.
|
||||||
**/
|
**/
|
||||||
|
virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) = 0;
|
||||||
virtual bool 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) = 0;
|
virtual bool 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) = 0;
|
||||||
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) = 0;
|
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) = 0;
|
||||||
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0;
|
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) = 0;
|
||||||
|
@ -195,6 +195,26 @@ void cPluginLua::Tick(float a_Dt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPluginLua::OnBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
|
||||||
|
{
|
||||||
|
cCSLock Lock(m_CriticalSection);
|
||||||
|
bool res = false;
|
||||||
|
cLuaRefs & Refs = m_HookMap[cPluginManager::HOOK_BLOCK_SPREAD];
|
||||||
|
for (cLuaRefs::iterator itr = Refs.begin(), end = Refs.end(); itr != end; ++itr)
|
||||||
|
{
|
||||||
|
m_LuaState.Call((int)(**itr), a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source, cLuaState::Return, res);
|
||||||
|
if (res)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginLua::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)
|
bool cPluginLua::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);
|
cCSLock Lock(m_CriticalSection);
|
||||||
@ -1430,6 +1450,7 @@ const char * cPluginLua::GetHookFnName(int a_HookType)
|
|||||||
{
|
{
|
||||||
switch (a_HookType)
|
switch (a_HookType)
|
||||||
{
|
{
|
||||||
|
case cPluginManager::HOOK_BLOCK_SPREAD: return "OnBlockSpread";
|
||||||
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
|
case cPluginManager::HOOK_BLOCK_TO_PICKUPS: return "OnBlockToPickups";
|
||||||
case cPluginManager::HOOK_CHAT: return "OnChat";
|
case cPluginManager::HOOK_CHAT: return "OnChat";
|
||||||
case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable";
|
case cPluginManager::HOOK_CHUNK_AVAILABLE: return "OnChunkAvailable";
|
||||||
|
@ -69,6 +69,7 @@ public:
|
|||||||
|
|
||||||
virtual void Tick(float a_Dt) override;
|
virtual void Tick(float a_Dt) override;
|
||||||
|
|
||||||
|
virtual bool OnBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source) override;
|
||||||
virtual bool 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) override;
|
virtual bool 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) override;
|
||||||
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override;
|
virtual bool OnChat (cPlayer * a_Player, AString & a_Message) override;
|
||||||
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
|
virtual bool OnChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
|
||||||
|
@ -205,6 +205,27 @@ void cPluginManager::Tick(float a_Dt)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
bool cPluginManager::CallHookBlockSpread(cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source)
|
||||||
|
{
|
||||||
|
HookMap::iterator Plugins = m_Hooks.find(HOOK_BLOCK_SPREAD);
|
||||||
|
if (Plugins == m_Hooks.end())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
|
||||||
|
{
|
||||||
|
if ((*itr)->OnBlockSpread(a_World, a_BlockX, a_BlockY, a_BlockZ, a_Source))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cPluginManager::CallHookBlockToPickups(
|
bool cPluginManager::CallHookBlockToPickups(
|
||||||
cWorld * a_World, cEntity * a_Digger,
|
cWorld * a_World, cEntity * a_Digger,
|
||||||
int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
|
||||||
|
@ -58,6 +58,7 @@ public: // tolua_export
|
|||||||
// tolua_begin
|
// tolua_begin
|
||||||
enum PluginHook
|
enum PluginHook
|
||||||
{
|
{
|
||||||
|
HOOK_BLOCK_SPREAD,
|
||||||
HOOK_BLOCK_TO_PICKUPS,
|
HOOK_BLOCK_TO_PICKUPS,
|
||||||
HOOK_CHAT,
|
HOOK_CHAT,
|
||||||
HOOK_CHUNK_AVAILABLE,
|
HOOK_CHUNK_AVAILABLE,
|
||||||
@ -154,6 +155,7 @@ public: // 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
|
// Calls for individual hooks. Each returns false if the action is to continue or true if the plugin wants to abort
|
||||||
|
bool CallHookBlockSpread (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, eSpreadSource a_Source);
|
||||||
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 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 CallHookChat (cPlayer * a_Player, AString & a_Message);
|
||||||
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
bool CallHookChunkAvailable (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
|
||||||
|
@ -866,6 +866,19 @@ enum eShrapnelLevel
|
|||||||
slAll
|
slAll
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
enum eSpreadSource
|
||||||
|
{
|
||||||
|
ssFireSpread,
|
||||||
|
ssGrassSpread,
|
||||||
|
ssMushroomSpread,
|
||||||
|
ssMycelSpread,
|
||||||
|
ssVineSpread,
|
||||||
|
} ;
|
||||||
|
|
||||||
// tolua_end
|
// tolua_end
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +78,12 @@ public:
|
|||||||
NIBBLETYPE AboveMeta;
|
NIBBLETYPE AboveMeta;
|
||||||
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
|
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
|
||||||
if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest))
|
if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest))
|
||||||
|
{
|
||||||
|
if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, BlockX * cChunkDef::Width, BlockY, BlockZ * cChunkDef::Width, ssGrassSpread))
|
||||||
{
|
{
|
||||||
Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
|
Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} // for i - repeat twice
|
} // for i - repeat twice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: Add Mushroom Spread
|
||||||
|
|
||||||
|
|
||||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
{
|
{
|
||||||
// Reset meta to 0
|
// Reset meta to 0
|
||||||
|
@ -16,6 +16,8 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Add Mycel Spread
|
||||||
|
|
||||||
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
|
||||||
{
|
{
|
||||||
a_Pickups.push_back(cItem(E_BLOCK_DIRT, 1, 0));
|
a_Pickups.push_back(cItem(E_BLOCK_DIRT, 1, 0));
|
||||||
|
@ -174,10 +174,13 @@ public:
|
|||||||
BLOCKTYPE Block;
|
BLOCKTYPE Block;
|
||||||
a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block);
|
a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY - 1, a_RelZ, Block);
|
||||||
if (Block == E_BLOCK_AIR)
|
if (Block == E_BLOCK_AIR)
|
||||||
|
{
|
||||||
|
if (!cRoot::Get()->GetPluginManager()->CallHookBlockSpread((cWorld*) &a_WorldInterface, a_RelX * cChunkDef::Width, a_RelY - 1, a_RelZ * cChunkDef::Width, ssVineSpread))
|
||||||
{
|
{
|
||||||
a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
|
a_Chunk.UnboundedRelSetBlock(a_RelX, a_RelY - 1, a_RelZ, E_BLOCK_VINES, a_Chunk.GetMeta(a_RelX, a_RelY, a_RelZ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
|
virtual NIBBLETYPE MetaRotateCCW(NIBBLETYPE a_Meta) override
|
||||||
{
|
{
|
||||||
|
@ -21,7 +21,6 @@ declared in this file as well; the Gallery server exports areas in this format.
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fwd:
|
// fwd:
|
||||||
class cChunkDesc;
|
class cChunkDesc;
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "../BlockID.h"
|
#include "../BlockID.h"
|
||||||
#include "../Defines.h"
|
#include "../Defines.h"
|
||||||
#include "../Chunk.h"
|
#include "../Chunk.h"
|
||||||
|
#include "Root.h"
|
||||||
|
#include "PluginManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -315,9 +317,15 @@ void cFireSimulator::TrySpreadFire(cChunk * a_Chunk, int a_RelX, int a_RelY, int
|
|||||||
*/
|
*/
|
||||||
if (CanStartFireInBlock(a_Chunk, x, y, z))
|
if (CanStartFireInBlock(a_Chunk, x, y, z))
|
||||||
{
|
{
|
||||||
FLOG("FS: Starting new fire at {%d, %d, %d}.",
|
int a_PosX = x + a_Chunk->GetPosX() * cChunkDef::Width;
|
||||||
x + a_Chunk->GetPosX() * cChunkDef::Width, y, z + a_Chunk->GetPosZ() * cChunkDef::Width
|
int a_PosZ = z + a_Chunk->GetPosZ() * cChunkDef::Width;
|
||||||
);
|
|
||||||
|
if (cRoot::Get()->GetPluginManager()->CallHookBlockSpread(&m_World, a_PosX, y, a_PosZ, ssFireSpread))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
FLOG("FS: Starting new fire at {%d, %d, %d}.", a_PosX, y, a_PosZ);
|
||||||
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
|
a_Chunk->UnboundedRelSetBlock(x, y, z, E_BLOCK_FIRE, 0);
|
||||||
}
|
}
|
||||||
} // for y
|
} // for y
|
||||||
|
Loading…
Reference in New Issue
Block a user