|
6 | 6 | #include "legacy/api/ItemAPI.h" |
7 | 7 | #include "legacy/api/PlayerAPI.h" |
8 | 8 | #include "ll/api/memory/Hook.h" |
9 | | -#include "ll/api/memory/Memory.h" |
10 | 9 | #include "ll/api/service/Bedrock.h" |
11 | 10 | #include "lse/api/Thread.h" |
12 | 11 | #include "mc/legacy/ActorUniqueID.h" |
|
46 | 45 | #include "mc/world/level/block/StructureBlock.h" |
47 | 46 | #include "mc/world/level/block/TntBlock.h" |
48 | 47 | #include "mc/world/level/block/TrapDoorBlock.h" |
49 | | -#include "mc/world/level/block/VanillaBlockTypeIds.h" |
| 48 | +#include "mc/world/level/block/VanillaStates.h" |
50 | 49 | #include "mc/world/level/block/actor/BaseCommandBlock.h" |
51 | 50 | #include "mc/world/level/block/actor/PistonBlockActor.h" |
| 51 | +#include "mc/world/level/block/block_events/BlockPlayerInteractEvent.h" |
52 | 52 | #include "mc/world/level/block/block_events/BlockRedstoneUpdateEvent.h" |
53 | 53 | #include "mc/world/level/dimension/Dimension.h" |
54 | 54 | #include "mc/world/level/material/Material.h" |
@@ -243,18 +243,35 @@ LL_TYPE_INSTANCE_HOOK(ExplodeHook, HookPriority::Normal, Explosion, &Explosion:: |
243 | 243 | } |
244 | 244 | } |
245 | 245 | IF_LISTENED_END(EVENT_TYPES::onBlockExplode); |
| 246 | + return origin(random); |
| 247 | +} |
246 | 248 |
|
| 249 | +LL_TYPE_INSTANCE_HOOK( |
| 250 | + UseRespawnAnchorHook, |
| 251 | + HookPriority::Normal, |
| 252 | + RespawnAnchorBlock, |
| 253 | + &RespawnAnchorBlock::use, |
| 254 | + void, |
| 255 | + ::BlockEvents::BlockPlayerInteractEvent& eventData |
| 256 | +) { |
247 | 257 | IF_LISTENED(EVENT_TYPES::onRespawnAnchorExplode) { |
248 | | - // TODO: find a function which can get player |
249 | | - if (isServerThread() |
250 | | - && *mRegion.getBlock(*mPos).getBlockType().mNameInfo->mFullName == VanillaBlockTypeIds::RespawnAnchor()) { |
251 | | - if (!CallEvent(EVENT_TYPES::onRespawnAnchorExplode, IntPos::newPos(*mPos, mRegion.getDimensionId()))) { |
252 | | - return false; |
| 258 | + if (isServerThread()) { |
| 259 | + auto state = _tryLookupAlteredStateCollection( |
| 260 | + VanillaStates::RespawnAnchorCharge().mID, |
| 261 | + eventData.getBlock().getData() |
| 262 | + ); |
| 263 | + if (state.has_value() && state.value() > 1) { |
| 264 | + if (!CallEvent( |
| 265 | + EVENT_TYPES::onRespawnAnchorExplode, |
| 266 | + IntPos::newPos(eventData.mPos, eventData.mPlayer.getDimensionId()) |
| 267 | + )) { |
| 268 | + return; |
| 269 | + } |
253 | 270 | } |
254 | 271 | } |
255 | 272 | } |
256 | 273 | IF_LISTENED_END(EVENT_TYPES::onRespawnAnchorExplode); |
257 | | - return origin(random); |
| 274 | + origin(eventData); |
258 | 275 | } |
259 | 276 |
|
260 | 277 | LL_TYPE_STATIC_HOOK( |
@@ -606,7 +623,7 @@ void PressurePlateTriggerEvent() { static ll::memory::HookRegistrar<PressurePlat |
606 | 623 | void FarmDecayEvent() { static ll::memory::HookRegistrar<FarmDecayHook> reg; } |
607 | 624 | void PistonPushEvent() { static ll::memory::HookRegistrar<PistonPushHook> reg; } |
608 | 625 | void ExplodeEvent() { static ll::memory::HookRegistrar<ExplodeHook> reg; } |
609 | | -void RespawnAnchorExplodeEvent() { ExplodeEvent(); } |
| 626 | +void RespawnAnchorExplodeEvent() { static ll::memory::HookRegistrar<UseRespawnAnchorHook> reg; } |
610 | 627 | void PortalSpawnEvent() { static ll::memory::HookRegistrar<PortalSpawnHook> reg; } |
611 | 628 | void BlockExplodedEvent() { static ll::memory::HookRegistrar<BlockExplodedHook> reg; } |
612 | 629 | void RedstoneUpdateEvent() { |
|
0 commit comments