An IItemStack Object consists of an item definition, a meta/damage value and NBT data.
In other words, it refers to an item or to a block.

Dieses Paket importieren

Link to dieses-paket-importieren

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import.
import crafttweaker.item.IItemStack;

Calling an IItemStack

Link to calling-an-iitemstack

There are several methods that return an IItemStack

Calling an IItemStack[] or a IItemStack List

Link to calling-an-iitemstack-or-a-iitemstack-list

If you call these functions, you will most likely do so to iterate through the resulting lists/Arrays

  • Using the items method on an IIngredient returns a IItemStack List: <ore:ingotGold>.items
  • Using the itemArray method on an IIngredient returns a IItemStack[]: <ore:ingotGold>.itemArray
  • Using the items method on a IMod object returns a IItemStack[]: loadedMods["minecraft"].items

So what can we do with that now?

Extending IIngredient

Link to extending-iingredient

IItemStack extends IIngredient.
That means all functionality that is available to IIngredient objects also is applicable to IItemStacks.

Derived Methods
  • stack.mark
  • stack.amount
  • stack.items
  • stack.itemArray
  • stack.liquids
  • stack.commandString
  • stack | otherIngredient
  • stack.or(otherIngredient)
  • stack.transform(transformer)
  • stack.transformNew(transformer)
  • stack.only(condition)
  • stack.marked(mark)
  • stack.matches(item)
  • stack.matchesExact(item)
  • stack.matches(liquid)
  • stack has ingredient
  • stack.applyTransform(stack,player)
  • stack.hasTransformers()

ZenGetter/ZenSetter

Link to zengetterzensetter

Read how to use them here. Also, check out the examples below.

ZenGetter/ZenMethodZenSetter/ZenMethodType
ZenGetter/ZenMethod
definition
ZenSetter/ZenMethod
Type
IItemDefinition
ZenGetter/ZenMethod
name
ZenSetter/ZenMethod
Type
string
ZenGetter/ZenMethod
displayName
ZenSetter/ZenMethod
displayName
Type
string
ZenGetter/ZenMethod
maxStackSize
ZenSetter/ZenMethod
maxStackSize
Type
int
ZenGetter/ZenMethod
hardness
ZenSetter/ZenMethod
hardness
Type
float
ZenGetter/ZenMethod
damage
ZenSetter/ZenMethod
Type
int
ZenGetter/ZenMethod
maxDamage
ZenSetter/ZenMethod
maxDamage
Type
int
ZenGetter/ZenMethod
hasTag
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
tag
ZenSetter/ZenMethod
withTag(tag)
Type
IData
ZenGetter/ZenMethod
ores
ZenSetter/ZenMethod
Type
List<IOreDictEntry>
ZenGetter/ZenMethod
toolClasses
ZenSetter/ZenMethod
Type
List<string>
ZenGetter/ZenMethod
itemEnchantability
ZenSetter/ZenMethod
Type
int
ZenGetter/ZenMethod
containerItem
ZenSetter/ZenMethod
Type
IItemStack
ZenGetter/ZenMethod
hasContainerItem
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
repairCost
ZenSetter/ZenMethod
repairCost
Type
int
ZenGetter/ZenMethod
canEditBlocks
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isOnItemFrame
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isEnchantable
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isEnchanted
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isDamaged
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isDamageable
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isItemBlock
ZenSetter/ZenMethod
Type
bool (if contained item is an itemblock)
ZenGetter/ZenMethod
isStackable
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isBeaconPayment
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
hasEffect
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
hasDisplayName
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
metadata
ZenSetter/ZenMethod
Type
int
ZenGetter/ZenMethod
hasSubtypes
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
isEmpty
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
burnTime
ZenSetter/ZenMethod
Type
int
ZenGetter/ZenMethod
showsDurabilityBar
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
hasCustomEntity
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
enchantments
ZenSetter/ZenMethod
Type
List<IEnchantment>
ZenGetter/ZenMethod
matchTagExact
ZenSetter/ZenMethod
Type
bool
ZenGetter/ZenMethod
maxItemUseDuration
ZenSetter/ZenMethod
Type
int
ZenGetter/ZenMethod
capNBT
ZenSetter/ZenMethod
Type
IData
MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.anyAmount()
Rückgabewert
A new IItemStack with any amount for recipes
Parameter Typen
Methodenaufruf
stack.amount(int amount)
Rückgabewert
A new IItemStack with the specified amount
Parameter Typen
int
Methodenaufruf
stack.withAmount(int amount)
Rückgabewert
A new IItemStack with the specified amount
Parameter Typen
int
Methodenaufruf
stack * amount
Rückgabewert
A new IItemStack with the specified amount
Parameter Typen
int
Methodenaufruf
stack.splitStack(int amount)
Rückgabewert
The split IItemStack. The old one will be reduced accordingly.
Parameter Typen
int
MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.percent(float chance)
Rückgabewert
A WeightedItemStack
Parameter Typen
float (100 = 100%)
Methodenaufruf
stack.weight(float chance)
Rückgabewert
A WeightedItemStack
Parameter Typen
float (1 = 100%)
MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.anyDamage()
Rückgabewert
A new IItemStack with any damage for recipes
Parameter Typen
Methodenaufruf
stack.withDamage(int damage)
Rückgabewert
A new IItemStack with the specified damage
Parameter Typen
int
Methodenaufruf
stack.damageItem(int amount, IEntity entity)
Rückgabewert
void (nothing)
Parameter Typen
int, IEntity
MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.withEmptyTag()
Rückgabewert
A new IItemStack with an empty NBT tag
Parameter Typen
Methodenaufruf
stack.withTag(IData tag)
Rückgabewert
A new IItemStack with the specified NBT tag
Parameter Typen
IData
Methodenaufruf
stack.withTag(IData-Tag, bool matchTagExact)
Rückgabewert
A new IItemStack with the specified NBT tag
Parameter Typen
IData, bool
Methodenaufruf
stack.removeTag(String-Name)
Rückgabewert
A new IItemStack with the specified NBT tag removed, if it exists
Parameter Typen
string
Methodenaufruf
stack.updateTag(IData Tag)
Rückgabewert
A new IItemStack with the added NBT tag
Parameter Typen
IData
Methodenaufruf
stack.updateTag(IData-Tag, bool matchTagExact)
Rückgabewert
A new IItemStack with the added NBT tag
Parameter Typen
IData, bool
MethodenaufrufRückgabewert
Methodenaufruf
stack.asBlock()
Rückgabewert
A new IBlock object.
Methodenaufruf
stack as IBlock
Rückgabewert
A new IBlock object.

