Search in sources :

Example 1 with IAugment

use of minechem.item.augment.augments.IAugment in project Minechem by iopleke.

the class AugmentedItem method getAugments.

@Override
public Map<IAugment, Integer> getAugments(ItemStack stack) {
    Map<IAugment, Integer> result = new HashMap<IAugment, Integer>();
    if (stack.hasTagCompound() && stack.getTagCompound().hasKey(augmentList, Compendium.NBTTags.tagList)) {
        NBTTagList augments = stack.getTagCompound().getTagList(augmentList, Compendium.NBTTags.tagString);
        for (int i = 0; i < augments.tagCount(); i++) {
            String key = augments.getStringTagAt(i);
            result.put(AugmentRegistry.getAugment(key), (int) stack.getTagCompound().getCompoundTag(key).getByte(level));
        }
    }
    return result;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) HashMap(java.util.HashMap) IAugment(minechem.item.augment.augments.IAugment) NBTTagString(net.minecraft.nbt.NBTTagString)

Example 2 with IAugment

use of minechem.item.augment.augments.IAugment in project Minechem by iopleke.

the class AugmentedItem method setAugment.

/**
     * Set {@link minechem.item.augment.augments.IAugment} on Item
     *
     * @param item        ItemStack to add augment to
     * @param augmentItem Augment to add
     */
@Override
public boolean setAugment(ItemStack item, ItemStack augmentItem) {
    IAugment augment = AugmentRegistry.getAugment(augmentItem);
    if (augment == null) {
        return false;
    }
    if (!item.hasTagCompound()) {
        item.setTagCompound(new NBTTagCompound());
    }
    NBTTagCompound tagCompound = item.getTagCompound();
    String augmentKey = augment.getKey();
    if (!tagCompound.hasKey(augmentKey, Compendium.NBTTags.tagCompound)) {
        NBTTagList augments = tagCompound.getTagList(augmentList, Compendium.NBTTags.tagString);
        augments.appendTag(new NBTTagString(augmentKey));
        tagCompound.setTag(augmentList, augments);
        NBTTagCompound augmentTag = new NBTTagCompound();
        augmentTag.setTag(Compendium.NBTTags.item, augmentItem.writeToNBT(new NBTTagCompound()));
        augmentTag.setByte(this.level, (byte) 0);
        tagCompound.setTag(augmentKey, augmentTag);
        return true;
    }
    return false;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) IAugment(minechem.item.augment.augments.IAugment) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) NBTTagString(net.minecraft.nbt.NBTTagString) NBTTagString(net.minecraft.nbt.NBTTagString)

Aggregations

IAugment (minechem.item.augment.augments.IAugment)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 NBTTagString (net.minecraft.nbt.NBTTagString)2 HashMap (java.util.HashMap)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1