package net.minecraft.world.item;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.block.DispenserBlock;
import net.minecraft.resources.ResourceLocation;

public class ElytraItem extends Item {
    public ElytraItem(final Properties a) {
        super(a);
        this.addProperty(new ResourceLocation("broken"), (ben, bjw, akz) -> isFlyEnabled(ben) ? 0.0f : 1.0f);
        DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
    }
    
    public static boolean isFlyEnabled(final ItemStack ben) {
        return ben.getDamageValue() < ben.getMaxDamage() - 1;
    }
    
    @Override
    public boolean isValidRepairItem(final ItemStack ben1, final ItemStack ben2) {
        return ben2.getItem() == Items.PHANTOM_MEMBRANE;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        final EquipmentSlot akv6 = Mob.getEquipmentSlotForItem(ben5);
        final ItemStack ben6 = ayj.getItemBySlot(akv6);
        if (ben6.isEmpty()) {
            ayj.setItemSlot(akv6, ben5.copy());
            ben5.setCount(0);
            return InteractionResultHolder.<ItemStack>success(ben5);
        }
        return InteractionResultHolder.<ItemStack>fail(ben5);
    }
}
