use of org.spongepowered.common.event.tracking.phase.tick.BlockEventTickContext in project SpongeCommon by SpongePowered.
the class TrackingUtil method fireMinecraftBlockEvent.
public static boolean fireMinecraftBlockEvent(final ServerLevel worldIn, final BlockEventData event, final net.minecraft.world.level.block.state.BlockState currentState) {
final TrackableBlockEventDataBridge blockEvent = (TrackableBlockEventDataBridge) event;
@Nullable final Object source = blockEvent.bridge$getTileEntity() != null ? blockEvent.bridge$getTileEntity() : blockEvent.bridge$getTickingLocatable();
if (source == null) {
// No source present which means we are ignoring the phase state
return currentState.triggerEvent(worldIn, event.getPos(), event.getParamA(), event.getParamB());
}
final BlockEventTickContext phaseContext = TickPhase.Tick.BLOCK_EVENT.createPhaseContext(PhaseTracker.SERVER);
phaseContext.source(source);
final UUID user = ((TrackableBlockEventDataBridge) event).bridge$getSourceUserUUID();
if (user != null) {
phaseContext.creator = user;
phaseContext.notifier = user;
}
boolean result = true;
try (final BlockEventTickContext o = phaseContext) {
o.buildAndSwitch();
phaseContext.setEventSucceeded(currentState.triggerEvent(worldIn, event.getPos(), event.getParamA(), event.getParamB()));
// We need to grab the result here as the phase context close will trigger a reset
result = phaseContext.wasNotCancelled();
}
// at which point we want to keep track of the return value from the target, and from the block events.
return result;
}
Aggregations