package hmggirlfront.block;

import java.util.Random;

import javax.annotation.Nullable;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.block.tile.TileEntity_Point;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAreaEffectCloud;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IProjectile;
import net.minecraft.entity.item.EntityTNTPrimed;
import net.minecraft.init.Blocks;
import net.minecraft.init.PotionTypes;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockPoint extends BlockContainer
{
	
	protected static final AxisAlignedBB AABB = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D);
	
    public BlockPoint()
    {
    	super(Material.IRON);
        //setBlockUnbreakable();
        //setLightOpacity(1);
        //setLightLevel(1.0F);
    }
    @Override
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
    	//worldIn.playSound((double)((float)pos.getX() + 0.5F), (double)((float)pos.getY() + 0.5F), (double)((float)pos.getZ() + 0.5F), 
        //		SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 1.0F, 1F, false);
    }
    @Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		return new TileEntity_Point();
	}
    
    
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
    	double ix = pos.getX();
    	double iy = pos.getY();
    	double iz = pos.getZ();
    	
    	for(int xx1 = 0; xx1 < 120; ++xx1) {
			for(int yy1 = 0; yy1 < 120; ++yy1) {
				for(int zz1 = 0; zz1 < 120; ++zz1) {
					if(worldIn.getBlockState(new BlockPos(ix + xx1 -60, iy + yy1 - 60, iz + zz1 - 60)).getBlock() == mod_GirlFront.bdoll_point){
						if(xx1 == 60 && yy1 == 60 && zz1 == 60) {
						}else if (!worldIn.isRemote){
							worldIn.setBlockState(new BlockPos(ix + xx1 -60, iy + yy1 - 60, iz + zz1 - 60), Blocks.AIR.getDefaultState(), 2);
						}
					}
				}
			}
		}
    }
    
    /**
     * Called when this Block is destroyed by an Explosion
     */
   // public void onBlockDestroyedByExplosion(World worldIn, BlockPos pos, Explosion explosionIn)
    public void onBlockExploded(World worldIn, BlockPos pos, Explosion explosion)
    {
       
 			if (!worldIn.isRemote) 
 		    	{
 					worldIn.setBlockToAir(pos);
 				}
    }
    
    /**
     * Called When an Entity Collided with the Block
     */
    public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn)
    {
    	double x = pos.getX();
    	double y = pos.getY();
    	double z = pos.getZ();
    	if (!worldIn.isRemote) 
	    	{
				worldIn.setBlockToAir(pos);
			}
    }
    
    @SideOnly(Side.CLIENT)
    public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
    {
       
    }
    
    @Nullable
    public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
    {
    	return NULL_AABB;
    }
    /**
     * Return an AABB (in world coords!) that should be highlighted when the player is targeting this Block
     */
    @SideOnly(Side.CLIENT)
    public AxisAlignedBB getSelectedBoundingBox(IBlockState state, World worldIn, BlockPos pos)
    {
    	return AABB;
    }
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random random)
    {
        return 0;
    }

    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }

    protected boolean canSilkHarvest()
    {
        return true;
    }
    /**
     * Used to determine ambient occlusion and culling when rebuilding chunks for render
     */
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    /**
     * The type of render function called. 3 for standard block models, 2 for TESR's, 1 for liquids, -1 is no render
     */
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }
}