Lore/DisplayName

Link to loredisplayname

MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.withDisplayName(String name)
Rückgabewert
A new IItemStack with the specified display name. Unlike the displayName setter, this only applies to this single item.
Parameter Typen
string (supports color codes with "§")
Methodenaufruf
stack.withLore(String[] lore)
Rückgabewert
A new IItemStack with the specified lore.
Parameter Typen
string[] (supports color codes with "§")
Methodenaufruf
stack.clearCustomName()
Rückgabewert
void (nothing)
Parameter Typen

Gets or Sets an item's forge capability data. In most cases, the tag of the stack has what you need, this is mainly for advanced use cases.

MethodenaufrufRückgabewert
Methodenaufruf
stack.getCapNBT()
Rückgabewert
IData
Methodenaufruf
stack.withCapNBT(IData data)
Rückgabewert
A new IItemStack with the specified capability NBT
MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.canApplyAtCraftingTable(IEnchantmentDefinition enchantment)
Rückgabewert
A bool.
Parameter Typen
IEnchantmentDefinition
Methodenaufruf
stack.addEnchantment(IEnchantment enchantment)
Rückgabewert
void (nothing)
Parameter Typen
IEnchantment

canItem...

Link to canitem

MethodenaufrufRückgabewertParameter Typen
Methodenaufruf
stack.canPlaceOn(IBlockDefinition block)
Rückgabewert
A bool that tells if the item can be placed on the block.
Parameter Typen
IBlockDefinition
Methodenaufruf
stack.canDestroy(IBlockDefinition block)
Rückgabewert
A bool that tells if the item can destroy the block.
Parameter Typen
IBlockDefinition
Methodenaufruf
stack.canHarvestBlock(IBlockState block)
Rückgabewert
A bool that tells if the item can harvest the block.
Parameter Typen
IBlockState
Methodenaufruf
stack.getStrengthAgainstBlock(IBlockState block)
Rückgabewert
A float that represents the item's strength against the block.
Parameter Typen
IBlockState

create IEntityItem

Link to create-ientityitem

MethodenaufrufRückgabewertParameter Types
Methodenaufruf
stack.createEntityItem(IWorld world, float x, float y, float z);
Rückgabewert
A new IEntityItem that corresponds to the newly created item in the world
Parameter Types
IWorld, float, float, float
Methodenaufruf
stack.createEntityItem(IWorld world, IBlockPos pos);
Rückgabewert
A new IEntityItem that corresponds to the newly created item in the world
Parameter Types
IWorld, IBlockPos

