package hmggirlfront.block;

import javax.annotation.Nullable;

import hmggirlfront.mod_GirlFront;
import hmggirlfront.block.tile.TileEntity_Goods;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class Block_Goods extends BlockContainer
{

	private int id;
	
    public Block_Goods(int i)
    {
    	super(Material.ROCK);
        this.id = i;
        //this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(DAMAGE, Integer.valueOf(0)));
        if(i == 0){
        	setHardness(5.0F);
        	setSoundType(SoundType.STONE);
        	setResistance(100.0F);
        }else{
        setHardness(1.0F);
        setSoundType(SoundType.STONE);
        setResistance(1.0F);
        }
        //setLightOpacity(1);
        //setLightLevel(1.0F);
    }
    
    public void harvestBlock(World worldIn, EntityPlayer player, BlockPos pos, IBlockState state, @Nullable TileEntity te, @Nullable ItemStack stack){}
    
    @Override
    public void breakBlock(World worldIn, BlockPos pos, IBlockState state){
    	int ra = worldIn.rand.nextInt(2);
    	int ra2 = worldIn.rand.nextInt(6);
    	int ra3 = worldIn.rand.nextInt(8);
    	
    	boolean x_pos = false;
        boolean z_pos = false;
        
        int x = pos.getX();
        int y= pos.getY();
        int z = pos.getZ();
        if(x %5 == 0) {
        	x_pos = true;
        }
        if(z %5 == 0) {
        	z_pos = true;
        }
    	
    	if(worldIn.getBlockState(pos).getBlock() == mod_GirlFront.b_goods_ibc01_break && !x_pos && !z_pos) {
    		{
        		if(ra == 0){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.idoll_bullet));
            	}
        	}
        	{
        		if(ra2 == 0){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.idoll_food));
            	}
        		if(ra2 == 1){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.idoll_hp));
            	}
        		if(ra2 == 2){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.idoll_bullet));
            	}
        		if(ra2 == 3){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.idoll_parts));
            	}
        	}
        	{
        		if(ra3 == 0){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.dollgun_m1911));
            	}
        		if(ra3 == 1){
        			spawnAsEntity(worldIn, pos, new ItemStack(mod_GirlFront.dollgun_vz61));
            	}
        	}
    	}else {
    		for(int yy = 0; yy< ra2+5; ++yy){
    			spawnAsEntity(worldIn, pos, new ItemStack(Items.IRON_INGOT));
    		}
    	}
    }
    @Override
	public TileEntity createNewTileEntity(World worldIn, int meta) {
		return new TileEntity_Goods();
	}
    
    @SideOnly(Side.CLIENT)
    public BlockRenderLayer getBlockLayer()
    {
        return BlockRenderLayer.CUTOUT;
    }
    
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }

    /**
     * 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;
    }
}