use of org.spongepowered.common.interfaces.block.IMixinBlockEventData in project SpongeCommon by SpongePowered.
the class MixinWorldServer method onAddBlockEvent.
@Redirect(method = "addBlockEvent", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/WorldServer$ServerBlockEventList;add(Ljava/lang/Object;)Z", remap = false))
private boolean onAddBlockEvent(WorldServer.ServerBlockEventList list, Object obj, BlockPos pos, Block blockIn, int eventId, int eventParam) {
final BlockEventData blockEventData = (BlockEventData) obj;
IMixinBlockEventData blockEvent = (IMixinBlockEventData) blockEventData;
// This is very common with pistons as they add block events while blocks are being notified.
if (blockIn instanceof BlockPistonBase) {
// We only fire pre events for pistons
if (SpongeCommonEventFactory.handlePistonEvent(this, list, obj, pos, blockIn, eventId, eventParam)) {
return false;
}
blockEvent.setCaptureBlocks(false);
// TODO BLOCK_EVENT flag
} else if (SpongeCommonEventFactory.callChangeBlockEventPre(this, pos).isCancelled()) {
return false;
}
final PhaseTracker phaseTracker = PhaseTracker.getInstance();
final PhaseData currentPhase = phaseTracker.getCurrentPhaseData();
final IPhaseState phaseState = currentPhase.state;
if (phaseState.ignoresBlockEvent()) {
return list.add((BlockEventData) obj);
}
final PhaseContext<?> context = currentPhase.context;
final LocatableBlock locatable = LocatableBlock.builder().location(new Location<>(this, pos.getX(), pos.getY(), pos.getZ())).state(this.getBlock(pos.getX(), pos.getY(), pos.getZ())).build();
blockEvent.setTickBlock(locatable);
phaseState.addNotifierToBlockEvent(context, this, pos, blockEvent);
return list.add((BlockEventData) obj);
}
use of org.spongepowered.common.interfaces.block.IMixinBlockEventData in project SpongeCommon by SpongePowered.
the class TrackingUtil method fireMinecraftBlockEvent.
public static boolean fireMinecraftBlockEvent(WorldServer worldIn, BlockEventData event) {
IBlockState currentState = worldIn.getBlockState(event.getPosition());
final IMixinBlockEventData blockEvent = (IMixinBlockEventData) event;
IPhaseState<?> phase = blockEvent.getCaptureBlocks() ? TickPhase.Tick.BLOCK_EVENT : TickPhase.Tick.NO_CAPTURE_BLOCK;
final PhaseContext<?> phaseContext = phase.createPhaseContext();
Object source = blockEvent.getTickBlock() != null ? blockEvent.getTickBlock() : blockEvent.getTickTileEntity();
if (source != null) {
phaseContext.source(source);
} else {
// No source present which means we are ignoring the phase state
boolean result = currentState.onBlockEventReceived(worldIn, event.getPosition(), event.getEventID(), event.getEventParameter());
return result;
}
if (blockEvent.getSourceUser() != null) {
phaseContext.notifier(blockEvent.getSourceUser());
}
try (PhaseContext<?> o = phaseContext.buildAndSwitch()) {
return currentState.onBlockEventReceived(worldIn, event.getPosition(), event.getEventID(), event.getEventParameter());
}
}
Aggregations