Gets a mutable ItemStack. Its damage, amount and tag is mutable. Its withTag, withAmount and other methods will change the item itself, rather than returning a new changed item.

MethodenaufrufRückgabewert
Methodenaufruf
stack.mutable()
Rückgabewert
IMutableItemStack

ItemTransformers and ItemConditions

Link to itemtransformers-and-itemconditions

You can find how to use these either in the IIngredient page or in their respecive entries:
Item Conditions
Item Transformers

Globally (translates the item to the new name).

ZenScript
Copy
val apple = <minecraft:apple>;

//prints "Apple"
print(apple.displayName);

//Sets apples Display Name to "Tomato"
apple.displayName = "Tomato";

//prints "Tomato"
print(apple.displayName);

Locally (only this single item).

ZenScript
Copy
<minecraft:coal>.withDisplayName("Black Gold");

<minecraft:coal>.withLore(["This function","requires a","string[]"]);

Maximum Stack Size

Link to maximum-stack-size

The maximum Stack Size is how many items fit in one Stack, for example, wool’s Stack size is 64 and Buckets’ only 16.

ZenScript
Copy
val apple = <minecraft:apple>;
val bucket = <minecraft:bucket>;

//prints 64
print(apple.maxStackSize);

//sets apples Max Stack size to 32
apple.maxStackSize = 32;

//prints 32
print(apple.maxStackSize);

//sets apples Max Stack size to Bucket's Max Stack size
apple.maxStackSize = bucket.maxStackSize;

//prints 16
print(apple.maxStackSize);

The Hardness is how long it takes to break the referred block. Only works if the object refers to a block.

ZenScript
Copy
val grass = <minecraft:grass>;

//prints 1.0
print(grass.hardness);

//sets grass Hardness to 10.0
grass.hardness = 10.0;

//prints 10.0
print(grass.hardness);

The damage for items that cannot be damaged is 0.

ZenScript
Copy
val pick = <minecraft:diamond_pickaxe>;

//prints 1561
print(pick.maxDamage);

//sets the max damage of the Diamond Pickaxe to 256
pick.maxDamage = 256;

//prints 256
print(pick.maxDamage);



//Damage doesn't matter, used in recipes
<minecraft:iron_pickaxe>.anyDamage();

//With the given damage
<minecraft:iron_pickaxe>.withDamage(122);

The tag is an IData object.
If the item does not contain a tag, it will return an empty tag, never null.

ZenScript
Copy
//creates apple with the given tag
//Removes existing tags
<minecraft:apple>.withTag({Unbreakable: 1});

//creates apple with an empty tag
<minecraft:apple>.withEmptyTag();

//removes a tag by its name
item.removeTag("tagName");

//removes all tags from an item
item.removeTag(null);

//update the existing tag
//If the tag doesn't override an existing tag, they will stay constant.
item.updateTag({Unbreakable: 1});

Returns the liquid contained in a single item (if multiple) or null if the item is no container.
Returns an ILiquidStack Object or null.

ZenScript
Copy
val lav = <minecraft:lava_bucket>;
print(lav.liquid.name);

How many apples are there?

ZenScript
Copy
<minecraft:apple>.anyAmount();

//1 Apple
val apple = <minecraft:apple>;

//2 Apples
val moreApples = apple * 2;

//3 Apples
val evenMoreApples = <minecraft:apple> * 3;

Returns a weightedItemStack with the provided percentage.

ZenScript
Copy
val apple = <minecraft:apple>;

//Creates a weightedItemStack with 100 percent chance
var applePercentage = apple % 100;

//Does the same as the above
applePercentage = apple.weight(1.0);

Returns a List of IOreDictEntries referring to this item.

ZenScript
Copy
<minecraft:apple>.ores;

Casting to IBlock

Link to casting-to-iblock

You can cast an IItemStack to an IBlock, as long as you are referring to a block, otherwise the cast will throw an exception.

ZenScript
Copy
<minecraft:dirt>.asBlock();
<minecraft:dirt> as crafttweaker.block.IBlock;

You can also test if an IItemStack contains an ItemBlock and can thus be converted:

zenscript:
Copy
<minecraft:dirt>.isItemBlock; // true
<minecraft:stick>.isItemBlock; // false

You can check if an IItemStack is a food item and what food properties it has.
May not work for every modded food item!

ZenScript
Copy
<minecraft:apple>.isFood; //true
<minecraft:apple>.saturation; //0.3
<minecraft:apple>.healAmount; //4