Advertisement
Guest User

Untitled

a guest
Apr 29th, 2021
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. public class BoltcasterItem extends ShootableItem implements IVanishable {
  2.  
  3. private final double damage;
  4. private final int velocity;
  5.  
  6. public BoltcasterItem(double damageIn,int velocityIn, Properties builder) {
  7. super(builder);
  8. this.damage = damageIn;
  9. this.velocity = velocityIn;
  10.  
  11. ItemModelsProperties.registerProperty(this, new ResourceLocation("loaded"), (stack, world, player) -> {
  12. if(player != null)
  13. return player.isHandActive() && player.getActiveItemStack() == stack ? 1.0F : player.findAmmo(stack).getCount();
  14. else
  15. return 0.0F;
  16. });
  17. }
  18. @Override
  19. public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
  20. ItemStack stack = playerIn.getHeldItem(handIn);
  21. boolean flag = playerIn.abilities.isCreativeMode || EnchantmentHelper.getEnchantmentLevel(Enchantments.INFINITY, stack) > 0;
  22. ItemStack arrowstack = playerIn.findAmmo(stack);
  23.  
  24. if (!arrowstack.isEmpty() || flag) {
  25. if (arrowstack.isEmpty()) {
  26. arrowstack = new ItemStack(Items.ARROW);
  27. }
  28. }
  29.  
  30. float f = getArrowVelocity(10 + this.velocity);
  31.  
  32. boolean flag1 = playerIn.abilities.isCreativeMode || (arrowstack.getItem() instanceof ArrowItem && ((ArrowItem) arrowstack.getItem()).isInfinite(arrowstack, stack, playerIn));
  33.  
  34. boolean flag2 = !playerIn.findAmmo(stack).isEmpty();
  35.  
  36. if (!worldIn.isRemote) {
  37. if (!playerIn.abilities.isCreativeMode && !flag2) {
  38. worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.BLOCK_DISPENSER_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  39. } else {
  40.  
  41. ArrowItem arrowitem = (ArrowItem) (arrowstack.getItem() instanceof ArrowItem ? arrowstack.getItem() : Items.ARROW);
  42. AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, arrowstack, playerIn);
  43. abstractarrowentity = customArrow(abstractarrowentity);
  44. abstractarrowentity.func_234612_a_(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, f * 3.0F, 1.0F);
  45. abstractarrowentity.setDamage(abstractarrowentity.getDamage() + this.damage);
  46. if (f == 1.0F) {
  47. abstractarrowentity.setIsCritical(true);
  48. }
  49.  
  50. int j = EnchantmentHelper.getEnchantmentLevel(Enchantments.POWER, stack);
  51. if (j > 0) {
  52. abstractarrowentity.setDamage(abstractarrowentity.getDamage() + (double) j * 0.5D + 0.5D);
  53. }
  54.  
  55. int k = EnchantmentHelper.getEnchantmentLevel(Enchantments.PUNCH, stack);
  56. if (k > 0) {
  57. abstractarrowentity.setKnockbackStrength(k);
  58. }
  59.  
  60. if (EnchantmentHelper.getEnchantmentLevel(Enchantments.FLAME, stack) > 0) {
  61. abstractarrowentity.setFire(100);
  62. }
  63.  
  64. stack.damageItem(1, playerIn, (p_220009_1_) -> {
  65. p_220009_1_.sendBreakAnimation(playerIn.getActiveHand());
  66. });
  67. if (flag1 || playerIn.abilities.isCreativeMode && (arrowstack.getItem() == Items.SPECTRAL_ARROW || arrowstack.getItem() == Items.TIPPED_ARROW)) {
  68. abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
  69. }
  70.  
  71. worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_CROSSBOW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  72. worldIn.addEntity(abstractarrowentity);
  73. }
  74.  
  75. if (!flag1 && !playerIn.abilities.isCreativeMode) {
  76. arrowstack.shrink(1);
  77. if (arrowstack.isEmpty()) {
  78. playerIn.inventory.deleteStack(arrowstack);
  79. }
  80. }
  81. }
  82.  
  83. ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(stack, worldIn, playerIn, handIn, flag);
  84. if (ret != null) return ret;
  85.  
  86. if (!playerIn.abilities.isCreativeMode && !flag2) {
  87.  
  88. stack.getCapability(CoolDownCapability.COOLDOWN_CAPABILITY).map(h -> {
  89. boolean canCoolDown = h.getCanCoolDown();
  90.  
  91. h.getCoolDownTracker().setCooldown(this, 30);
  92.  
  93. ProjectDawn.LOGGER.info("empty side");
  94.  
  95. return canCoolDown;
  96.  
  97. }).orElse(null);
  98.  
  99.  
  100. return ActionResult.resultFail(stack);
  101. } else {
  102. playerIn.setActiveHand(handIn);
  103.  
  104.  
  105. stack.getCapability(CoolDownCapability.COOLDOWN_CAPABILITY).map(h -> {
  106. boolean canCoolDown = h.getCanCoolDown();
  107.  
  108. h.getCoolDownTracker().setCooldown(this, 30);
  109.  
  110. ProjectDawn.LOGGER.info("loaded side");
  111.  
  112. return canCoolDown;
  113.  
  114. }).orElse(null);
  115.  
  116.  
  117. return ActionResult.resultConsume(stack);
  118. }
  119. }
  120.  
  121. @Override
  122. public ICapabilityProvider initCapabilities(ItemStack stack, CompoundNBT nbt) {
  123. if (this.getClass() == BoltcasterItem.class)
  124. return new CoolDownProvider();
  125. else
  126. return super.initCapabilities(stack, nbt);
  127. }
  128.  
  129. public static float getArrowVelocity(int charge) {
  130. float f = (float)charge / 20.0F;
  131. f = (f * f + f * 2.0F) / 3.0F;
  132. if (f > 1.0F) {
  133. f = 1.0F;
  134. }
  135.  
  136. return f;
  137. }
  138. public AbstractArrowEntity customArrow(AbstractArrowEntity arrow) {
  139. return arrow;
  140. }
  141.  
  142. @Override
  143. public Predicate<ItemStack> getInventoryAmmoPredicate() {
  144. return ARROWS;
  145. }
  146.  
  147. @Override
  148. public int func_230305_d_() { return 8; }
  149.  
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement