|
40 | 40 | #include "mc/world/level/block/Block.h" |
41 | 41 | #include "mc/world/level/block/ItemFrameBlock.h" |
42 | 42 | #include "mc/world/level/block/RespawnAnchorBlock.h" |
| 43 | +#include "mc/world/level/block/VanillaBlockTypeIds.h" |
43 | 44 | #include "mc/world/level/block/VanillaStates.h" |
44 | 45 | #include "mc/world/level/block/actor/PistonBlockActor.h" |
45 | 46 | #include "mc/world/level/block/block_events/BlockPlayerInteractEvent.h" |
46 | 47 | #include "mc/world/level/dimension/Dimension.h" |
| 48 | +#include "mc/world/level/material/Material.h" |
47 | 49 |
|
48 | 50 | namespace lse::events::player { |
49 | 51 |
|
@@ -492,59 +494,42 @@ LL_TYPE_INSTANCE_HOOK( |
492 | 494 | } |
493 | 495 |
|
494 | 496 | LL_TYPE_INSTANCE_HOOK( |
495 | | - UseBucketTakeHook1, |
| 497 | + UseBucketTakeHook, |
496 | 498 | HookPriority::Normal, |
497 | 499 | BucketItem, |
498 | | - &BucketItem::_takeLiquid, |
499 | | - bool, |
500 | | - ItemStack& item, |
501 | | - Actor& entity, |
502 | | - BlockPos const& pos |
| 500 | + &BucketItem::$_useOn, |
| 501 | + InteractionResult, |
| 502 | + ::ItemStack& instance, |
| 503 | + ::Actor& entity, |
| 504 | + ::BlockPos pos, |
| 505 | + uchar face, |
| 506 | + ::Vec3 const& clickPos |
503 | 507 | ) { |
504 | 508 | IF_LISTENED(EVENT_TYPES::onUseBucketTake) { |
505 | 509 | if (isServerThread()) { |
506 | | - if (!CallEvent( |
507 | | - EVENT_TYPES::onUseBucketTake, |
508 | | - PlayerClass::newPlayer(&static_cast<Player&>(entity)), |
509 | | - ItemClass::newItem(&item), |
510 | | - BlockClass::newBlock(pos, entity.getDimensionId()), |
511 | | - Number::newNumber(-1), |
512 | | - FloatPos::newPos(pos, entity.getDimensionId()) |
513 | | - )) { |
514 | | - return false; |
| 510 | + auto& bs = entity.getDimensionBlockSource(); |
| 511 | + using ::SharedTypes::v1_26_20::MaterialType; |
| 512 | + if (auto& type = bs.getMaterial(pos).mType; type != MaterialType::Water && type != MaterialType::Lava) { |
| 513 | + return InteractionResult{false, true}; |
| 514 | + } |
| 515 | + if (auto& bl = bs.getBlock(pos).mBlockType; |
| 516 | + *bl->mNameInfo->mFullName != VanillaBlockTypeIds::PowderSnow()) { |
| 517 | + return InteractionResult{false, true}; |
515 | 518 | } |
516 | | - } |
517 | | - } |
518 | | - IF_LISTENED_END(EVENT_TYPES::onUseBucketTake); |
519 | | - return origin(item, entity, pos); |
520 | | -} |
521 | | - |
522 | | -LL_TYPE_INSTANCE_HOOK( |
523 | | - UseBucketTakeHook2, |
524 | | - HookPriority::Normal, |
525 | | - BucketItem, |
526 | | - &BucketItem::_takePowderSnow, |
527 | | - bool, |
528 | | - ItemStack& item, |
529 | | - Actor& entity, |
530 | | - BlockPos const& pos |
531 | | -) { |
532 | | - IF_LISTENED(EVENT_TYPES::onUseBucketTake) { |
533 | | - if (isServerThread()) { |
534 | 519 | if (!CallEvent( |
535 | 520 | EVENT_TYPES::onUseBucketTake, |
536 | 521 | PlayerClass::newPlayer(&static_cast<Player&>(entity)), |
537 | | - ItemClass::newItem(&item), |
| 522 | + ItemClass::newItem(&instance), |
538 | 523 | BlockClass::newBlock(pos, entity.getDimensionId()), |
539 | 524 | Number::newNumber(-1), |
540 | 525 | FloatPos::newPos(pos, entity.getDimensionId()) |
541 | 526 | )) { |
542 | | - return false; |
| 527 | + return InteractionResult{false, true}; |
543 | 528 | } |
544 | 529 | } |
545 | 530 | } |
546 | 531 | IF_LISTENED_END(EVENT_TYPES::onUseBucketTake); |
547 | | - return origin(item, entity, pos); |
| 532 | + return origin(instance, entity, pos, face, clickPos); |
548 | 533 | } |
549 | 534 |
|
550 | 535 | LL_TYPE_INSTANCE_HOOK(ConsumeTotemHook, HookPriority::Normal, Player, &Player::$consumeTotem, bool) { |
@@ -669,7 +654,7 @@ LL_TYPE_INSTANCE_HOOK( |
669 | 654 | uchar face, |
670 | 655 | std::optional<Vec3> hit |
671 | 656 | ) { |
672 | | - if (!isServerThread() || (!isInteractiveBlock() && !mBlockType->isCraftingBlock())) { |
| 657 | + if (!isServerThread() || (!mBlockType->isInteractiveBlock() && !mBlockType->isCraftingBlock())) { |
673 | 658 | return origin(player, pos, face, hit); // 提前把不可交互方块过滤掉 |
674 | 659 | } |
675 | 660 | IF_LISTENED(EVENT_TYPES::onBlockInteracted) { |
@@ -705,7 +690,7 @@ void SleepEvent() { static ll::memory::HookRegistrar<SleepHook> reg; } |
705 | 690 | void OpenInventoryEvent() { static ll::memory::HookRegistrar<OpenInventoryHook> reg; } |
706 | 691 | void PullFishingHookEvent() { static ll::memory::HookRegistrar<PullFishingHook> reg; } |
707 | 692 | void UseBucketPlaceEvent() { static ll::memory::HookRegistrar<UseBucketPlaceHook> reg; } |
708 | | -void UseBucketTakeEvent() { static ll::memory::HookRegistrar<UseBucketTakeHook1, UseBucketTakeHook2> reg; } |
| 693 | +void UseBucketTakeEvent() { static ll::memory::HookRegistrar<UseBucketTakeHook> reg; } |
709 | 694 | void ConsumeTotemEvent() { static ll::memory::HookRegistrar<ConsumeTotemHook> reg; } |
710 | 695 | void SetArmorEvent() { static ll::memory::HookRegistrar<SetArmorHook> reg; } |
711 | 696 | void InteractEntityEvent() { static ll::memory::HookRegistrar<InteractEntityHook> reg; } |
|
0 commit comments