Java Code Examples for net.minecraft.world.World.notifyNeighborsOfStateChange()

The following are Jave code examples for showing how to use notifyNeighborsOfStateChange() of the net.minecraft.world.World class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: Bewitchment   File: BlockSaltBarrier.java   Source Code and License Vote up 6 votes
@Override
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
	if (!worldIn.isRemote) {
		this.updateSurroundingSalt(worldIn, state);

		for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL) {
			worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, true);
		}

		for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL) {
			this.notifyBarrierNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
		}

		for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL) {
			final BlockPos blockpos = pos.offset(enumfacing2);

			if (worldIn.getBlockState(blockpos).isNormalCube()) {
				this.notifyBarrierNeighborsOfStateChange(worldIn, blockpos.up());
			} else {
				this.notifyBarrierNeighborsOfStateChange(worldIn, blockpos.down());
			}
		}
	}
}
 
Example 2
Project: BaseClient   File: BlockLever.java   Source Code and License Vote up 6 votes
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ)
{
    if (worldIn.isRemote)
    {
        return true;
    }
    else
    {
        state = state.cycleProperty(POWERED);
        worldIn.setBlockState(pos, state, 3);
        worldIn.playSoundEffect((double)pos.getX() + 0.5D, (double)pos.getY() + 0.5D, (double)pos.getZ() + 0.5D, "random.click", 0.3F, ((Boolean)state.getValue(POWERED)).booleanValue() ? 0.6F : 0.5F);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
        worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this);
        return true;
    }
}
 
Example 3
Project: CustomWorldGen   File: BlockRailPowered.java   Source Code and License Vote up 6 votes
protected void updateState(IBlockState p_189541_1_, World p_189541_2_, BlockPos p_189541_3_, Block p_189541_4_)
{
    boolean flag = ((Boolean)p_189541_1_.getValue(POWERED)).booleanValue();
    boolean flag1 = p_189541_2_.isBlockPowered(p_189541_3_) || this.findPoweredRailSignal(p_189541_2_, p_189541_3_, p_189541_1_, true, 0) || this.findPoweredRailSignal(p_189541_2_, p_189541_3_, p_189541_1_, false, 0);

    if (flag1 != flag)
    {
        p_189541_2_.setBlockState(p_189541_3_, p_189541_1_.withProperty(POWERED, Boolean.valueOf(flag1)), 3);
        p_189541_2_.notifyNeighborsOfStateChange(p_189541_3_.down(), this);

        if (((BlockRailBase.EnumRailDirection)p_189541_1_.getValue(SHAPE)).isAscending())
        {
            p_189541_2_.notifyNeighborsOfStateChange(p_189541_3_.up(), this);
        }
    }
}
 
Example 4
Project: CustomWorldGen   File: BlockRedstoneWire.java   Source Code and License Vote up 5 votes
/**
 * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
 */
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    super.breakBlock(worldIn, pos, state);

    if (!worldIn.isRemote)
    {
        for (EnumFacing enumfacing : EnumFacing.values())
        {
            worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
        }

        this.updateSurroundingRedstone(worldIn, pos, state);

        for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
        {
            this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
        }

        for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
        {
            BlockPos blockpos = pos.offset(enumfacing2);

            if (worldIn.getBlockState(blockpos).isNormalCube())
            {
                this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
            }
            else
            {
                this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
            }
        }
    }
}
 
Example 5
Project: harshencastle   File: HarshenHiddenPlateActive.java   Source Code and License Vote up 5 votes
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn,
		EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
	for(EnumFacing face : EnumFacing.VALUES)
		worldIn.notifyNeighborsOfStateChange(pos.offset(facing), this, false);
	return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
}
 
Example 6
Project: BaseClient   File: BlockRailBase.java   Source Code and License Vote up 5 votes
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
	super.breakBlock(worldIn, pos, state);

	if (((BlockRailBase.EnumRailDirection) state.getValue(this.getShapeProperty())).isAscending()) {
		worldIn.notifyNeighborsOfStateChange(pos.up(), this);
	}

	if (this.isPowered) {
		worldIn.notifyNeighborsOfStateChange(pos, this);
		worldIn.notifyNeighborsOfStateChange(pos.down(), this);
	}
}
 
