5353#include " mc/world/phys/HitResult.h"
5454
5555namespace lse ::events::player {
56- LL_TYPE_INSTANCE_HOOK (
57- StartDestroyHook,
58- HookPriority::Normal,
59- BlockEventCoordinator,
60- &BlockEventCoordinator::sendBlockDestructionStarted,
61- void ,
62- ::Player& player,
63- const ::BlockPos& blockPos,
64- const ::Block& hitBlock,
65- uchar face
66- ) {
67- IF_LISTENED (EVENT_TYPES::onStartDestroyBlock) {
68- if (!CallEvent (
69- EVENT_TYPES::onStartDestroyBlock,
70- PlayerClass::newPlayer (&player),
71- BlockClass::newBlock (hitBlock, blockPos, player.getDimensionId ())
72- )) {
73- return ;
74- }
75- }
76- IF_LISTENED_END (EVENT_TYPES::onStartDestroyBlock)
77- origin (player, blockPos, hitBlock, face);
78- }
79-
8056LL_TYPE_INSTANCE_HOOK (
8157 DropItemHook1,
8258 HookPriority::Normal,
@@ -227,14 +203,15 @@ LL_TYPE_INSTANCE_HOOK(
227203}
228204
229205LL_STATIC_HOOK (
230- AttackBlockHook ,
206+ StartDestroyBlockHook ,
231207 HookPriority::Normal,
232208 &ServerPlayerBlockUseHandler::onStartDestroyBlock,
233209 void ,
234210 ServerPlayer& player,
235211 const BlockPos& pos,
236212 int face
237213) {
214+ bool isCancelled = false ;
238215 IF_LISTENED (EVENT_TYPES::onAttackBlock) {
239216 ItemStack const & item = player.getSelectedItem ();
240217 if (!CallEvent (
@@ -243,10 +220,23 @@ LL_STATIC_HOOK(
243220 BlockClass::newBlock (pos, player.getDimensionId ()),
244221 !item.isNull () ? ItemClass::newItem (&const_cast <ItemStack&>(item)) : Local<Value>()
245222 )) {
246- return ;
223+ isCancelled = true ;
247224 }
248225 }
249226 IF_LISTENED_END (EVENT_TYPES::onAttackBlock);
227+ IF_LISTENED (EVENT_TYPES::onStartDestroyBlock) {
228+ if (!CallEvent (
229+ EVENT_TYPES::onStartDestroyBlock,
230+ PlayerClass::newPlayer (&player),
231+ BlockClass::newBlock (pos, player.getDimensionId ())
232+ )) {
233+ isCancelled = true ;
234+ }
235+ }
236+ IF_LISTENED_END (EVENT_TYPES::onStartDestroyBlock)
237+ if (isCancelled) {
238+ return ;
239+ }
250240 return origin (player, pos, face);
251241}
252242
@@ -663,7 +653,7 @@ LL_TYPE_INSTANCE_HOOK(
663653 origin (effect);
664654}
665655
666- void StartDestroyBlock () { StartDestroyHook ::hook (); }
656+ void StartDestroyBlock () { StartDestroyBlockHook ::hook (); }
667657void DropItem () {
668658 DropItemHook1::hook ();
669659 DropItemHook2::hook ();
@@ -674,7 +664,7 @@ void CloseContainerEvent() {
674664 CloseContainerHook2::hook ();
675665}
676666void ChangeSlotEvent () { ChangeSlotHook::hook (); }
677- void AttackBlockEvent () { AttackBlockHook ::hook (); }
667+ void AttackBlockEvent () { StartDestroyBlockHook ::hook (); }
678668void UseFrameEvent () {
679669 UseFrameHook1::hook ();
680670 UseFrameHook2::hook ();
0 commit comments