Esempio n. 1
0
  /**
   * Construct a wrapper for an NBT tag stored (in memory) in an item stack. This is where auxillary
   * data such as enchanting, name and lore is stored. It doesn't include the items material, damage
   * value or count.
   *
   * <p>The item stack must be a wrapper for a CraftItemStack. Use {@link
   * MinecraftReflection#getCraftItemStack(ItemStack)} if not.
   *
   * @param stack - the item stack.
   * @return A wrapper for its NBT tag.
   */
  public static NbtWrapper<?> fromItemTag(ItemStack stack) {
    checkItemStack(stack);

    StructureModifier<NbtBase<?>> modifier = getStackModifier(stack);
    NbtBase<?> result = modifier.read(0);

    // Create the tag if it doesn't exist
    if (result == null) {
      result = NbtFactory.ofCompound("tag");
      modifier.write(0, result);
    }
    return fromBase(result);
  }
Esempio n. 2
0
  /**
   * Set the NBT compound tag of a given item stack.
   *
   * <p>The item stack must be a wrapper for a CraftItemStack. Use {@link
   * MinecraftReflection#getCraftItemStack(ItemStack)} if not.
   *
   * @param stack - the item stack, cannot be air.
   * @param compound - the new NBT compound, or NULL to remove it.
   * @throws IllegalArgumentException If the stack is not a CraftItemStack, or it represents air.
   */
  public static void setItemTag(ItemStack stack, NbtCompound compound) {
    checkItemStack(stack);

    StructureModifier<NbtBase<?>> modifier = getStackModifier(stack);
    modifier.write(0, compound);
  }