Example 7
Project: CustomWorldGen   File: BlockRedstoneTorch.java   Source Code and License Vote up 5 votes
/**
 * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
 */
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (this.isOn)
    {
        for (EnumFacing enumfacing : EnumFacing.values())
        {
            worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this);
        }
    }
}
 
Example 8
Project: Backmemed   File: BlockRedstoneWire.java   Source Code and License Vote up 5 votes
private IBlockState updateSurroundingRedstone(World worldIn, BlockPos pos, IBlockState state)
{
    state = this.calculateCurrentChanges(worldIn, pos, pos, state);
    List<BlockPos> list = Lists.newArrayList(this.blocksNeedingUpdate);
    this.blocksNeedingUpdate.clear();

    for (BlockPos blockpos : list)
    {
        worldIn.notifyNeighborsOfStateChange(blockpos, this, false);
    }

    return state;
}
 
Example 9
Project: Backmemed   File: BlockRedstoneWire.java   Source Code and License Vote up 5 votes
/**
 * Called after the block is set in the Chunk data, but before the Tile Entity is set
 */
public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
{
    if (!worldIn.isRemote)
    {
        this.updateSurroundingRedstone(worldIn, pos, state);

        for (EnumFacing enumfacing : EnumFacing.Plane.VERTICAL)
        {
            worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
        }

        for (EnumFacing enumfacing1 : EnumFacing.Plane.HORIZONTAL)
        {
            this.notifyWireNeighborsOfStateChange(worldIn, pos.offset(enumfacing1));
        }

        for (EnumFacing enumfacing2 : EnumFacing.Plane.HORIZONTAL)
        {
            BlockPos blockpos = pos.offset(enumfacing2);

            if (worldIn.getBlockState(blockpos).isNormalCube())
            {
                this.notifyWireNeighborsOfStateChange(worldIn, blockpos.up());
            }
            else
            {
                this.notifyWireNeighborsOfStateChange(worldIn, blockpos.down());
            }
        }
    }
}
 
Example 10
Project: CustomWorldGen   File: BlockLever.java   Source Code and License Vote up 5 votes
/**
 * Called serverside after this block is replaced with another in Chunk, but before the Tile Entity is updated
 */
public void breakBlock(World worldIn, BlockPos pos, IBlockState state)
{
    if (((Boolean)state.getValue(POWERED)).booleanValue())
    {
        worldIn.notifyNeighborsOfStateChange(pos, this);
        EnumFacing enumfacing = ((BlockLever.EnumOrientation)state.getValue(FACING)).getFacing();
        worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing.getOpposite()), this);
    }

    super.breakBlock(worldIn, pos, state);
}
 
Example 11
Project: BaseClient   File: BlockTripWireHook.java   Source Code and License Vote up 5 votes
public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
	boolean flag = ((Boolean) state.getValue(ATTACHED)).booleanValue();
	boolean flag1 = ((Boolean) state.getValue(POWERED)).booleanValue();

	if (flag || flag1) {
		this.func_176260_a(worldIn, pos, state, true, false, -1, (IBlockState) null);
	}

	if (flag1) {
		worldIn.notifyNeighborsOfStateChange(pos, this);
		worldIn.notifyNeighborsOfStateChange(pos.offset(((EnumFacing) state.getValue(FACING)).getOpposite()), this);
	}

	super.breakBlock(worldIn, pos, state);
}
 
Example 12
Project: BaseClient   File: BlockRailDetector.java   Source Code and License Vote up 5 votes
private void updatePoweredState(World worldIn, BlockPos pos, IBlockState state)
{
    boolean flag = ((Boolean)state.getValue(POWERED)).booleanValue();
    boolean flag1 = false;
    List<EntityMinecart> list = this.<EntityMinecart>findMinecarts(worldIn, pos, EntityMinecart.class, new Predicate[0]);

    if (!list.isEmpty())
    {
        flag1 = true;
    }

    if (flag1 && !flag)
    {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(true)), 3);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        worldIn.notifyNeighborsOfStateChange(pos.down(), this);
        worldIn.markBlockRangeForRenderUpdate(pos, pos);
    }

    if (!flag1 && flag)
    {
        worldIn.setBlockState(pos, state.withProperty(POWERED, Boolean.valueOf(false)), 3);
        worldIn.notifyNeighborsOfStateChange(pos, this);
        worldIn.notifyNeighborsOfStateChange(pos.down(), this);
        worldIn.markBlockRangeForRenderUpdate(pos, pos);
    }

    if (flag1)
    {
        worldIn.scheduleUpdate(pos, this, this.tickRate(worldIn));
    }

    worldIn.updateComparatorOutputLevel(pos, this);
}
 
