Search in sources :

Example 1 with SpongeEnchantment

use of org.spongepowered.common.item.enchantment.SpongeEnchantment in project SpongeCommon by SpongePowered.

the class NbtDataUtil method getItemEnchantments.

public static List<Enchantment> getItemEnchantments(ItemStack itemStack) {
    if (!itemStack.isItemEnchanted()) {
        return Collections.emptyList();
    }
    final List<Enchantment> enchantments = Lists.newArrayList();
    final NBTTagList list = itemStack.getEnchantmentTagList();
    for (int i = 0; i < list.tagCount(); i++) {
        final NBTTagCompound compound = list.getCompoundTagAt(i);
        final short enchantmentId = compound.getShort(NbtDataUtil.ITEM_ENCHANTMENT_ID);
        final short level = compound.getShort(NbtDataUtil.ITEM_ENCHANTMENT_LEVEL);
        final EnchantmentType enchantmentType = (EnchantmentType) net.minecraft.enchantment.Enchantment.getEnchantmentByID(enchantmentId);
        if (enchantmentType == null) {
            continue;
        }
        enchantments.add(new SpongeEnchantment(enchantmentType, level));
    }
    return enchantments;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) SpongeEnchantment(org.spongepowered.common.item.enchantment.SpongeEnchantment) EnchantmentType(org.spongepowered.api.item.enchantment.EnchantmentType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Enchantment(org.spongepowered.api.item.enchantment.Enchantment) SpongeEnchantment(org.spongepowered.common.item.enchantment.SpongeEnchantment)

Example 2 with SpongeEnchantment

use of org.spongepowered.common.item.enchantment.SpongeEnchantment in project SpongeCommon by SpongePowered.

the class StoredEnchantmentDataProcessor method getVal.

@Override
protected Optional<List<Enchantment>> getVal(ItemStack entity) {
    if (!entity.hasTagCompound() || !entity.getTagCompound().hasKey(NbtDataUtil.ITEM_STORED_ENCHANTMENTS_LIST, NbtDataUtil.TAG_LIST)) {
        return Optional.empty();
    }
    List<Enchantment> list = Lists.newArrayList();
    NBTTagList tags = entity.getTagCompound().getTagList(NbtDataUtil.ITEM_STORED_ENCHANTMENTS_LIST, NbtDataUtil.TAG_COMPOUND);
    for (int i = 0; i < tags.tagCount(); i++) {
        NBTTagCompound tag = tags.getCompoundTagAt(i);
        list.add(new SpongeEnchantment((EnchantmentType) net.minecraft.enchantment.Enchantment.getEnchantmentByID(tag.getShort(NbtDataUtil.ITEM_ENCHANTMENT_ID)), tag.getShort(NbtDataUtil.ITEM_ENCHANTMENT_LEVEL)));
    }
    return Optional.of(list);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) SpongeEnchantment(org.spongepowered.common.item.enchantment.SpongeEnchantment) EnchantmentType(org.spongepowered.api.item.enchantment.EnchantmentType) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Enchantment(org.spongepowered.api.item.enchantment.Enchantment) SpongeEnchantment(org.spongepowered.common.item.enchantment.SpongeEnchantment)

Aggregations

NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 Enchantment (org.spongepowered.api.item.enchantment.Enchantment)2 EnchantmentType (org.spongepowered.api.item.enchantment.EnchantmentType)2 SpongeEnchantment (org.spongepowered.common.item.enchantment.SpongeEnchantment)2