Search in sources :

Example 6 with NotifyNeighborBlockEvent

use of org.spongepowered.api.event.block.NotifyNeighborBlockEvent in project SpongeCommon by SpongePowered.

the class MixinWorldServer method notifyNeighborsOfStateChange.

/**
 * @author gabizou - March 12th, 2016
 *
 * Technically an overwrite to properly track on *server* worlds.
 */
@Override
public void notifyNeighborsOfStateChange(BlockPos pos, Block blockType, boolean updateObserverBlocks) {
    if (!isValid(pos)) {
        return;
    }
    final Chunk chunk = ((IMixinChunkProviderServer) this.getChunkProvider()).getLoadedChunkWithoutMarkingActive(pos.getX() >> 4, pos.getZ() >> 4);
    // Don't let neighbor updates trigger a chunk load ever
    if (chunk == null) {
        return;
    }
    final NotifyNeighborBlockEvent event = SpongeCommonEventFactory.callNotifyNeighborEvent(this, pos, NOTIFY_DIRECTIONS);
    if (event == null || !event.isCancelled()) {
        final PhaseTracker phaseTracker = PhaseTracker.getInstance();
        for (EnumFacing facing : EnumFacing.values()) {
            if (event != null) {
                final Direction direction = DirectionFacingProvider.getInstance().getKey(facing).get();
                if (!event.getNeighbors().keySet().contains(direction)) {
                    continue;
                }
            }
            phaseTracker.notifyBlockOfStateChange(this, pos.offset(facing), blockType, pos);
        }
    }
    // Copied over to ensure observers retain functionality.
    if (updateObserverBlocks) {
        this.updateObservingBlocksAt(pos, blockType);
    }
}
Also used : NotifyNeighborBlockEvent(org.spongepowered.api.event.block.NotifyNeighborBlockEvent) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) EnumFacing(net.minecraft.util.EnumFacing) IMixinChunk(org.spongepowered.common.interfaces.IMixinChunk) Chunk(net.minecraft.world.chunk.Chunk) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) Direction(org.spongepowered.api.util.Direction)

Aggregations

NotifyNeighborBlockEvent (org.spongepowered.api.event.block.NotifyNeighborBlockEvent)6 EnumFacing (net.minecraft.util.EnumFacing)5 Direction (org.spongepowered.api.util.Direction)4 BlockPos (net.minecraft.util.math.BlockPos)3 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)3 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)3 IBlockState (net.minecraft.block.state.IBlockState)2 Chunk (net.minecraft.world.chunk.Chunk)2 BlockState (org.spongepowered.api.block.BlockState)2 LocatableBlock (org.spongepowered.api.world.LocatableBlock)2 World (org.spongepowered.api.world.World)2 IMixinChunkProviderServer (org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 IInteractionObject (net.minecraft.world.IInteractionObject)1 NeighborNotifyEvent (net.minecraftforge.event.world.BlockEvent.NeighborNotifyEvent)1 TileEntity (org.spongepowered.api.block.tileentity.TileEntity)1 CauseStackManager (org.spongepowered.api.event.CauseStackManager)1 StackFrame (org.spongepowered.api.event.CauseStackManager.StackFrame)1 Location (org.spongepowered.api.world.Location)1