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 bph1, final Block bph2, final Properties a) {
        super(bph1, bph2, a);
    }
    
    @Override
    public Component getName(final ItemStack ben) {
        if (ben.getItem() == Items.PLAYER_HEAD && ben.hasTag()) {
            String string3 = null;
            final CompoundTag jt4 = ben.getTag();
            if (jt4.contains("SkullOwner", 8)) {
                string3 = jt4.getString("SkullOwner");
            }
            else if (jt4.contains("SkullOwner", 10)) {
                final CompoundTag jt5 = jt4.getCompound("SkullOwner");
                if (jt5.contains("Name", 8)) {
                    string3 = jt5.getString("Name");
                }
            }
            if (string3 != null) {
                return new TranslatableComponent(this.getDescriptionId() + ".named", new Object[] { string3 });
            }
        }
        return super.getName(ben);
    }
    
    @Override
    public boolean verifyTagAfterLoad(final CompoundTag jt) {
        super.verifyTagAfterLoad(jt);
        if (jt.contains("SkullOwner", 8) && !StringUtils.isBlank((CharSequence)jt.getString("SkullOwner"))) {
            GameProfile gameProfile3 = new GameProfile((UUID)null, jt.getString("SkullOwner"));
            gameProfile3 = SkullBlockEntity.updateGameprofile(gameProfile3);
            jt.put("SkullOwner", NbtUtils.writeGameProfile(new CompoundTag(), gameProfile3));
            return true;
        }
        return false;
    }
}
