use of net.minecraft.block.BlockEventData 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);
}
Aggregations