package net.minecraft.world.item;

import net.minecraft.world.entity.Mob;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;

public class NameTagItem extends Item {
    public NameTagItem(final Properties a) {
        super(a);
    }
    
    @Override
    public InteractionResult interactLivingEntity(final ItemStack bki, final Player bec, final LivingEntity aoy, final InteractionHand anf) {
        if (bki.hasCustomHoverName() && !(aoy instanceof Player)) {
            if (!bec.level.isClientSide && aoy.isAlive()) {
                aoy.setCustomName(bki.getHoverName());
                if (aoy instanceof Mob) {
                    ((Mob)aoy).setPersistenceRequired();
                }
                bki.shrink(1);
            }
            return InteractionResult.sidedSuccess(bec.level.isClientSide);
        }
        return InteractionResult.PASS;
    }
}
