Guest User

Untitled

a guest
Aug 8th, 2017
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mod.drakania.items;
  2.  
  3. import com.mod.drakania.DrakaMod;
  4.  
  5. import cpw.mods.fml.relauncher.Side;
  6. import cpw.mods.fml.relauncher.SideOnly;
  7. import net.minecraft.client.renderer.texture.IIconRegister;
  8. import net.minecraft.creativetab.CreativeTabs;
  9. import net.minecraft.enchantment.Enchantment;
  10. import net.minecraft.enchantment.EnchantmentHelper;
  11. import net.minecraft.entity.player.EntityPlayer;
  12. import net.minecraft.entity.projectile.EntityArrow;
  13. import net.minecraft.init.Items;
  14. import net.minecraft.item.EnumAction;
  15. import net.minecraft.item.Item;
  16. import net.minecraft.item.ItemStack;
  17. import net.minecraft.util.IIcon;
  18. import net.minecraft.world.World;
  19. import net.minecraftforge.common.MinecraftForge;
  20. import net.minecraftforge.event.entity.player.ArrowLooseEvent;
  21. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  22.  
  23. public class DrakaBow extends Item
  24. {
  25. public static final String[] drakabowPullIconNameArray = new String[] {"drakapulling_0", "drakapulling_1", "drakapulling_2"};
  26. @SideOnly(Side.CLIENT)
  27. private IIcon[] iconArray;
  28. private static final String __OBFID = "CL_00001777";
  29.  
  30. public DrakaBow()
  31. {
  32. this.maxStackSize = 1;
  33. this.setMaxDamage(500);
  34. this.setCreativeTab(DrakaMod.drakaModTab);
  35. }
  36.  
  37. /**
  38. * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  39. */
  40. public void onPlayerStoppedUsing(ItemStack p_77615_1_, World p_77615_2_, EntityPlayer p_77615_3_, int p_77615_4_)
  41. {
  42. int j = this.getMaxItemUseDuration(p_77615_1_) - p_77615_4_;
  43.  
  44. ArrowLooseEvent event = new ArrowLooseEvent(p_77615_3_, p_77615_1_, j);
  45. MinecraftForge.EVENT_BUS.post(event);
  46. if (event.isCanceled())
  47. {
  48. return;
  49. }
  50. j = event.charge;
  51.  
  52. boolean flag = p_77615_3_.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, p_77615_1_) > 0;
  53.  
  54. if (flag || p_77615_3_.inventory.hasItem(Items.arrow))
  55. {
  56. float f = (float)j / 20.0F;
  57. f = (f * f + f * 2.0F) / 3.0F;
  58.  
  59. if ((double)f < 0.1D)
  60. {
  61. return;
  62. }
  63.  
  64. if (f > 1.0F)
  65. {
  66. f = 1.0F;
  67. }
  68.  
  69. EntityArrow entityarrow = new EntityArrow(p_77615_2_, p_77615_3_, f * 2.0F);
  70.  
  71. if (f == 1.0F)
  72. {
  73. entityarrow.setIsCritical(true);
  74. }
  75.  
  76. int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, p_77615_1_);
  77.  
  78. if (k > 0)
  79. {
  80. entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  81. }
  82.  
  83. int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, p_77615_1_);
  84.  
  85. if (l > 0)
  86. {
  87. entityarrow.setKnockbackStrength(l);
  88. }
  89.  
  90. if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, p_77615_1_) > 0)
  91. {
  92. entityarrow.setFire(100);
  93. }
  94.  
  95. p_77615_1_.damageItem(1, p_77615_3_);
  96. p_77615_2_.playSoundAtEntity(p_77615_3_, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  97.  
  98. if (flag)
  99. {
  100. entityarrow.canBePickedUp = 2;
  101. }
  102. else
  103. {
  104. p_77615_3_.inventory.consumeInventoryItem(Items.arrow);
  105. }
  106.  
  107. if (!p_77615_2_.isRemote)
  108. {
  109. p_77615_2_.spawnEntityInWorld(entityarrow);
  110. }
  111. }
  112. }
  113.  
  114. public ItemStack onEaten(ItemStack p_77654_1_, World p_77654_2_, EntityPlayer p_77654_3_)
  115. {
  116. return p_77654_1_;
  117. }
  118.  
  119. /**
  120. * How long it takes to use or consume an item
  121. */
  122. public int getMaxItemUseDuration(ItemStack p_77626_1_)
  123. {
  124. return 72000;
  125. }
  126.  
  127. /**
  128. * returns the action that specifies what animation to play when the items is being used
  129. */
  130. public EnumAction getItemUseAction(ItemStack p_77661_1_)
  131. {
  132. return EnumAction.bow;
  133. }
  134.  
  135. /**
  136. * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  137. */
  138. public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
  139. {
  140. ArrowNockEvent event = new ArrowNockEvent(p_77659_3_, p_77659_1_);
  141. MinecraftForge.EVENT_BUS.post(event);
  142. if (event.isCanceled())
  143. {
  144. return event.result;
  145. }
  146.  
  147. if (p_77659_3_.capabilities.isCreativeMode || p_77659_3_.inventory.hasItem(Items.arrow))
  148. {
  149. p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
  150. }
  151.  
  152. return p_77659_1_;
  153. }
  154.  
  155. /**
  156. * Return the enchantability factor of the item, most of the time is based on material.
  157. */
  158. public int getItemEnchantability()
  159. {
  160. return 1;
  161. }
  162.  
  163. @SideOnly(Side.CLIENT)
  164. public void registerIcons(IIconRegister p_94581_1_)
  165. {
  166. this.itemIcon = p_94581_1_.registerIcon(this.getIconString() + "_standby");
  167. this.iconArray = new IIcon[drakabowPullIconNameArray.length];
  168.  
  169. for (int i = 0; i < this.iconArray.length; ++i)
  170. {
  171. this.iconArray[i] = p_94581_1_.registerIcon(this.getIconString() + "_" + drakabowPullIconNameArray[i]);
  172. }
  173. }
  174.  
  175. /**
  176. * used to cycle through icons based on their used duration, i.e. for the bow
  177. */
  178. @SideOnly(Side.CLIENT)
  179. public IIcon getItemIconForUseDuration(int p_94599_1_)
  180. {
  181. return this.iconArray[p_94599_1_];
  182. }
  183. }
RAW Paste Data