Search in sources :

Example 1 with NeighborNotifyEvent

use of net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method onNeighborNotify.

public static NeighborNotifyEvent onNeighborNotify(World world, BlockPos pos, IBlockState state, EnumSet<EnumFacing> notifiedSides, boolean forceRedstoneUpdate) {
    NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides, forceRedstoneUpdate);
    MinecraftForge.EVENT_BUS.post(event);
    return event;
}
Also used : NeighborNotifyEvent(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent)

Example 2 with NeighborNotifyEvent

use of net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent in project SpongeForge by SpongePowered.

the class SpongeForgeEventFactory method callNeighborNotifyEvent.

public static NotifyNeighborBlockEvent callNeighborNotifyEvent(Event event) {
    NotifyNeighborBlockEvent spongeEvent = (NotifyNeighborBlockEvent) event;
    LocatableBlock locatableBlock = spongeEvent.getCause().first(LocatableBlock.class).orElse(null);
    TileEntity tileEntitySource = spongeEvent.getCause().first(TileEntity.class).orElse(null);
    Location<World> sourceLocation = null;
    IBlockState state = null;
    if (locatableBlock != null) {
        Location<World> location = locatableBlock.getLocation();
        sourceLocation = location;
        state = (IBlockState) locatableBlock.getBlockState();
    } else if (tileEntitySource != null) {
        sourceLocation = tileEntitySource.getLocation();
        state = (IBlockState) sourceLocation.getBlock();
    } else {
        // should never happen but just in case it does
        return spongeEvent;
    }
    EnumSet<EnumFacing> facings = EnumSet.noneOf(EnumFacing.class);
    for (Map.Entry<Direction, BlockState> mapEntry : spongeEvent.getNeighbors().entrySet()) {
        if (mapEntry.getKey() != Direction.NONE) {
            facings.add(DirectionFacingProvider.getInstance().get(mapEntry.getKey()).get());
        }
    }
    if (facings.isEmpty()) {
        return spongeEvent;
    }
    BlockPos pos = ((IMixinLocation) (Object) sourceLocation).getBlockPos();
    net.minecraft.world.World world = (net.minecraft.world.World) sourceLocation.getExtent();
    // TODO - the boolean forced redstone bit needs to be set properly
    final NeighborNotifyEvent forgeEvent = new NeighborNotifyEvent(world, pos, state, facings, false);
    ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
    if (forgeEvent.isCanceled()) {
        spongeEvent.setCancelled(true);
    }
    return spongeEvent;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) EnumFacing(net.minecraft.util.EnumFacing) World(org.spongepowered.api.world.World) IMixinWorld(org.spongepowered.common.interfaces.world.IMixinWorld) Direction(org.spongepowered.api.util.Direction) TileEntity(org.spongepowered.api.block.tileentity.TileEntity) IMixinEventBus(org.spongepowered.mod.interfaces.IMixinEventBus) NotifyNeighborBlockEvent(org.spongepowered.api.event.block.NotifyNeighborBlockEvent) BlockState(org.spongepowered.api.block.BlockState) IBlockState(net.minecraft.block.state.IBlockState) NeighborNotifyEvent(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent) LocatableBlock(org.spongepowered.api.world.LocatableBlock) BlockPos(net.minecraft.util.math.BlockPos) Map(java.util.Map)

Example 3 with NeighborNotifyEvent

use of net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent in project MinecraftForge by MinecraftForge.

the class ForgeEventFactory method onNeighborNotify.

public static NeighborNotifyEvent onNeighborNotify(Level world, BlockPos pos, BlockState state, EnumSet<Direction> notifiedSides, boolean forceRedstoneUpdate) {
    NeighborNotifyEvent event = new NeighborNotifyEvent(world, pos, state, notifiedSides, forceRedstoneUpdate);
    MinecraftForge.EVENT_BUS.post(event);
    return event;
}
Also used : NeighborNotifyEvent(net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent)

Aggregations

NeighborNotifyEvent (net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent)3 Map (java.util.Map)1 IBlockState (net.minecraft.block.state.IBlockState)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 BlockState (org.spongepowered.api.block.BlockState)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 NotifyNeighborBlockEvent (org.spongepowered.api.event.block.NotifyNeighborBlockEvent)1 Direction (org.spongepowered.api.util.Direction)1 LocatableBlock (org.spongepowered.api.world.LocatableBlock)1 World (org.spongepowered.api.world.World)1 IMixinLocation (org.spongepowered.common.interfaces.world.IMixinLocation)1 IMixinWorld (org.spongepowered.common.interfaces.world.IMixinWorld)1 IMixinEventBus (org.spongepowered.mod.interfaces.IMixinEventBus)1