|
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" |
|
33 | 34 | #include "mc/world/item/BucketItem.h" |
34 | 35 | #include "mc/world/item/ItemInstance.h" |
35 | 36 | #include "mc/world/item/ItemStack.h" |
| 37 | +#include "mc/world/item/PotionItem.h" |
36 | 38 | #include "mc/world/level/BedrockSpawner.h" |
37 | 39 | #include "mc/world/level/BlockSource.h" |
38 | 40 | #include "mc/world/level/ChangeDimensionRequest.h" |
@@ -224,29 +226,29 @@ LL_TYPE_INSTANCE_HOOK( |
224 | 226 | origin(container, slot, oldItem, newItem, forceBalanced); |
225 | 227 | } |
226 | 228 |
|
227 | | -// LL_TYPE_INSTANCE_HOOK( |
228 | | -// AttackBlockHook, |
229 | | -// HookPriority::Normal, |
230 | | -// Block, |
231 | | -// &Block::attack, |
232 | | -// bool, |
233 | | -// Player* player, |
234 | | -// BlockPos const& pos |
235 | | -//) { |
236 | | -// IF_LISTENED(EVENT_TYPES::onAttackBlock) { |
237 | | -// ItemStack const& item = player->getSelectedItem(); |
238 | | -// if (!CallEvent( |
239 | | -// EVENT_TYPES::onAttackBlock, |
240 | | -// PlayerClass::newPlayer(player), |
241 | | -// BlockClass::newBlock(pos, player->getDimensionId()), |
242 | | -// !item.isNull() ? ItemClass::newItem(&const_cast<ItemStack&>(item)) : Local<Value>() |
243 | | -// )) { |
244 | | -// return false; |
245 | | -// } |
246 | | -// } |
247 | | -// IF_LISTENED_END(EVENT_TYPES::onAttackBlock); |
248 | | -// return origin(player, pos); |
249 | | -// } |
| 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 | +} |
250 | 252 |
|
251 | 253 | LL_TYPE_INSTANCE_HOOK( |
252 | 254 | UseFrameHook1, |
@@ -306,26 +308,42 @@ LL_TYPE_INSTANCE_HOOK(EatHook1, HookPriority::Normal, Player, &Player::eat, void |
306 | 308 | IF_LISTENED_END(EVENT_TYPES::onAte); |
307 | 309 | origin(instance); |
308 | 310 | } |
309 | | - |
310 | | -// LL_TYPE_INSTANCE_HOOK( |
311 | | -// EatHook2, |
312 | | -// HookPriority::Normal, |
313 | | -// ItemStack, |
314 | | -// &ItemStack::useTimeDepleted, |
315 | | -// ::ItemUseMethod, |
316 | | -// Level* level, |
317 | | -// Player* player |
318 | | -//) { |
319 | | -// IF_LISTENED(EVENT_TYPES::onAte) { |
320 | | -// if (isPotionItem() || getTypeName() == "minecraft:milk_bucket") { |
321 | | -// if (!CallEvent(EVENT_TYPES::onAte, PlayerClass::newPlayer(player), ItemClass::newItem(this))) { |
322 | | -// return ItemUseMethod::Unknown; |
323 | | -// } |
324 | | -// } |
325 | | -// } |
326 | | -// IF_LISTENED_END(EVENT_TYPES::onAte); |
327 | | -// return origin(level, player); |
328 | | -// } |
| 311 | +LL_TYPE_INSTANCE_HOOK( |
| 312 | + EatHook2, |
| 313 | + HookPriority::Normal, |
| 314 | + PotionItem, |
| 315 | + &PotionItem::$useTimeDepleted, |
| 316 | + ::ItemUseMethod, |
| 317 | + ::ItemStack& inoutInstance, |
| 318 | + Level* level, |
| 319 | + Player* player |
| 320 | +) { |
| 321 | + IF_LISTENED(EVENT_TYPES::onAte) { |
| 322 | + if (!CallEvent(EVENT_TYPES::onAte, PlayerClass::newPlayer(player), ItemClass::newItem(&inoutInstance))) { |
| 323 | + return ItemUseMethod::Unknown; |
| 324 | + } |
| 325 | + } |
| 326 | + IF_LISTENED_END(EVENT_TYPES::onAte); |
| 327 | + return origin(inoutInstance, level, player); |
| 328 | +} |
| 329 | +LL_TYPE_INSTANCE_HOOK( |
| 330 | + EatHook3, |
| 331 | + HookPriority::Normal, |
| 332 | + Item, |
| 333 | + (uintptr_t)BucketItem::$vftable()[79], |
| 334 | + ::ItemUseMethod, |
| 335 | + ::ItemStack& inoutInstance, |
| 336 | + Level* level, |
| 337 | + Player* player |
| 338 | +) { |
| 339 | + IF_LISTENED(EVENT_TYPES::onAte) { |
| 340 | + if (!CallEvent(EVENT_TYPES::onAte, PlayerClass::newPlayer(player), ItemClass::newItem(&inoutInstance))) { |
| 341 | + return ItemUseMethod::Unknown; |
| 342 | + } |
| 343 | + } |
| 344 | + IF_LISTENED_END(EVENT_TYPES::onAte); |
| 345 | + return origin(inoutInstance, level, player); |
| 346 | +} |
329 | 347 |
|
330 | 348 | LL_TYPE_INSTANCE_HOOK( |
331 | 349 | ChangeDimensionHook, |
@@ -656,16 +674,15 @@ void CloseContainerEvent() { |
656 | 674 | CloseContainerHook2::hook(); |
657 | 675 | } |
658 | 676 | void ChangeSlotEvent() { ChangeSlotHook::hook(); } |
659 | | -void AttackBlockEvent() { |
660 | | - // AttackBlockHook::hook(); |
661 | | -} |
| 677 | +void AttackBlockEvent() { AttackBlockHook::hook(); } |
662 | 678 | void UseFrameEvent() { |
663 | 679 | UseFrameHook1::hook(); |
664 | 680 | UseFrameHook2::hook(); |
665 | 681 | } |
666 | 682 | void EatEvent() { |
667 | 683 | EatHook1::hook(); |
668 | | - // EatHook2::hook(); |
| 684 | + EatHook2::hook(); |
| 685 | + EatHook3::hook(); |
669 | 686 | } |
670 | 687 | void ChangeDimensionEvent() { ChangeDimensionHook::hook(); }; |
671 | 688 | void OpenContainerScreenEvent() { OpenContainerScreenHook::hook(); } |
|
0 commit comments