package JAKJ . RedstoneInMotion ;

public abstract class WorldUtil
{
	public static void ClearBlock ( net . minecraft . world . World World , int X , int Y , int Z )
	{
		SetBlock ( World , X , Y , Z , 0 , 0 ) ;
	}

	public static void SetBlock ( net . minecraft . world . World World , int X , int Y , int Z , int Id , int Meta )
	{
		World . setBlock ( X , Y , Z , Id , Meta , 0x3 ) ;
	}

	public static void RefreshBlock ( net . minecraft . world . World World , int X , int Y , int Z , int OldId , int NewId )
	{
		UpdateLighting ( World , X , Y , Z ) ;

		NotifyBlocks ( World , X , Y , Z , OldId , NewId ) ;
	}

	public static void NotifyBlocks ( net . minecraft . world . World World , int X , int Y , int Z , int OldId , int NewId )
	{
		World . notifyBlockChange ( X , Y , Z , OldId ) ;

		if ( NewId == 0 )
		{
			return ;
		}

		if ( Block . Get ( NewId ) . hasComparatorInputOverride ( ) )
		{
			World . func_96440_m ( X , Y , Z , NewId ) ;
		}
	}

	public static void SneakySetBlock ( net . minecraft . world . World World , int X , int Y , int Z , int Id , int Meta )
	{
		net . minecraft . world . chunk . Chunk Chunk = World . getChunkFromBlockCoords ( X , Z ) ;

		int ChunkX = X & 0xF ;
		int ChunkY = Y & 0xF ;
		int ChunkZ = Z & 0xF ;

		Chunk . removeChunkBlockTileEntity ( ChunkX , Y , ChunkZ ) ;

		int LayerY = Y >> 4 ;

		if ( Chunk . storageArrays [ LayerY ] == null )
		{
			Chunk . storageArrays [ LayerY ] = new net . minecraft . world . chunk . storage . ExtendedBlockStorage ( ( LayerY ) << 4 , ! World . provider . hasNoSky ) ;
		}

		Chunk . storageArrays [ LayerY ] . setExtBlockID ( ChunkX , ChunkY , ChunkZ , Id ) ;

		Chunk . storageArrays [ LayerY ] . setExtBlockMetadata ( ChunkX , ChunkY , ChunkZ , Meta ) ;

		Chunk . isModified = true ;

		World . markBlockForUpdate ( X , Y , Z ) ;
	}

	/* this is woefully redundant and inefficient */
	public static void UpdateLighting ( net . minecraft . world . World World , int X , int Y , int Z )
	{
		net . minecraft . world . chunk . Chunk Chunk = World . getChunkFromBlockCoords ( X , Z ) ;

		int ChunkX = X & 0xF ;
		int ChunkY = Y & 0xF ;
		int ChunkZ = Z & 0xF ;

		int HeightMapIndex = ChunkZ << 4 | ChunkX ;

		if ( Y >= Chunk . precipitationHeightMap [ HeightMapIndex ] - 1 )
		{
			Chunk . precipitationHeightMap [ HeightMapIndex ] = -999 ;
		}

		int HeightMapValue = Chunk . heightMap [ HeightMapIndex ] ;

		if ( Y >= HeightMapValue )
		{
			Chunk . generateSkylightMap ( ) ;
		}
		else
		{
			if ( Chunk . getBlockLightOpacity ( ChunkX , Y , ChunkZ ) > 0 )
			{
				if ( Y >= HeightMapValue )
				{
					Chunk . relightBlock ( ChunkX , Y + 1 , ChunkZ ) ;
				}
			}
			else if ( Y == HeightMapValue - 1 )
			{
				Chunk . relightBlock ( ChunkX , Y , ChunkZ ) ;
			}

			Chunk . propagateSkylightOcclusion ( ChunkX , ChunkZ ) ;
		}

		World . updateAllLightTypes ( X , Y , Z ) ;
	}
}
