content: package com.github.alexthe666.iceandfire.item;
  
  import com.github.alexthe666.iceandfire.IceAndFire;
  import com.github.alexthe666.iceandfire.entity.EntityPixieCharge;
  import com.github.alexthe666.iceandfire.entity.IafEntityRegistry;
  import com.github.alexthe666.iceandfire.misc.IafSoundRegistry;
  import net.minecraft.ChatFormatting;
  import net.minecraft.network.chat.Component;
  import net.minecraft.network.chat.TranslatableComponent;
  import net.minecraft.world.InteractionHand;
  import net.minecraft.world.InteractionResult;
  import net.minecraft.world.InteractionResultHolder;
  import net.minecraft.world.entity.player.Player;
  import net.minecraft.world.item.Item;
  import net.minecraft.world.item.ItemStack;
  import net.minecraft.world.item.TooltipFlag;
  import net.minecraft.world.item.enchantment.EnchantmentHelper;
  import net.minecraft.world.item.enchantment.Enchantments;
  import net.minecraft.world.level.Level;
  import org.jetbrains.annotations.NotNull;
  
  import javax.annotation.Nullable;
  import java.util.List;
  
  public class ItemPixieWand extends Item {
  
      public ItemPixieWand() {
          super(new Item.Properties().tab(IceAndFire.TAB_ITEMS).stacksTo(1).durability(500));
      }
  
  
      @Override
      public @NotNull InteractionResultHolder<ItemStack> use(@NotNull Level worldIn, Player playerIn, @NotNull InteractionHand hand) {
          ItemStack itemStackIn = playerIn.getItemInHand(hand);
          boolean flag = playerIn.isCreative() || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, itemStackIn) > 0;
          ItemStack itemstack = this.findAmmo(playerIn);
          playerIn.startUsingItem(hand);
          playerIn.swing(hand);
          if (!itemstack.isEmpty() || flag) {
              boolean flag1 = playerIn.isCreative() || this.isInfinite(itemstack, itemStackIn, playerIn);
              if (!flag1) {
                  itemstack.shrink(1);
                  if (itemstack.isEmpty()) {
                      playerIn.getInventory().removeItem(itemstack);
                  }
              }
              double d2 = playerIn.getLookAngle().x;
              double d3 = playerIn.getLookAngle().y;
              double d4 = playerIn.getLookAngle().z;
              float inaccuracy = 1.0F;
              d2 = d2 + playerIn.getRandom().nextGaussian() * 0.007499999832361937D * inaccuracy;
              d3 = d3 + playerIn.getRandom().nextGaussian() * 0.007499999832361937D * inaccuracy;
              d4 = d4 + playerIn.getRandom().nextGaussian() * 0.007499999832361937D * inaccuracy;
              EntityPixieCharge charge = new EntityPixieCharge(IafEntityRegistry.PIXIE_CHARGE.get(), worldIn, playerIn,
                  d2, d3, d4);
              charge.setPos(playerIn.getX(), playerIn.getY() + 1, playerIn.getZ());
              if (!worldIn.isClientSide) {
                  worldIn.addFreshEntity(charge);
              }
              playerIn.playSound(IafSoundRegistry.PIXIE_WAND, 1F, 0.75F + 0.5F * playerIn.getRandom().nextFloat());
              itemstack.hurtAndBreak(1, playerIn, (player) -> {
                  player.broadcastBreakEvent(playerIn.getUsedItemHand());
              });
              playerIn.getCooldowns().addCooldown(this, 5);
          }
          return new InteractionResultHolder<ItemStack>(InteractionResult.PASS, itemStackIn);
      }
  
      public boolean isInfinite(ItemStack stack, ItemStack bow, net.minecraft.world.entity.player.Player player) {
          int enchant = net.minecraft.world.item.enchantment.EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, bow);
          return enchant > 0 && stack.getItem() == IafItemRegistry.PIXIE_DUST.get();
      }
  
      private ItemStack findAmmo(Player player) {
          if (this.isAmmo(player.getItemInHand(InteractionHand.OFF_HAND))) {
              return player.getItemInHand(InteractionHand.OFF_HAND);
          } else if (this.isAmmo(player.getItemInHand(InteractionHand.MAIN_HAND))) {
              return player.getItemInHand(InteractionHand.MAIN_HAND);
          } else {
              for (int i = 0; i < player.getInventory().getContainerSize(); ++i) {
                  ItemStack itemstack = player.getInventory().getItem(i);
  
                  if (this.isAmmo(itemstack)) {
                      return itemstack;
                  }
              }
  
              return ItemStack.EMPTY;
          }
      }
  
      protected boolean isAmmo(ItemStack stack) {
          return !stack.isEmpty() && stack.getItem() == IafItemRegistry.PIXIE_DUST.get();
      }
  
  
      @Override
      public void appendHoverText(@NotNull ItemStack stack, @Nullable Level worldIn, List<Component> tooltip, @NotNull TooltipFlag flagIn) {
          tooltip.add(new TranslatableComponent("item.iceandfire.legendary_weapon.desc").withStyle(ChatFormatting.GRAY));
          tooltip.add(new TranslatableComponent("item.iceandfire.pixie_wand.desc_0").withStyle(ChatFormatting.GRAY));
          tooltip.add(new TranslatableComponent("item.iceandfire.pixie_wand.desc_1").withStyle(ChatFormatting.GRAY));
      }
  }
  