Advertisement
Guest User

Untitled

a guest
Oct 13th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public class MiniCrossbowItem extends ShootableItem implements IVanishable {
  2.  
  3. public final int cooldownSpeed;
  4. private final int damage;
  5.  
  6. public MiniCrossbowItem(IItemTier tierIn, int cooldownSpeedIn, int damageIn, Item.Properties propertiesIn) {
  7.  
  8. super(propertiesIn);
  9.  
  10. this.cooldownSpeed = cooldownSpeedIn;
  11. this.damage = damageIn;
  12. }
  13.  
  14. @Override
  15. public int getItemStackLimit(ItemStack stack) {
  16. return 1;
  17. }
  18.  
  19. @Override
  20. public Predicate<ItemStack> getInventoryAmmoPredicate() {
  21. return ARROWS;
  22. }
  23.  
  24. @Override
  25. public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
  26. ItemStack itemstack = playerIn.getHeldItem(handIn);
  27.  
  28. Vector3d aim = playerIn.getLookVec();
  29.  
  30. ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : Items.ARROW);
  31. AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerIn);
  32. abstractarrowentity.setDamage(abstractarrowentity.getDamage() + damage);
  33.  
  34. ItemStack arrow = playerIn.findAmmo(itemstack);
  35. CompoundNBT nbt = itemstack.getTag();
  36.  
  37. boolean flag1 = playerIn.abilities.isCreativeMode || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, arrow, playerIn));
  38.  
  39. boolean flag = !playerIn.findAmmo(itemstack).isEmpty();
  40.  
  41. if (!worldIn.isRemote) {
  42. ActionResult<ItemStack> ret = net.minecraftforge.event.ForgeEventFactory.onArrowNock(itemstack, worldIn, playerIn, handIn, flag);
  43. if (ret != null) return ret;
  44.  
  45. if (!playerIn.abilities.isCreativeMode && !flag) {
  46. worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.BLOCK_DISPENSER_FAIL, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  47. } else {
  48. playerIn.setActiveHand(handIn);
  49. abstractarrowentity.shoot(aim.x, aim.y, aim.z, 3.0f, 1.0f);
  50. worldIn.addEntity(abstractarrowentity);
  51. worldIn.playSound((PlayerEntity) null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ITEM_CROSSBOW_SHOOT, SoundCategory.NEUTRAL, 1.0F, 1.5F);
  52.  
  53. if(nbt == null) { nbt = new CompoundNBT(); }
  54. if(nbt.contains("shots")) { nbt.putInt("shots", nbt.getInt("shots") + 1); }
  55. else { nbt.putInt("shots", 1); }
  56. System.out.println(nbt.getInt("shots"));
  57. itemstack.setTag(nbt);
  58.  
  59. }
  60.  
  61.  
  62. if (!playerIn.abilities.isCreativeMode) {
  63. arrow.shrink(1);
  64. if (arrow.isEmpty()) {
  65. playerIn.inventory.deleteStack(arrow);
  66. }
  67. }
  68.  
  69. playerIn.getCooldownTracker().setCooldown(this, cooldownSpeed);
  70.  
  71.  
  72.  
  73. if (flag1 || playerIn.abilities.isCreativeMode && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW)) {
  74. abstractarrowentity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
  75. }
  76. }
  77.  
  78. if (!playerIn.abilities.isCreativeMode && !flag) {
  79. return ActionResult.resultFail(itemstack);
  80. } else {
  81. playerIn.setActiveHand(handIn);
  82.  
  83. if (!playerIn.abilities.isCreativeMode) {
  84. itemstack.damageItem(1, playerIn, (p_220045_0_) -> {
  85. p_220045_0_.sendBreakAnimation(EquipmentSlotType.MAINHAND);
  86. });
  87. }
  88.  
  89. return ActionResult.resultConsume(itemstack);
  90. }
  91.  
  92. }
  93.  
  94. @OnlyIn(Dist.CLIENT)
  95. public void addInformation(ItemStack stack, @Nullable World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) {
  96. super.addInformation(stack, worldIn, tooltip, flagIn);
  97. tooltip.add((new TranslationTextComponent("shots " + stack.getChildTag("shots"))).func_240699_a_(TextFormatting.GRAY));
  98. }
  99.  
  100. @Override
  101. public int func_230305_d_() {
  102. return 8;
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement