Zapfox

Untitled

Dec 3rd, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft)
  2. {
  3. if (entityLiving instanceof EntityPlayer)
  4. {
  5. EntityPlayer entityplayer = (EntityPlayer)entityLiving;
  6. boolean flag = entityplayer.capabilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
  7. ItemStack itemstack = this.findAmmo(entityplayer);
  8.  
  9. int i = this.getMaxItemUseDuration(stack) - timeLeft;
  10. i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, entityplayer, i, !itemstack.isEmpty() || flag);
  11. if (i < 0) return;
  12.  
  13. if (!itemstack.isEmpty() || flag)
  14. {
  15. if (itemstack.isEmpty())
  16. {
  17. itemstack = new ItemStack(Items.ARROW);
  18. }
  19.  
  20. float f = getArrowVelocity(i);
  21.  
  22. if ((double)f >= 0.1D)
  23. {
  24. boolean flag1 = entityplayer.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((ItemArrow) itemstack.getItem()).isInfinite(itemstack, stack, entityplayer));
  25.  
  26. if (!worldIn.isRemote)
  27. {
  28. ItemArrow itemarrow = (ItemArrow)(itemstack.getItem() instanceof ItemArrow ? itemstack.getItem() : Items.ARROW);
  29. EntityArrow entityarrow = itemarrow.createArrow(worldIn, itemstack, entityplayer);
  30. entityarrow.shoot(entityplayer, entityplayer.rotationPitch, entityplayer.rotationYaw, 0.0F, f * 3.0F, 1.0F);
  31.  
  32. if (f == 1.0F)
  33. {
  34. entityarrow.setIsCritical(true);
  35. }
  36.  
  37. int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
  38.  
  39. if (j > 0)
  40. {
  41. entityarrow.setDamage(entityarrow.getDamage() + (double)j * 0.5D + 0.5D);
  42. }
  43.  
  44. int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
  45.  
  46. if (k > 0)
  47. {
  48. entityarrow.setKnockbackStrength(k);
  49. }
  50.  
  51. if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0)
  52. {
  53. entityarrow.setFire(100);
  54. }
  55.  
  56. stack.damageItem(1, entityplayer);
  57.  
  58. if (flag1 || entityplayer.capabilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW))
  59. {
  60. entityarrow.pickupStatus = EntityArrow.PickupStatus.CREATIVE_ONLY;
  61. }
  62.  
  63. worldIn.spawnEntity(entityarrow);
  64. }
  65.  
  66. worldIn.playSound((EntityPlayer)null, entityplayer.posX, entityplayer.posY, entityplayer.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
  67.  
  68. if (!flag1 && !entityplayer.capabilities.isCreativeMode)
  69. {
  70. itemstack.shrink(1);
  71.  
  72. if (itemstack.isEmpty())
  73. {
  74. entityplayer.inventory.deleteStack(itemstack);
  75. }
  76. }
  77.  
  78. entityplayer.addStat(StatList.getObjectUseStats(this));
  79. }
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment