package net.minecraft.world.item;

import net.minecraft.world.entity.LivingEntity;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.player.Player;
import net.minecraft.network.chat.Component;
import java.util.List;
import javax.annotation.Nullable;
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 ShieldItem extends Item {
    public ShieldItem(final Properties a) {
        super(a);
        this.addProperty(new ResourceLocation("blocking"), (ben, bjw, akz) -> (akz != null && akz.isUsingItem() && akz.getUseItem() == ben) ? 1.0f : 0.0f);
        DispenserBlock.registerBehavior(this, ArmorItem.DISPENSE_ITEM_BEHAVIOR);
    }
    
    @Override
    public String getDescriptionId(final ItemStack ben) {
        if (ben.getTagElement("BlockEntityTag") != null) {
            return this.getDescriptionId() + '.' + getColor(ben).getName();
        }
        return super.getDescriptionId(ben);
    }
    
    @Override
    public void appendHoverText(final ItemStack ben, @Nullable final Level bjw, final List<Component> list, final TooltipFlag bfw) {
        BannerItem.appendHoverTextFromBannerBlockEntityTag(ben, list);
    }
    
    @Override
    public UseAnim getUseAnimation(final ItemStack ben) {
        return UseAnim.BLOCK;
    }
    
    @Override
    public int getUseDuration(final ItemStack ben) {
        return 72000;
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(final Level bjw, final Player ayj, final InteractionHand ajk) {
        final ItemStack ben5 = ayj.getItemInHand(ajk);
        ayj.startUsingItem(ajk);
        return InteractionResultHolder.<ItemStack>consume(ben5);
    }
    
    @Override
    public boolean isValidRepairItem(final ItemStack ben1, final ItemStack ben2) {
        return ItemTags.PLANKS.contains(ben2.getItem()) || super.isValidRepairItem(ben1, ben2);
    }
    
    public static DyeColor getColor(final ItemStack ben) {
        return DyeColor.byId(ben.getOrCreateTagElement("BlockEntityTag").getInt("Base"));
    }
}
