package net.battlefield;

import net.minecraft.client.Minecraft;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemBow;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Vec3;
import net.minecraft.src.World;

    public class BaseItemGun extends ItemBow
    {
        int acc;
        int sacc;
        float recoil;
        double damage;
        
        public BaseItemGun(int i, int j, int k, int l, float f, double damage1)
        {
            super(i);
            maxStackSize = 1;
            setMaxDamage(l);
            acc = j;
            sacc = k;
            recoil = f;
            damage = damage1;
            this.setCreativeTab(CreativeTabs.tabCombat);
        }
 
        public ItemStack onItemRightClick(ItemStack itemstack, World world, EntityPlayer entityplayer)
        {
            Vec3 vec3d = entityplayer.getLookVec();
            float f = recoil;
            double d1;
            double d2;
            double d3;
            if (entityplayer.isSneaking())
            {
                d1 = (double)sacc * vec3d.xCoord;
                d2 = (double)sacc * vec3d.yCoord;
                d3 = (double)sacc * vec3d.zCoord;
                f /= 3F;
            }
            else
            {
                d1 = (double)acc * vec3d.xCoord;
                d2 = (double)acc * vec3d.yCoord;
                d3 = (double)acc * vec3d.zCoord;
            }
            
            for(int i = 0; i < 1; i++)
            {
                if(entityplayer.inventory.hasItem(Battlefield.Ammunition.shiftedIndex))
                {
                	world.spawnParticle("smoke", entityplayer.posX, entityplayer.posY, entityplayer.posZ, 0.0D, 0.10000000000000001D, 0.0D);
                    EntityBullet entitybullet = new EntityBullet(world, entityplayer, 100, damage);
                    world.spawnEntityInWorld(entitybullet);
                    entityplayer.inventory.consumeInventoryItem(Battlefield.Ammunition.shiftedIndex);
                    itemstack.damageItem(1, entityplayer);
                    entityplayer.rotationPitch -= f;

                    if (world.isRemote)
                    {
	                	Minecraft mc = Minecraft.getMinecraft();
	                    mc.sndManager.playSoundFX("bfsounds.Gunshot", 1.0F, 1.0F);
                    }
                }
            }
            return itemstack;
        }
        
    	public String getTextureFile()
    	{
    		return "/battlefield/items.png";
    	}
    }