Example 13
Project: Backmemed   File: BlockRedstoneDiode.java   Source Code and License Vote up 5 votes
/**
 * Called when a player destroys this Block
 */
public void onBlockDestroyedByPlayer(World worldIn, BlockPos pos, IBlockState state)
{
    if (this.isRepeaterPowered)
    {
        for (EnumFacing enumfacing : EnumFacing.values())
        {
            worldIn.notifyNeighborsOfStateChange(pos.offset(enumfacing), this, false);
        }
    }

    super.onBlockDestroyedByPlayer(worldIn, pos, state);
}
 
Example 14
Project: BaseClient   File: BlockTripWireHook.java   Source Code and License Vote up 4 votes
private void func_176262_b(World worldIn, BlockPos p_176262_2_, EnumFacing p_176262_3_) {
	worldIn.notifyNeighborsOfStateChange(p_176262_2_, this);
	worldIn.notifyNeighborsOfStateChange(p_176262_2_.offset(p_176262_3_.getOpposite()), this);
}
 
Example 15
Project: BaseClient   File: BlockPistonBase.java   Source Code and License Vote up 4 votes
private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending)
{
    if (!extending)
    {
        worldIn.setBlockToAir(pos.offset(direction));
    }

    BlockPistonStructureHelper blockpistonstructurehelper = new BlockPistonStructureHelper(worldIn, pos, direction, extending);
    List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
    List<BlockPos> list1 = blockpistonstructurehelper.getBlocksToDestroy();

    if (!blockpistonstructurehelper.canMove())
    {
        return false;
    }
    else
    {
        int i = list.size() + list1.size();
        Block[] ablock = new Block[i];
        EnumFacing enumfacing = extending ? direction : direction.getOpposite();

        for (int j = list1.size() - 1; j >= 0; --j)
        {
            BlockPos blockpos = (BlockPos)list1.get(j);
            Block block = worldIn.getBlockState(blockpos).getBlock();
            block.dropBlockAsItem(worldIn, blockpos, worldIn.getBlockState(blockpos), 0);
            worldIn.setBlockToAir(blockpos);
            --i;
            ablock[i] = block;
        }

        for (int k = list.size() - 1; k >= 0; --k)
        {
            BlockPos blockpos2 = (BlockPos)list.get(k);
            IBlockState iblockstate = worldIn.getBlockState(blockpos2);
            Block block1 = iblockstate.getBlock();
            block1.getMetaFromState(iblockstate);
            worldIn.setBlockToAir(blockpos2);
            blockpos2 = blockpos2.offset(enumfacing);
            worldIn.setBlockState(blockpos2, Blocks.piston_extension.getDefaultState().withProperty(FACING, direction), 4);
            worldIn.setTileEntity(blockpos2, BlockPistonMoving.newTileEntity(iblockstate, direction, extending, false));
            --i;
            ablock[i] = block1;
        }

        BlockPos blockpos1 = pos.offset(direction);

        if (extending)
        {
            BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype = this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT;
            IBlockState iblockstate1 = Blocks.piston_head.getDefaultState().withProperty(BlockPistonExtension.FACING, direction).withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
            IBlockState iblockstate2 = Blocks.piston_extension.getDefaultState().withProperty(BlockPistonMoving.FACING, direction).withProperty(BlockPistonMoving.TYPE, this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT);
            worldIn.setBlockState(blockpos1, iblockstate2, 4);
            worldIn.setTileEntity(blockpos1, BlockPistonMoving.newTileEntity(iblockstate1, direction, true, false));
        }

        for (int l = list1.size() - 1; l >= 0; --l)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list1.get(l), ablock[i++]);
        }

        for (int i1 = list.size() - 1; i1 >= 0; --i1)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list.get(i1), ablock[i++]);
        }

        if (extending)
        {
            worldIn.notifyNeighborsOfStateChange(blockpos1, Blocks.piston_head);
            worldIn.notifyNeighborsOfStateChange(pos, this);
        }

        return true;
    }
}
 
