| 1 | package net.minecraft.item;
|
| 2 |
|
| 3 | import net.minecraft.creativetab.CreativeTabs;
|
| 4 | import net.minecraft.enchantment.Enchantment;
|
| 5 | import net.minecraft.enchantment.EnchantmentHelper;
|
| 6 | import net.minecraft.entity.player.EntityPlayer;
|
| 7 | import net.minecraft.entity.projectile.EntityArrow;
|
| 8 | import net.minecraft.init.Items;
|
| 9 | import net.minecraft.stats.StatList;
|
| 10 | import net.minecraft.world.World;
|
| 11 |
|
| 12 | public class ItemBow extends Item
|
| 13 | {
|
| 14 | public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2"};
|
| 15 |
|
| 16 | public ItemBow()
|
| 17 | {
|
| 18 | this.maxStackSize = 1;
|
| 19 | this.setMaxDamage(384);
|
| 20 | this.setCreativeTab(CreativeTabs.tabCombat);
|
| 21 | }
|
| 22 |
|
| 23 | /**
|
| 24 | * Called when the player stops using an Item (stops holding the right mouse button).
|
| 25 | */
|
| 26 | public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityPlayer playerIn, int timeLeft)
|
| 27 | {
|
| 28 | boolean flag = playerIn.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, stack) > 0;
|
| 29 |
|
| 30 | if (flag || playerIn.inventory.hasItem(Items.arrow))
|
| 31 | {
|
| 32 | int i = this.getMaxItemUseDuration(stack) - timeLeft;
|
| 33 | float f = (float)i / 20.0F;
|
| 34 | f = (f * f + f * 2.0F) / 3.0F;
|
| 35 |
|
| 36 | if ((double)f < 0.1D)
|
| 37 | {
|
| 38 | return;
|
| 39 | }
|
| 40 |
|
| 41 | if (f > 1.0F)
|
| 42 | {
|
| 43 | f = 1.0F;
|
| 44 | }
|
| 45 |
|
| 46 | EntityArrow entityarrow = new EntityArrow(worldIn, playerIn, f * 2.0F);
|
| 47 |
|
| 48 | if (f == 1.0F)
|
| 49 | {
|
| 50 | entityarrow.setIsCritical(true);
|
| 51 | }
|
| 52 |
|
| 53 | int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, stack);
|
| 54 |
|
| 55 | if (j > 0)
|
| 56 | {
|
| 57 | entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
|
| 58 | }
|
| 59 |
|
| 60 | int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, stack);
|
| 61 |
|
| 62 | if (k > 0)
|
| 63 | {
|
| 64 | entityarrow.setKnockbackStrength(k);
|
| 65 | }
|
| 66 |
|
| 67 | if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, stack) > 0)
|
| 68 | {
|
| 69 | entityarrow.setFire(100);
|
| 70 | }
|
| 71 |
|
| 72 | stack.damageItem(1, playerIn);
|
| 73 | worldIn.playSoundAtEntity(playerIn, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
|
| 74 |
|
| 75 | if (flag)
|
| 76 | {
|
| 77 | entityarrow.canBePickedUp = 2;
|
| 78 | }
|
| 79 | else
|
| 80 | {
|
| 81 | playerIn.inventory.consumeInventoryItem(Items.arrow);
|
| 82 | }
|
| 83 |
|
| 84 | playerIn.triggerAchievement(StatList.objectUseStats[Item.getIdFromItem(this)]);
|
| 85 |
|
| 86 | if (!worldIn.isRemote)
|
| 87 | {
|
| 88 | worldIn.spawnEntityInWorld(entityarrow);
|
| 89 | }
|
| 90 | }
|
| 91 | }
|
| 92 |
|
| 93 | /**
|
| 94 | * Called when the player finishes using this Item (E.g. finishes eating.). Not called when the player stops using
|
| 95 | * the Item before the action is complete.
|
| 96 | */
|
| 97 | public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityPlayer playerIn)
|
| 98 | {
|
| 99 | return stack;
|
| 100 | }
|
| 101 |
|
| 102 | /**
|
| 103 | * How long it takes to use or consume an item
|
| 104 | */
|
| 105 | public int getMaxItemUseDuration(ItemStack stack)
|
| 106 | {
|
| 107 | return 72000;
|
| 108 | }
|
| 109 |
|
| 110 | /**
|
| 111 | * returns the action that specifies what animation to play when the items is being used
|
| 112 | */
|
| 113 | public EnumAction getItemUseAction(ItemStack stack)
|
| 114 | {
|
| 115 | return EnumAction.BOW;
|
| 116 | }
|
| 117 |
|
| 118 | /**
|
| 119 | * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
|
| 120 | */
|
| 121 | public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
|
| 122 | {
|
| 123 | if (playerIn.capabilities.isCreativeMode || playerIn.inventory.hasItem(Items.arrow))
|
| 124 | {
|
| 125 | playerIn.setItemInUse(itemStackIn, this.getMaxItemUseDuration(itemStackIn));
|
| 126 | }
|
| 127 |
|
| 128 | return itemStackIn;
|
| 129 | }
|
| 130 |
|
| 131 | /**
|
| 132 | * Return the enchantability factor of the item, most of the time is based on material.
|
| 133 | */
|
| 134 | public int getItemEnchantability()
|
| 135 | {
|
| 136 | return 1;
|
| 137 | }
|
| 138 | }
|
| 139 |
|