|
| 1 | +package nourl.mythicmetals.item.tools; |
| 2 | + |
| 3 | +import net.minecraft.enchantment.EnchantmentHelper; |
| 4 | +import net.minecraft.entity.LivingEntity; |
| 5 | +import net.minecraft.entity.MovementType; |
| 6 | +import net.minecraft.entity.player.PlayerEntity; |
| 7 | +import net.minecraft.item.ItemStack; |
| 8 | +import net.minecraft.item.SwordItem; |
| 9 | +import net.minecraft.item.ToolMaterial; |
| 10 | +import net.minecraft.sound.SoundCategory; |
| 11 | +import net.minecraft.sound.SoundEvents; |
| 12 | +import net.minecraft.stat.Stats; |
| 13 | +import net.minecraft.util.Hand; |
| 14 | +import net.minecraft.util.TypedActionResult; |
| 15 | +import net.minecraft.util.UseAction; |
| 16 | +import net.minecraft.util.math.MathHelper; |
| 17 | +import net.minecraft.util.math.Vec3d; |
| 18 | +import net.minecraft.world.World; |
| 19 | + |
| 20 | +public class TidesingerSword extends SwordItem { |
| 21 | + public static final float TRIDENT_POWER = 3.0f; |
| 22 | + |
| 23 | + public TidesingerSword(ToolMaterial toolMaterial, int attackDamage, float attackSpeed, Settings settings) { |
| 24 | + super(toolMaterial, attackDamage, attackSpeed, settings); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public UseAction getUseAction(ItemStack stack) { |
| 29 | + return UseAction.SPEAR; |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public int getMaxUseTime(ItemStack stack) { |
| 34 | + return 72000; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { |
| 39 | + ItemStack itemStack = user.getStackInHand(hand); |
| 40 | + if (itemStack.getDamage() >= itemStack.getMaxDamage() - 1) { |
| 41 | + return TypedActionResult.fail(itemStack); |
| 42 | + } else if (EnchantmentHelper.getRiptide(itemStack) > 0 && !user.isTouchingWaterOrRain()) { |
| 43 | + return TypedActionResult.fail(itemStack); |
| 44 | + } else if (user.getItemCooldownManager().isCoolingDown(itemStack.getItem())) { |
| 45 | + return TypedActionResult.fail(itemStack); |
| 46 | + } else{ |
| 47 | + user.setCurrentHand(hand); |
| 48 | + return TypedActionResult.consume(itemStack); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) { |
| 54 | + int i = this.getMaxUseTime(stack) - remainingUseTicks; |
| 55 | + if (i >= 10 && user instanceof PlayerEntity playerEntity) { |
| 56 | + if (playerEntity.isTouchingWaterOrRain()) { |
| 57 | + if (!world.isClient) { |
| 58 | + stack.damage(1, playerEntity, p -> p.sendToolBreakStatus(user.getActiveHand())); |
| 59 | + } |
| 60 | + |
| 61 | + playerEntity.incrementStat(Stats.USED.getOrCreateStat(this)); |
| 62 | + float yaw = playerEntity.getYaw(); |
| 63 | + float pitch = playerEntity.getPitch(); |
| 64 | + float h = -MathHelper.sin(yaw * (float) (Math.PI / 180.0)) * MathHelper.cos(pitch * (float) (Math.PI / 180.0)); |
| 65 | + float k = -MathHelper.sin(pitch * (float) (Math.PI / 180.0)); |
| 66 | + float l = MathHelper.cos(yaw * (float) (Math.PI / 180.0)) * MathHelper.cos(pitch * (float) (Math.PI / 180.0)); |
| 67 | + float m = MathHelper.sqrt(h * h + k * k + l * l); |
| 68 | + h *= TRIDENT_POWER / m; |
| 69 | + k *= TRIDENT_POWER / m; |
| 70 | + l *= TRIDENT_POWER / m; |
| 71 | + playerEntity.addVelocity(h, k, l); |
| 72 | + playerEntity.useRiptide(20); |
| 73 | + if (playerEntity.isOnGround()) { |
| 74 | + float o = 1.1999999F; |
| 75 | + playerEntity.move(MovementType.SELF, new Vec3d(0.0, o, 0.0)); |
| 76 | + } |
| 77 | + |
| 78 | + world.playSoundFromEntity(null, playerEntity, SoundEvents.ITEM_TRIDENT_RIPTIDE_3, SoundCategory.PLAYERS, 1.0F, 1.0F); |
| 79 | + playerEntity.getItemCooldownManager().set(stack.getItem(), 80); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments