    001    package net.minecraft.src;
    002
    003    import net.minecraftforge.common.MinecraftForge;
    004    import net.minecraftforge.event.entity.player.ArrowLooseEvent;
    005    import net.minecraftforge.event.entity.player.ArrowNockEvent;
    006
    007    public class ItemBow extends Item
    008    {
    009        public ItemBow(int par1)
    010        {
    011            super(par1);
    012            this.maxStackSize = 1;
    013            this.setMaxDamage(384);
    014            this.setCreativeTab(CreativeTabs.tabCombat);
    015        }
    016
    017        /**
    018         * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
    019         */
    020        public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
    021        {
    022            int var6 = this.getMaxItemUseDuration(par1ItemStack) - par4;
    023
    024            ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, var6);
    025            MinecraftForge.EVENT_BUS.post(event);
    026            if (event.isCanceled())
    027            {
    028                return;
    029            }
    030            var6 = event.charge;
    031
    032            boolean var5 = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
    033
    034            if (var5 || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex))
    035            {
    036                float var7 = (float)var6 / 20.0F;
    037                var7 = (var7 * var7 + var7 * 2.0F) / 3.0F;
    038
    039                if ((double)var7 < 0.1D)
    040                {
    041                    return;
    042                }
    043
    044                if (var7 > 1.0F)
    045                {
    046                    var7 = 1.0F;
    047                }
    048
    049                EntityArrow var8 = new EntityArrow(par2World, par3EntityPlayer, var7 * 2.0F);
    050
    051                if (var7 == 1.0F)
    052                {
    053                    var8.func_70243_d(true);
    054                }
    055
    056                int var9 = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
    057
    058                if (var9 > 0)
    059                {
    060                    var8.setDamage(var8.getDamage() + (double)var9 * 0.5D + 0.5D);
    061                }
    062
    063                int var10 = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
    064
    065                if (var10 > 0)
    066                {
    067                    var8.setKnockbackStrength(var10);
    068                }
    069
    070                if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
    071                {
    072                    var8.setFire(100);
    073                }
    074
    075                par1ItemStack.damageItem(1, par3EntityPlayer);
    076                par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + var7 * 0.5F);
    077
    078                if (var5)
    079                {
    080                    var8.canBePickedUp = 2;
    081                }
    082                else
    083                {
    084                    par3EntityPlayer.inventory.consumeInventoryItem(Item.arrow.shiftedIndex);
    085                }
    086
    087                if (!par2World.isRemote)
    088                {
    089                    par2World.spawnEntityInWorld(var8);
    090                }
    091            }
    092        }
    093
    094        public ItemStack onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    095        {
    096            return par1ItemStack;
    097        }
    098
    099        /**
    100         * How long it takes to use or consume an item
    101         */
    102        public int getMaxItemUseDuration(ItemStack par1ItemStack)
    103        {
    104            return 72000;
    105        }
    106
    107        /**
    108         * returns the action that specifies what animation to play when the items is being used
    109         */
    110        public EnumAction getItemUseAction(ItemStack par1ItemStack)
    111        {
    112            return EnumAction.bow;
    113        }
    114
    115        /**
    116         * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
    117         */
    118        public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    119        {
    120            ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
    121            MinecraftForge.EVENT_BUS.post(event);
    122            if (event.isCanceled())
    123            {
    124                return event.result;
    125            }
    126
    127            if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Item.arrow.shiftedIndex))
    128            {
    129                par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
    130            }
    131
    132            return par1ItemStack;
    133        }
    134
    135        /**
    136         * Return the enchantability factor of the item, most of the time is based on material.
    137         */
    138        public int getItemEnchantability()
    139        {
    140            return 1;
    141        }
    142    }