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;
}
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);
}
Aggregations