Guest User

DO NOT COPY

a guest
May 28th, 2014
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. package com.sear.tutorial.tools;
  2.  
  3. import com.sear.tutorial.Tutorial;
  4. import com.sear.tutorial.entity.EntityRubyArrow;
  5.  
  6. import net.minecraft.block.material.Material;
  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. import cpw.mods.fml.relauncher.Side;
  23. import cpw.mods.fml.relauncher.SideOnly;
  24.  
  25. public class ItemRubyBow extends Item
  26. {
  27. public static final String[] bowPullIconNameArray = new String[] {"pulling_0", "pulling_1", "pulling_2","pulling_3"};
  28. @SideOnly(Side.CLIENT)
  29. private IIcon[] iconArray;
  30. private static final String __OBFID = "CL_00001777";
  31.  
  32. public ItemRubyBow()
  33. {
  34.  
  35. this.maxStackSize = 1;
  36. this.setMaxDamage(384);
  37. this.setCreativeTab(CreativeTabs.tabCombat);
  38. setUnlocalizedName("ItemRubyBow");
  39. setTextureName(Tutorial.MODID + ":" + getUnlocalizedName().substring(5));
  40. }
  41.  
  42. /**
  43. * called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
  44. */
  45. public void onPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
  46. {
  47. int j = this.getMaxItemUseDuration(par1ItemStack) - par4;
  48.  
  49. ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, par1ItemStack, j);
  50. MinecraftForge.EVENT_BUS.post(event);
  51. if (event.isCanceled())
  52. {
  53. return;
  54. }
  55. j = event.charge;
  56.  
  57. boolean flag = par3EntityPlayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantment.infinity.effectId, par1ItemStack) > 0;
  58.  
  59. if (flag || par3EntityPlayer.inventory.hasItem(Tutorial.RubyArrow))
  60. {
  61. float f = (float)j / 20.0F;
  62. f = (f * f + f * 2.0F) / 3.0F;
  63.  
  64. if ((double)f < 0.1D)
  65. {
  66. return;
  67. }
  68.  
  69. if (f > 1.0F)
  70. {
  71. f = 1.0F;
  72. }
  73.  
  74. EntityRubyArrow entityarrow = new EntityRubyArrow(par2World, par3EntityPlayer, f * 2.0F);
  75.  
  76. if (f == 1.0F)
  77. {
  78. entityarrow.setIsCritical(true);
  79. }
  80.  
  81. int k = EnchantmentHelper.getEnchantmentLevel(Enchantment.power.effectId, par1ItemStack);
  82.  
  83. if (k > 0)
  84. {
  85. entityarrow.setDamage(entityarrow.getDamage() + (double)k * 0.5D + 0.5D);
  86. }
  87.  
  88. int l = EnchantmentHelper.getEnchantmentLevel(Enchantment.punch.effectId, par1ItemStack);
  89.  
  90. if (l > 0)
  91. {
  92. entityarrow.setKnockbackStrength(0);
  93. }
  94.  
  95. if (EnchantmentHelper.getEnchantmentLevel(Enchantment.flame.effectId, par1ItemStack) > 0)
  96. {
  97. entityarrow.setFire(100);
  98. }
  99.  
  100. par1ItemStack.damageItem(1, par3EntityPlayer);
  101. par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  102.  
  103. if (flag)
  104. {
  105. entityarrow.canBePickedUp = 2;
  106. }
  107. else
  108. {
  109. par3EntityPlayer.inventory.consumeInventoryItem(Tutorial.RubyArrow);
  110. }
  111.  
  112. if (!par2World.isRemote)
  113. {
  114. par2World.spawnEntityInWorld(entityarrow);
  115. }
  116. }
  117. }
  118.  
  119. public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  120. {
  121. return par1ItemStack;
  122. }
  123.  
  124. /**
  125. * How long it takes to use or consume an item
  126. */
  127. public int getMaxItemUseDuration(ItemStack par1ItemStack)
  128. {
  129. return 72000;
  130. }
  131.  
  132. /**
  133. * returns the action that specifies what animation to play when the items is being used
  134. */
  135. public EnumAction getItemUseAction(ItemStack par1ItemStack)
  136. {
  137. return EnumAction.bow;
  138. }
  139.  
  140. /**
  141. * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  142. */
  143. public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
  144. {
  145. ArrowNockEvent event = new ArrowNockEvent(par3EntityPlayer, par1ItemStack);
  146. MinecraftForge.EVENT_BUS.post(event);
  147. if (event.isCanceled())
  148. {
  149. return event.result;
  150. }
  151.  
  152. if (par3EntityPlayer.capabilities.isCreativeMode || par3EntityPlayer.inventory.hasItem(Tutorial.RubyArrow))
  153. {
  154. par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
  155. }
  156.  
  157. return par1ItemStack;
  158. }
  159.  
  160. /**
  161. * Return the enchantability factor of the item, most of the time is based on material.
  162. */
  163. public int getItemEnchantability()
  164. {
  165. return 20;
  166. }
  167.  
  168. @SideOnly(Side.CLIENT)
  169. public void registerIcons(IIconRegister par1IconRegister)
  170. {
  171. this.itemIcon = par1IconRegister.registerIcon(this.getIconString() + "_standby");
  172. this.iconArray = new IIcon[bowPullIconNameArray.length];
  173.  
  174. for (int i = 0; i < this.iconArray.length; ++i)
  175. {
  176. this.iconArray[i] = par1IconRegister.registerIcon(this.getIconString() + "_" + bowPullIconNameArray[i]);
  177. }
  178.  
  179. }
  180.  
  181. /**
  182. * used to cycle through icons based on their used duration, i.e. for the bow
  183. */
  184. @SideOnly(Side.CLIENT)
  185. public IIcon getItemIconForUseDuration(int par1)
  186. {
  187. return this.iconArray[par1];
  188. }
  189.  
  190. }
Advertisement
Add Comment
Please, Sign In to add comment