52 lines
2.0 KiB
Java
52 lines
2.0 KiB
Java
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 bpe1, final Block bpe2, final Properties a) {
|
|
super(bpe1, bpe2, a);
|
|
}
|
|
|
|
@Override
|
|
public Component getName(final ItemStack bek) {
|
|
if (bek.getItem() == Items.PLAYER_HEAD && bek.hasTag()) {
|
|
String string3 = null;
|
|
final CompoundTag jt4 = bek.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(bek);
|
|
}
|
|
|
|
@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;
|
|
}
|
|
}
|