package net.minecraft.world.item;

import net.minecraft.nbt.Tag;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.world.level.block.entity.SkullBlockEntity;
import java.util.UUID;
import com.mojang.authlib.GameProfile;
import org.apache.commons.lang3.StringUtils;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Block;

public class PlayerHeadItem extends StandingAndWallBlockItem {
    public PlayerHeadItem(final Block bvr1, final Block bvr2, final Properties a) {
        super(bvr1, bvr2, a);
    }
    
    @Override
    public Component getName(final ItemStack bki) {
        if (bki.getItem() == Items.PLAYER_HEAD && bki.hasTag()) {
            String string3 = null;
            final CompoundTag le4 = bki.getTag();
            if (le4.contains("SkullOwner", 8)) {
                string3 = le4.getString("SkullOwner");
            }
            else if (le4.contains("SkullOwner", 10)) {
                final CompoundTag le5 = le4.getCompound("SkullOwner");
                if (le5.contains("Name", 8)) {
                    string3 = le5.getString("Name");
                }
            }
            if (string3 != null) {
                return new TranslatableComponent(this.getDescriptionId() + ".named", new Object[] { string3 });
            }
        }
        return super.getName(bki);
    }
    
    @Override
    public boolean verifyTagAfterLoad(final CompoundTag le) {
        super.verifyTagAfterLoad(le);
        if (le.contains("SkullOwner", 8) && !StringUtils.isBlank((CharSequence)le.getString("SkullOwner"))) {
            GameProfile gameProfile3 = new GameProfile((UUID)null, le.getString("SkullOwner"));
            gameProfile3 = SkullBlockEntity.updateGameprofile(gameProfile3);
            le.put("SkullOwner", NbtUtils.writeGameProfile(new CompoundTag(), gameProfile3));
            return true;
        }
        return false;
    }
}
