Search in sources :

Example 1 with PlayerHeadItem

use of net.minecraft.world.item.PlayerHeadItem in project SpongeCommon by SpongePowered.

the class SkullItemStackData method register.

// @formatter:off
public static void register(final DataProviderRegistrator registrator) {
    registrator.asMutable(ItemStack.class).create(Keys.GAME_PROFILE).get(h -> {
        final CompoundTag tag = h.getTagElement(Constants.Item.Skull.ITEM_SKULL_OWNER);
        final GameProfile mcProfile = tag == null ? null : NbtUtils.readGameProfile(tag);
        return mcProfile == null ? null : SpongeGameProfile.of(mcProfile);
    }).set((h, v) -> {
        final com.mojang.authlib.GameProfile mcProfile = SpongeGameProfile.toMcProfile(v);
        final CompoundTag tag = NbtUtils.writeGameProfile(new CompoundTag(), mcProfile);
        h.addTagElement(Constants.Item.Skull.ITEM_SKULL_OWNER, tag);
    }).delete(h -> h.removeTagKey(Constants.Item.Skull.ITEM_SKULL_OWNER)).supports(h -> h.getItem() instanceof PlayerHeadItem);
}
Also used : SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) Keys(org.spongepowered.api.data.Keys) CompoundTag(net.minecraft.nbt.CompoundTag) NbtUtils(net.minecraft.nbt.NbtUtils) Constants(org.spongepowered.common.util.Constants) DataProviderRegistrator(org.spongepowered.common.data.provider.DataProviderRegistrator) GameProfile(com.mojang.authlib.GameProfile) ItemStack(net.minecraft.world.item.ItemStack) PlayerHeadItem(net.minecraft.world.item.PlayerHeadItem) PlayerHeadItem(net.minecraft.world.item.PlayerHeadItem) SpongeGameProfile(org.spongepowered.common.profile.SpongeGameProfile) GameProfile(com.mojang.authlib.GameProfile) GameProfile(com.mojang.authlib.GameProfile) ItemStack(net.minecraft.world.item.ItemStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

GameProfile (com.mojang.authlib.GameProfile)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 NbtUtils (net.minecraft.nbt.NbtUtils)1 ItemStack (net.minecraft.world.item.ItemStack)1 PlayerHeadItem (net.minecraft.world.item.PlayerHeadItem)1 Keys (org.spongepowered.api.data.Keys)1 DataProviderRegistrator (org.spongepowered.common.data.provider.DataProviderRegistrator)1 SpongeGameProfile (org.spongepowered.common.profile.SpongeGameProfile)1 Constants (org.spongepowered.common.util.Constants)1