Advertisement
sarxJava

SaddledTailSpearItem

Jul 29th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. package net.msrandom.wings.item;
  2.  
  3. import net.minecraft.block.BlockState;
  4. import net.minecraft.enchantment.EnchantmentHelper;
  5. import net.minecraft.entity.LivingEntity;
  6. import net.minecraft.entity.MoverType;
  7. import net.minecraft.entity.player.PlayerEntity;
  8. import net.minecraft.entity.projectile.AbstractArrowEntity;
  9. import net.minecraft.inventory.EquipmentSlotType;
  10. import net.minecraft.item.Item;
  11. import net.minecraft.item.ItemStack;
  12. import net.minecraft.item.TridentItem;
  13. import net.minecraft.item.UseAction;
  14. import net.minecraft.stats.Stats;
  15. import net.minecraft.util.*;
  16. import net.minecraft.util.math.BlockPos;
  17. import net.minecraft.util.math.MathHelper;
  18. import net.minecraft.util.math.Vec3d;
  19. import net.minecraft.world.World;
  20. import net.msrandom.wings.entity.item.SaddledTailSpearEntity;
  21.  
  22. public class SaddledTailSpearItem extends TridentItem {
  23. public SaddledTailSpearItem(Item.Properties builder) {
  24. super(builder);
  25. }
  26.  
  27.  
  28. @Override
  29. public boolean canPlayerBreakBlockWhileHolding(BlockState state, World worldIn, BlockPos pos, PlayerEntity player) {
  30. return !player.isCreative();
  31. }
  32.  
  33. @Override
  34. public UseAction getUseAction(ItemStack stack) {
  35. return UseAction.SPEAR;
  36. }
  37.  
  38. @Override
  39. public int getUseDuration(ItemStack stack) {
  40. return 72000;
  41. }
  42.  
  43. @Override
  44. public void onPlayerStoppedUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
  45. if (entityLiving instanceof PlayerEntity) {
  46. PlayerEntity playerEntity = (PlayerEntity) entityLiving;
  47. int i = this.getUseDuration(stack) - timeLeft;
  48. if (i >= 10) {
  49. int j = EnchantmentHelper.getRiptideModifier(stack);
  50. if (j <= 0 || playerEntity.isWet()) {
  51. if (!worldIn.isRemote) {
  52. stack.damageItem(1, playerEntity, playerEntity1 -> {
  53. playerEntity1.sendBreakAnimation(entityLiving.getActiveHand());
  54. });
  55. if (j == 0) {
  56. SaddledTailSpearEntity saddledTailSpearEntity = new SaddledTailSpearEntity(worldIn, playerEntity, stack);
  57. saddledTailSpearEntity.shoot(playerEntity, playerEntity.rotationPitch, playerEntity.rotationYaw, 0.0F, 2.5F + (float) i * 0.5F, 1.0F);
  58. if (playerEntity.abilities.isCreativeMode) {
  59. saddledTailSpearEntity.pickupStatus = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
  60. }
  61.  
  62. worldIn.addEntity(saddledTailSpearEntity);
  63. worldIn.playMovingSound((PlayerEntity) null, saddledTailSpearEntity, SoundEvents.ITEM_TRIDENT_THROW, SoundCategory.PLAYERS, 1.0F, 1.0F);
  64. if (!playerEntity.abilities.isCreativeMode) {
  65. playerEntity.inventory.deleteStack(stack);
  66.  
  67. }
  68.  
  69. }
  70.  
  71. }
  72.  
  73. }
  74.  
  75. playerEntity.addStat(Stats.ITEM_USED.get(this));
  76. if (j > 0) {
  77. float f7 = playerEntity.rotationYaw;
  78. float f = playerEntity.rotationPitch;
  79. float f1 = -MathHelper.sin(f7 * ((float) Math.PI / 180F)) * MathHelper.cos(f * ((float) Math.PI / 180F));
  80. float f2 = -MathHelper.sin(f * ((float) Math.PI / 180F));
  81. float f3 = MathHelper.cos(f7 * ((float) Math.PI / 180F)) * MathHelper.cos(f * ((float) Math.PI / 180F));
  82. float f4 = MathHelper.sqrt(f1 * f1 + f2 * f2 + f3 * f3);
  83. float f5 = 3.0F * ((1.0F + (float) j) / 4.0F);
  84. f1 = f1 * (f5 / f4);
  85. f2 = f2 * (f5 / f4);
  86. f3 = f3 * (f5 / f4);
  87. playerEntity.addVelocity((double) f1, (double) f2, (double) f3);
  88. playerEntity.startSpinAttack(20);
  89. if (playerEntity.onGround) {
  90. float f6 = 1.1999999F;
  91. playerEntity.move(MoverType.SELF, new Vec3d(0.0D, (double) 1.1999999F, 0.0D));
  92. }
  93. }
  94.  
  95. SoundEvent soundEvent = SoundEvents.ITEM_TRIDENT_RIPTIDE_1;
  96. playerEntity.addStat(Stats.ITEM_USED.get(this));
  97. worldIn.playMovingSound((PlayerEntity) null, playerEntity, soundEvent, SoundCategory.PLAYERS, 1.0F, 1.0F);
  98.  
  99. }
  100. }
  101. }
  102.  
  103. @Override
  104. public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
  105. ItemStack itemStack = playerIn.getHeldItem(handIn);
  106. if (itemStack.getDamage() >= itemStack.getMaxDamage() - 1) {
  107. return ActionResult.resultFail(itemStack);
  108. } else if (EnchantmentHelper.getRiptideModifier(itemStack) > 0 && !playerIn.isWet()) {
  109. return ActionResult.resultFail(itemStack);
  110. } else {
  111. playerIn.setActiveHand(handIn);
  112. return ActionResult.resultConsume(itemStack);
  113. }
  114. }
  115.  
  116. @Override
  117. public boolean hitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker) {
  118. stack.damageItem(1, attacker, livingEntity -> {
  119. livingEntity.sendBreakAnimation(EquipmentSlotType.MAINHAND);
  120. });
  121. return true;
  122. }
  123.  
  124. @Override
  125. public boolean onBlockDestroyed(ItemStack stack, World worldIn, BlockState state, BlockPos pos, LivingEntity entityLiving) {
  126. if ((double) state.getBlockHardness(worldIn, pos) != 0.0D) {
  127. stack.damageItem(2, entityLiving, livingEntity -> {
  128. livingEntity.sendBreakAnimation(EquipmentSlotType.MAINHAND);
  129. });
  130. }
  131. return true;
  132. }
  133. }
  134.  
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement