minecraft-source/src/net/minecraft/world/item/ElytraItem.java

43 lines
1.6 KiB
Java

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"), (bek, bjt, akw) -> isFlyEnabled(bek) ? 0.0f : 1.0f);
DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
}
public static boolean isFlyEnabled(final ItemStack bek) {
return bek.getDamageValue() < bek.getMaxDamage() - 1;
}
@Override
public boolean isValidRepairItem(final ItemStack bek1, final ItemStack bek2) {
return bek2.getItem() == Items.PHANTOM_MEMBRANE;
}
@Override
public InteractionResultHolder<ItemStack> use(final Level bjt, final Player ayg, final InteractionHand ajh) {
final ItemStack bek5 = ayg.getItemInHand(ajh);
final EquipmentSlot aks6 = Mob.getEquipmentSlotForItem(bek5);
final ItemStack bek6 = ayg.getItemBySlot(aks6);
if (bek6.isEmpty()) {
ayg.setItemSlot(aks6, bek5.copy());
bek5.setCount(0);
return InteractionResultHolder.<ItemStack>success(bek5);
}
return InteractionResultHolder.<ItemStack>fail(bek5);
}
}