Example #1
0
  public AttributeUtil(ItemStack stack) {
    // Create a CraftItemStack (under the hood)
    this.nmsStack = CraftItemStack.asNMSCopy(stack);

    if (this.nmsStack == null) {
      return;
    }

    // if (nmsStack == null) {
    //	CivLog.error("Couldn't make NMS copyyy of:"+stack);
    // this.nmsStack = CraftItemStack.asNMSCopy(ItemManager.createItemStack(CivData.WOOL, 1));
    //	if (this.nmsStack == null) {
    //	return;
    // }
    //  }

    // Load NBT
    if (nmsStack.getTag() == null) {
      parent = new NBTTagCompound();
      nmsStack.setTag(parent);
    } else {
      parent = nmsStack.getTag();
    }

    // Load attribute list
    if (parent.hasKey("AttributeModifiers")) {
      attributes = parent.getList("AttributeModifiers", NBTStaticHelper.TAG_COMPOUND);
    } else {
      /* No attributes on this item detected. */
      attributes = new NBTTagList();
      parent.set("AttributeModifiers", attributes);
    }
  }
Example #2
0
  /**
   * Retrieve the modified item stack.
   *
   * @return The modified item stack.
   */
  public ItemStack getStack() {
    if (nmsStack == null) {
      return ItemManager.createItemStack(CivData.WOOL, 0);
    }

    if (nmsStack.getTag() != null) {
      if (attributes.size() == 0) {
        parent.remove("AttributeModifiers");
      }
    }

    return CraftItemStack.asCraftMirror(nmsStack);
  }