|
8 | 8 | #include "ll/api/memory/Memory.h" |
9 | 9 | #include "ll/api/service/Bedrock.h" |
10 | 10 | #include "mc/deps/ecs/WeakEntityRef.h" |
| 11 | +#include "mc/network/ServerPlayerBlockUseHandler.h" |
11 | 12 | #include "mc/server/ServerPlayer.h" |
12 | 13 | #include "mc/server/module/VanillaServerGameplayEventListener.h" |
13 | 14 | #include "mc/world/ContainerID.h" |
@@ -224,30 +225,30 @@ LL_TYPE_INSTANCE_HOOK( |
224 | 225 | IF_LISTENED_END(EVENT_TYPES::onInventoryChange); |
225 | 226 | origin(container, slot, oldItem, newItem, forceBalanced); |
226 | 227 | } |
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 | +} |
251 | 252 |
|
252 | 253 | LL_TYPE_INSTANCE_HOOK( |
253 | 254 | UseFrameHook1, |
@@ -673,9 +674,7 @@ void CloseContainerEvent() { |
673 | 674 | CloseContainerHook2::hook(); |
674 | 675 | } |
675 | 676 | void ChangeSlotEvent() { ChangeSlotHook::hook(); } |
676 | | -void AttackBlockEvent() { |
677 | | - // AttackBlockHook::hook(); |
678 | | -} |
| 677 | +void AttackBlockEvent() { AttackBlockHook::hook(); } |
679 | 678 | void UseFrameEvent() { |
680 | 679 | UseFrameHook1::hook(); |
681 | 680 | UseFrameHook2::hook(); |
|
0 commit comments