Skip to content

Commit 3faae69

Browse files
authored
feat: fix AttackBlock event
1 parent 3eb9a2f commit 3faae69

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/lse/events/PlayerEvents.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "ll/api/memory/Memory.h"
99
#include "ll/api/service/Bedrock.h"
1010
#include "mc/deps/ecs/WeakEntityRef.h"
11+
#include "mc/network/ServerPlayerBlockUseHandler.h"
1112
#include "mc/server/ServerPlayer.h"
1213
#include "mc/server/module/VanillaServerGameplayEventListener.h"
1314
#include "mc/world/ContainerID.h"
@@ -224,30 +225,30 @@ LL_TYPE_INSTANCE_HOOK(
224225
IF_LISTENED_END(EVENT_TYPES::onInventoryChange);
225226
origin(container, slot, oldItem, newItem, forceBalanced);
226227
}
227-
// FIXME: this hook is not working
228-
// LL_TYPE_INSTANCE_HOOK(
229-
// AttackBlockHook,
230-
// HookPriority::Normal,
231-
// Block,
232-
// &Block::attack,
233-
// bool,
234-
// Player* player,
235-
// BlockPos const& pos
236-
//) {
237-
// IF_LISTENED(EVENT_TYPES::onAttackBlock) {
238-
// ItemStack const& item = player->getSelectedItem();
239-
// if (!CallEvent(
240-
// EVENT_TYPES::onAttackBlock,
241-
// PlayerClass::newPlayer(player),
242-
// BlockClass::newBlock(pos, player->getDimensionId()),
243-
// !item.isNull() ? ItemClass::newItem(&const_cast<ItemStack&>(item)) : Local<Value>()
244-
// )) {
245-
// return false;
246-
// }
247-
// }
248-
// IF_LISTENED_END(EVENT_TYPES::onAttackBlock);
249-
// return origin(player, pos);
250-
// }
228+
229+
LL_STATIC_HOOK(
230+
AttackBlockHook,
231+
HookPriority::Normal,
232+
&ServerPlayerBlockUseHandler::onStartDestroyBlock,
233+
void,
234+
ServerPlayer& player,
235+
const BlockPos& pos,
236+
int face
237+
) {
238+
IF_LISTENED(EVENT_TYPES::onAttackBlock) {
239+
ItemStack const& item = player.getSelectedItem();
240+
if (!CallEvent(
241+
EVENT_TYPES::onAttackBlock,
242+
PlayerClass::newPlayer(&player),
243+
BlockClass::newBlock(pos, player.getDimensionId()),
244+
!item.isNull() ? ItemClass::newItem(&const_cast<ItemStack&>(item)) : Local<Value>()
245+
)) {
246+
return;
247+
}
248+
}
249+
IF_LISTENED_END(EVENT_TYPES::onAttackBlock);
250+
return origin(player, pos, face);
251+
}
251252

252253
LL_TYPE_INSTANCE_HOOK(
253254
UseFrameHook1,
@@ -673,9 +674,7 @@ void CloseContainerEvent() {
673674
CloseContainerHook2::hook();
674675
}
675676
void ChangeSlotEvent() { ChangeSlotHook::hook(); }
676-
void AttackBlockEvent() {
677-
// AttackBlockHook::hook();
678-
}
677+
void AttackBlockEvent() { AttackBlockHook::hook(); }
679678
void UseFrameEvent() {
680679
UseFrameHook1::hook();
681680
UseFrameHook2::hook();

0 commit comments

Comments
 (0)