Package cofh.lib.util.helpers

Source Code of cofh.lib.util.helpers.AugmentHelper

package cofh.lib.util.helpers;

import cofh.api.item.IAugmentItem;

import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

public class AugmentHelper {

  private AugmentHelper() {

  }

  /* NBT TAG HELPERS */
  public static void writeAugmentsToNBT(NBTTagCompound nbt, ItemStack[] augments) {

    if (augments.length <= 0) {
      return;
    }
    NBTTagList list = new NBTTagList();
    for (int i = 0; i < augments.length; i++) {
      if (augments[i] != null) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setInteger("Slot", i);
        augments[i].writeToNBT(tag);
        list.appendTag(tag);
      }
    }
    nbt.setTag("Augments", list);
  }

  /* ITEM HELPERS */
  public static void writeAugments(ItemStack stack, ItemStack[] augments) {

    if (augments.length <= 0) {
      return;
    }
    if (stack.stackTagCompound == null) {
      stack.setTagCompound(new NBTTagCompound());
    }
    NBTTagList list = new NBTTagList();
    for (int i = 0; i < augments.length; i++) {
      if (augments[i] != null) {
        NBTTagCompound tag = new NBTTagCompound();
        tag.setInteger("Slot", i);
        augments[i].writeToNBT(tag);
        list.appendTag(tag);
      }
    }
    stack.stackTagCompound.setTag("Augments", list);
  }

  public static boolean isAugmentItem(ItemStack stack) {

    return stack != null && stack.getItem() instanceof IAugmentItem;
  }

}
TOP

Related Classes of cofh.lib.util.helpers.AugmentHelper

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.