Example 16
Project: Backmemed   File: BlockPistonBase.java   Source Code and License Vote up 4 votes
private boolean doMove(World worldIn, BlockPos pos, EnumFacing direction, boolean extending)
{
    if (!extending)
    {
        worldIn.setBlockToAir(pos.offset(direction));
    }

    BlockPistonStructureHelper blockpistonstructurehelper = new BlockPistonStructureHelper(worldIn, pos, direction, extending);

    if (!blockpistonstructurehelper.canMove())
    {
        return false;
    }
    else
    {
        List<BlockPos> list = blockpistonstructurehelper.getBlocksToMove();
        List<IBlockState> list1 = Lists.<IBlockState>newArrayList();

        for (int i = 0; i < list.size(); ++i)
        {
            BlockPos blockpos = (BlockPos)list.get(i);
            list1.add(worldIn.getBlockState(blockpos).getActualState(worldIn, blockpos));
        }

        List<BlockPos> list2 = blockpistonstructurehelper.getBlocksToDestroy();
        int k = list.size() + list2.size();
        IBlockState[] aiblockstate = new IBlockState[k];
        EnumFacing enumfacing = extending ? direction : direction.getOpposite();

        for (int j = list2.size() - 1; j >= 0; --j)
        {
            BlockPos blockpos1 = (BlockPos)list2.get(j);
            IBlockState iblockstate = worldIn.getBlockState(blockpos1);
            iblockstate.getBlock().dropBlockAsItem(worldIn, blockpos1, iblockstate, 0);
            worldIn.setBlockState(blockpos1, Blocks.AIR.getDefaultState(), 4);
            --k;
            aiblockstate[k] = iblockstate;
        }

        for (int l = list.size() - 1; l >= 0; --l)
        {
            BlockPos blockpos3 = (BlockPos)list.get(l);
            IBlockState iblockstate2 = worldIn.getBlockState(blockpos3);
            worldIn.setBlockState(blockpos3, Blocks.AIR.getDefaultState(), 2);
            blockpos3 = blockpos3.offset(enumfacing);
            worldIn.setBlockState(blockpos3, Blocks.PISTON_EXTENSION.getDefaultState().withProperty(FACING, direction), 4);
            worldIn.setTileEntity(blockpos3, BlockPistonMoving.createTilePiston((IBlockState)list1.get(l), direction, extending, false));
            --k;
            aiblockstate[k] = iblockstate2;
        }

        BlockPos blockpos2 = pos.offset(direction);

        if (extending)
        {
            BlockPistonExtension.EnumPistonType blockpistonextension$enumpistontype = this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT;
            IBlockState iblockstate3 = Blocks.PISTON_HEAD.getDefaultState().withProperty(BlockPistonExtension.FACING, direction).withProperty(BlockPistonExtension.TYPE, blockpistonextension$enumpistontype);
            IBlockState iblockstate1 = Blocks.PISTON_EXTENSION.getDefaultState().withProperty(BlockPistonMoving.FACING, direction).withProperty(BlockPistonMoving.TYPE, this.isSticky ? BlockPistonExtension.EnumPistonType.STICKY : BlockPistonExtension.EnumPistonType.DEFAULT);
            worldIn.setBlockState(blockpos2, iblockstate1, 4);
            worldIn.setTileEntity(blockpos2, BlockPistonMoving.createTilePiston(iblockstate3, direction, true, true));
        }

        for (int i1 = list2.size() - 1; i1 >= 0; --i1)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list2.get(i1), aiblockstate[k++].getBlock(), false);
        }

        for (int j1 = list.size() - 1; j1 >= 0; --j1)
        {
            worldIn.notifyNeighborsOfStateChange((BlockPos)list.get(j1), aiblockstate[k++].getBlock(), false);
        }

        if (extending)
        {
            worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.PISTON_HEAD, false);
        }

        return true;
    }
}