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

The following examples show how to use net.minecraft.world.World#notifyNeighborsOfStateChange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ItemTraverseWoodDoor.java    From CommunityMod with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door, boolean isRightHinge) {
    BlockPos blockpos = pos.offset(facing.rotateY());
    BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
    int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
    int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
    boolean flag = worldIn.getBlockState(blockpos1).getBlock() == door || worldIn.getBlockState(blockpos1.up()).getBlock() == door;
    boolean flag1 = worldIn.getBlockState(blockpos).getBlock() == door || worldIn.getBlockState(blockpos.up()).getBlock() == door;

    if ((!flag || flag1) && j <= i) {
        if (flag1 && !flag || j < i) {
            isRightHinge = false;
        }
    }
    else {
        isRightHinge = true;
    }

    BlockPos blockpos2 = pos.up();
    boolean flag2 = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos2);
    IBlockState iblockstate = door.getDefaultState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, isRightHinge ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(BlockDoor.POWERED, Boolean.valueOf(flag2)).withProperty(BlockDoor.OPEN, Boolean.valueOf(flag2));
    worldIn.setBlockState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2);
    worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2);
    worldIn.notifyNeighborsOfStateChange(pos, door, false);
    worldIn.notifyNeighborsOfStateChange(blockpos2, door, false);
}
 
Example 2
Source File: ItemTraverseWoodDoor.java    From Traverse-Legacy-1-12-2 with MIT License 6 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door, boolean isRightHinge) {
    BlockPos blockpos = pos.offset(facing.rotateY());
    BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
    int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
    int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
    boolean flag = worldIn.getBlockState(blockpos1).getBlock() == door || worldIn.getBlockState(blockpos1.up()).getBlock() == door;
    boolean flag1 = worldIn.getBlockState(blockpos).getBlock() == door || worldIn.getBlockState(blockpos.up()).getBlock() == door;

    if ((!flag || flag1) && j <= i) {
        if (flag1 && !flag || j < i) {
            isRightHinge = false;
        }
    } else {
        isRightHinge = true;
    }

    BlockPos blockpos2 = pos.up();
    boolean flag2 = worldIn.isBlockPowered(pos) || worldIn.isBlockPowered(blockpos2);
    IBlockState iblockstate = door.getDefaultState().withProperty(BlockDoor.FACING, facing).withProperty(BlockDoor.HINGE, isRightHinge ? BlockDoor.EnumHingePosition.RIGHT : BlockDoor.EnumHingePosition.LEFT).withProperty(BlockDoor.POWERED, Boolean.valueOf(flag2)).withProperty(BlockDoor.OPEN, Boolean.valueOf(flag2));
    worldIn.setBlockState(pos, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.LOWER), 2);
    worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockDoor.HALF, BlockDoor.EnumDoorHalf.UPPER), 2);
    worldIn.notifyNeighborsOfStateChange(pos, door, false);
    worldIn.notifyNeighborsOfStateChange(blockpos2, door, false);
}
 
Example 3
Source File: ItemSurgeryChamber.java    From Cyberware with MIT License 5 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door)
{
	BlockPos blockpos = pos.offset(facing.rotateY());
	BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
	int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
	int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
	BlockPos blockpos2 = pos.up();
	
	IBlockState iblockstate = door.getDefaultState().withProperty(BlockSurgeryChamber.FACING, facing).withProperty(BlockSurgeryChamber.OPEN, true);
	worldIn.setBlockState(pos, iblockstate.withProperty(BlockSurgeryChamber.HALF, BlockSurgeryChamber.EnumChamberHalf.LOWER), 2);
	worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockSurgeryChamber.HALF, BlockSurgeryChamber.EnumChamberHalf.UPPER), 2);
	worldIn.notifyNeighborsOfStateChange(pos, door);
	worldIn.notifyNeighborsOfStateChange(blockpos2, door);
}
 
Example 4
Source File: ItemEngineeringTable.java    From Cyberware with MIT License 5 votes vote down vote up
public static void placeDoor(World worldIn, BlockPos pos, EnumFacing facing, Block door)
{
	BlockPos blockpos = pos.offset(facing.rotateY());
	BlockPos blockpos1 = pos.offset(facing.rotateYCCW());
	int i = (worldIn.getBlockState(blockpos1).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos1.up()).isNormalCube() ? 1 : 0);
	int j = (worldIn.getBlockState(blockpos).isNormalCube() ? 1 : 0) + (worldIn.getBlockState(blockpos.up()).isNormalCube() ? 1 : 0);
	BlockPos blockpos2 = pos.up();
	
	IBlockState iblockstate = door.getDefaultState().withProperty(BlockEngineeringTable.FACING, facing);
	worldIn.setBlockState(pos, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.LOWER), 2);
	worldIn.setBlockState(blockpos2, iblockstate.withProperty(BlockEngineeringTable.HALF, BlockEngineeringTable.EnumEngineeringHalf.UPPER), 2);
	worldIn.notifyNeighborsOfStateChange(pos, door);
	worldIn.notifyNeighborsOfStateChange(blockpos2, door);
}
 
Example 5
Source File: BlockButton.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
private void notifyNeighbors(World worldIn, BlockPos pos, EnumFacing facing)
{
    worldIn.notifyNeighborsOfStateChange(pos, this, false);
    worldIn.notifyNeighborsOfStateChange(pos.offset(facing.getOpposite()), this, false);
}
 
Example 6
Source File: BlockPress.java    From AdvancedRocketry with MIT License 4 votes vote down vote up
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);
			// Forge: With our change to how snowballs are dropped this needs to disallow to mimic vanilla behavior.
			float chance = iblockstate.getBlock() instanceof BlockSnow ? -1.0f : 1.0f;
			iblockstate.getBlock().dropBlockAsItemWithChance(worldIn, blockpos1, iblockstate, chance, 0);
			worldIn.setBlockToAir(blockpos1);
			--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 = 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, BlockPistonExtension.EnumPistonType.DEFAULT);
			worldIn.setBlockState(blockpos2, iblockstate1, 4);
			worldIn.setTileEntity(blockpos2, BlockPistonMoving.createTilePiston(iblockstate3, direction, true, false));
		}

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

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

		if (extending)
		{
			worldIn.notifyNeighborsOfStateChange(blockpos2, Blocks.PISTON_HEAD, true);
			worldIn.notifyNeighborsOfStateChange(pos, this, true);
		}

		return true;
	}
}