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;
}
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;
}
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;
}
Aggregations