1
0

Implement Dropspenser Hook (#4903)

* Implement Dropspenser Hook

Implemented a hook for dropspensing.
HOOK_DROPSPENSE

When plugin callback returns true then dropspense is cancelled

* Update src/Bindings/PluginManager.h

Co-authored-by: peterbell10 <peterbell10@live.co.uk>

* Create OnDropSpense.lua

* Fix indent

* Forgot include

Forgot to include the plugin manager. Although now im confused why it was working on my end without including the plugin manager

* Update plugins.lua with dropspense

* fix typos

* haha notepad++ go brr

Co-authored-by: peterbell10 <peterbell10@live.co.uk>
This commit is contained in:
KrystilizeNevaDies
2020-09-22 01:31:45 +10:00
committed by GitHub
parent 0a1bf06c6f
commit 23bca00831
9 changed files with 69 additions and 4 deletions

View File

@@ -66,6 +66,7 @@ public:
virtual bool OnHandshake (cClientHandle & a_Client, const AString & a_Username) = 0;
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) = 0;
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) = 0;
virtual bool OnDropSpense (cWorld & a_World, cDropSpenserEntity & a_DropSpenser, int a_SlotNum) = 0;
virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) = 0;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) = 0;
virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) = 0;

View File

@@ -523,6 +523,15 @@ bool cPluginLua::OnHopperPushingItem(cWorld & a_World, cHopperEntity & a_Hopper,
bool cPluginLua::OnDropSpense(cWorld & a_World, cDropSpenserEntity & a_DropSpenser, int a_SlotNum)
{
return CallSimpleHooks(cPluginManager::HOOK_DROPSPENSE, &a_World, &a_DropSpenser, a_SlotNum);
}
bool cPluginLua::OnKilled(cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage)
{
cOperation op(*this);

View File

@@ -87,6 +87,7 @@ public:
virtual bool OnHandshake (cClientHandle & a_Client, const AString & a_Username) override;
virtual bool OnHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum) override;
virtual bool OnHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum) override;
virtual bool OnDropSpense (cWorld & a_World, cDropSpenserEntity & a_DropSpenser, int a_SlotNum) override;
virtual bool OnKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage) override;
virtual bool OnKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI) override;
virtual bool OnLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username) override;

View File

@@ -613,6 +613,19 @@ bool cPluginManager::CallHookHopperPushingItem(cWorld & a_World, cHopperEntity &
bool cPluginManager::CallHookDropSpense(cWorld & a_World, cDropSpenserEntity & a_DropSpenser, int a_SlotNum)
{
return GenericCallHook(HOOK_DROPSPENSE, [&](cPlugin * a_Plugin)
{
return a_Plugin->OnDropSpense(a_World, a_DropSpenser, a_SlotNum);
}
);
}
bool cPluginManager::CallHookKilled(cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage)
{
return GenericCallHook(HOOK_KILLED, [&](cPlugin * a_Plugin)

View File

@@ -18,6 +18,7 @@ class cClientHandle;
class cCommandOutputCallback;
class cCraftingGrid;
class cCraftingRecipe;
class cDropSpenserEntity;
class cEntity;
class cHopperEntity;
class cItems;
@@ -101,6 +102,7 @@ public:
HOOK_HANDSHAKE,
HOOK_HOPPER_PULLING_ITEM,
HOOK_HOPPER_PUSHING_ITEM,
HOOK_DROPSPENSE,
HOOK_KILLED,
HOOK_KILLING,
HOOK_LOGIN,
@@ -249,7 +251,8 @@ public:
bool CallHookHandshake (cClientHandle & a_ClientHandle, const AString & a_Username);
bool CallHookHopperPullingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_DstSlotNum, cBlockEntityWithItems & a_SrcEntity, int a_SrcSlotNum);
bool CallHookHopperPushingItem (cWorld & a_World, cHopperEntity & a_Hopper, int a_SrcSlotNum, cBlockEntityWithItems & a_DstEntity, int a_DstSlotNum);
bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage);
bool CallHookDropSpense (cWorld & a_World, cDropSpenserEntity & a_DropSpenser, int a_SlotNum);
bool CallHookKilled (cEntity & a_Victim, TakeDamageInfo & a_TDI, AString & a_DeathMessage);
bool CallHookKilling (cEntity & a_Victim, cEntity * a_Killer, TakeDamageInfo & a_TDI);
bool CallHookLogin (cClientHandle & a_Client, UInt32 a_ProtocolVersion, const AString & a_Username);
bool CallHookLoginForge (cClientHandle & a_Client, AStringMap & a_Mods);
@@ -457,4 +460,3 @@ private:

View File

@@ -6,6 +6,7 @@
#include "Globals.h"
#include "DropSpenserEntity.h"
#include "../Bindings/PluginManager.h"
#include "../EffectID.h"
#include "../Entities/Player.h"
#include "../Chunk.h"
@@ -80,8 +81,16 @@ void cDropSpenserEntity::DropSpense(cChunk & a_Chunk)
int RandomSlot = m_World->GetTickRandomNumber(SlotsCnt - 1);
int SpenseSlot = OccupiedSlots[RandomSlot];
if (cPluginManager::Get()->CallHookDropSpense(*m_World, *this, SpenseSlot))
{
// Plugin disagrees with the move
return;
}
// DropSpense the item, using the specialized behavior in the subclasses:
DropSpenseFromSlot(a_Chunk, OccupiedSlots[RandomSlot]);
DropSpenseFromSlot(a_Chunk, SpenseSlot);
// Broadcast a smoke and click effects:
NIBBLETYPE Meta = a_Chunk.GetMeta(GetRelPos());

View File

@@ -95,7 +95,7 @@ bool cHopperEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cHopperEntity::SendTo(cClientHandle & a_Client)
{
// The hopper entity doesn't need anything sent to the client when it's created / gets in the viewdistance
// All the actual handling is in the cWindow UI code that gets called when the hopper is rclked
// All the actual handling is in the cWindow UI code that gets called when the hopper is right-clicked
UNUSED(a_Client);
}