package net.minecraft.block;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Random;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityDaylightDetector;
import net.minecraft.util.IIcon;
import net.minecraft.util.MathHelper;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

public class BlockDaylightDetector extends BlockContainer
{
	private IIcon[] field_149958_a = new IIcon[2];
	private static final String __OBFID = "CL_00000223";

	public BlockDaylightDetector()
	{
		super(Material.wood);
		this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F);
		this.setCreativeTab(CreativeTabs.tabRedstone);
	}

	public void setBlockBoundsBasedOnState(IBlockAccess p_149719_1_, int p_149719_2_, int p_149719_3_, int p_149719_4_)
	{
		this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.375F, 1.0F);
	}

	public int isProvidingWeakPower(IBlockAccess p_149709_1_, int p_149709_2_, int p_149709_3_, int p_149709_4_, int p_149709_5_)
	{
		return p_149709_1_.getBlockMetadata(p_149709_2_, p_149709_3_, p_149709_4_);
	}

	public void updateTick(World p_149674_1_, int p_149674_2_, int p_149674_3_, int p_149674_4_, Random p_149674_5_) {}

	public void onNeighborBlockChange(World p_149695_1_, int p_149695_2_, int p_149695_3_, int p_149695_4_, Block p_149695_5_) {}

	public void onBlockAdded(World p_149726_1_, int p_149726_2_, int p_149726_3_, int p_149726_4_) {}

	public void func_149957_e(World p_149957_1_, int p_149957_2_, int p_149957_3_, int p_149957_4_)
	{
		if (!p_149957_1_.provider.hasNoSky)
		{
			int l = p_149957_1_.getBlockMetadata(p_149957_2_, p_149957_3_, p_149957_4_);
			int i1 = p_149957_1_.getSavedLightValue(EnumSkyBlock.Sky, p_149957_2_, p_149957_3_, p_149957_4_) - p_149957_1_.skylightSubtracted;
			float f = p_149957_1_.getCelestialAngleRadians(1.0F);

			if (f < (float)Math.PI)
			{
				f += (0.0F - f) * 0.2F;
			}
			else
			{
				f += (((float)Math.PI * 2F) - f) * 0.2F;
			}

			i1 = Math.round((float)i1 * MathHelper.cos(f));

			if (i1 < 0)
			{
				i1 = 0;
			}

			if (i1 > 15)
			{
				i1 = 15;
			}

			if (l != i1)
			{
				p_149957_1_.setBlockMetadataWithNotify(p_149957_2_, p_149957_3_, p_149957_4_, i1, 3);
			}
		}
	}

	public boolean renderAsNormalBlock()
	{
		return false;
	}

	public boolean isOpaqueCube()
	{
		return false;
	}

	public boolean canProvidePower()
	{
		return true;
	}

	public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_)
	{
		return new TileEntityDaylightDetector();
	}

	@SideOnly(Side.CLIENT)
	public IIcon getIcon(int p_149691_1_, int p_149691_2_)
	{
		return p_149691_1_ == 1 ? this.field_149958_a[0] : this.field_149958_a[1];
	}

	@SideOnly(Side.CLIENT)
	public void registerBlockIcons(IIconRegister p_149651_1_)
	{
		this.field_149958_a[0] = p_149651_1_.registerIcon(this.getTextureName() + "_top");
		this.field_149958_a[1] = p_149651_1_.registerIcon(this.getTextureName() + "_side");
	}
}