|
16 | 16 | #include "mc/world/actor/Hopper.h" |
17 | 17 | #include "mc/world/actor/player/Player.h" |
18 | 18 | #include "mc/world/containers/models/LevelContainerModel.h" |
| 19 | +#include "mc/world/item/Item.h" |
19 | 20 | #include "mc/world/item/ItemStack.h" |
20 | 21 | #include "mc/world/level/BlockSource.h" |
21 | 22 | #include "mc/world/level/Explosion.h" |
|
45 | 46 | #include "mc/world/level/block/StructureBlock.h" |
46 | 47 | #include "mc/world/level/block/TntBlock.h" |
47 | 48 | #include "mc/world/level/block/TrapDoorBlock.h" |
| 49 | +#include "mc/world/level/block/VanillaBlockTypeIds.h" |
48 | 50 | #include "mc/world/level/block/VanillaStates.h" |
49 | 51 | #include "mc/world/level/block/actor/BaseCommandBlock.h" |
50 | 52 | #include "mc/world/level/block/actor/PistonBlockActor.h" |
51 | 53 | #include "mc/world/level/block/block_events/BlockPlayerInteractEvent.h" |
52 | 54 | #include "mc/world/level/block/block_events/BlockRedstoneUpdateEvent.h" |
53 | 55 | #include "mc/world/level/dimension/Dimension.h" |
54 | 56 | #include "mc/world/level/material/Material.h" |
55 | | - |
56 | 57 | namespace lse::events::block { |
57 | 58 |
|
58 | 59 | using api::thread::isServerThread; |
@@ -256,14 +257,19 @@ LL_TYPE_INSTANCE_HOOK( |
256 | 257 | ) { |
257 | 258 | IF_LISTENED(EVENT_TYPES::onRespawnAnchorExplode) { |
258 | 259 | if (isServerThread()) { |
259 | | - auto state = _tryLookupAlteredStateCollection( |
260 | | - VanillaStates::RespawnAnchorCharge().mID, |
261 | | - eventData.getBlock().getData() |
262 | | - ); |
263 | | - if (state.has_value() && state.value() > 1) { |
| 260 | + // 原版逻辑:手持萤石且未满时 _tryCharge 会优先充能并短路,不会爆炸; |
| 261 | + // 充能大于 0 且不在下界(维度 1)时 _trySetSpawn 才会调用 _explode 引爆 |
| 262 | + auto& block = eventData.mPlayer.getDimensionBlockSource().getBlock(eventData.mPos); |
| 263 | + int charge = block.getState<int>(VanillaStates::RespawnAnchorCharge().mID).value_or(0); |
| 264 | + auto& item = eventData.mPlayer.getSelectedItem(); |
| 265 | + auto* itemBlockType = item.mItem ? item.mItem->mBlockType.get().get() : nullptr; |
| 266 | + bool isCharging = itemBlockType && *itemBlockType->mNameInfo->mFullName == VanillaBlockTypeIds::Glowstone() |
| 267 | + && charge < static_cast<int>(VanillaStates::RespawnAnchorCharge().mVariationCount) - 1; |
| 268 | + if (charge > 0 && !isCharging && eventData.mPlayer.getDimensionId() != 1) { |
264 | 269 | if (!CallEvent( |
265 | 270 | EVENT_TYPES::onRespawnAnchorExplode, |
266 | | - IntPos::newPos(eventData.mPos, eventData.mPlayer.getDimensionId()) |
| 271 | + IntPos::newPos(eventData.mPos, eventData.mPlayer.getDimensionId()), |
| 272 | + PlayerClass::newPlayer(&eventData.mPlayer) |
267 | 273 | )) { |
268 | 274 | return; |
269 | 275 | } |
|
0 commit comments