IItemStack

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.

Importing the package

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

There are several methods that return an IItemStack

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

Functions

So what can we do with that now?

Extending IIngredient

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

Derived Methods

ZenGetters/ZenSetters

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

ZenGetter/ZenMethod ZenSetter/ZenMethod Type
definition IItemDefinition
name string
displayName displayName string
maxStackSize maxStackSize int
hardness hardness float
damage int
maxDamage maxDamage int
hasTag bool
tag withTag(tag) IData
ores List<IOreDictEntry>
toolClasses List<string>
itemEnchantability int
containerItem IItemStack
hasContainerItem bool
repairCost repairCost int
canEditBlocks bool
isOnItemFrame bool
isEnchantable bool
isEnchanted bool
isDamaged bool
isDamageable bool
isStackable bool
isBeaconPayment bool
hasEffect bool
hasDisplayName bool
metadata int
hasSubtypes bool
isEmpty bool
burnTime int
showsDurabilityBar bool
hasCustomEntity bool
enchantments List<IEnchantment>

Amount

Methodenaufruf Rückgabewert Parameter Typen
stack.anyAmount() A new IItemStack with the changed property
stack.amount(int amount) A new IItemStack with the changed property int
stack.withAmount(int amount) Einen neuen IItemStack mit der angegebenen Größe int
stack * amount Einen neuen IItemStack mit der angegebenen Größe int
stack.splitStack(int amount) The split IItemStack. The old one will be reduced accordingly. int

Weight

Method call Returns ParameterTypes
stack.percent(float chance) A WeightedItemStack float (100 = 100%)
stack.weight(float chance) A WeightedItemStack float (1 = 100%)

Damage

Method call Returns ParameterTypes
stack.anyDamage() A new IItemStack with the changed property
stack.withDamage(int damage) A new IItemStack with the changed property int
stack.damageItem(int amount, IEntity entity) void (nothing) int, IEntity

Tags

Method call Returns ParameterTypes
stack.withEmtpyTag() A new IItemStack with the changed property
stack.withTag(IData tag) A new IItemStack with the changed property IData
stack.removeTag(String name) A new IItemStack with the changed property string
stack.updateTag(IData tag) A new IItemStack with the changed property IData

Block Casting

Method call Returns
stack.asBlock() A new IBlock object.
stack as IBlock A new IBlock object.

Lore/DisplayName

Method call Returns ParameterTypes
stack.withDisplayName(String name) A new IItemStack with the changed property. Unlike the displayName setter, this only applies to this single item. string (supports color codes with “§”)
stack.withLore(String[] lore) A new IItemStack with the changed property. string[] (supports color codes with “§”)
stack.clearCustomName() void (nothing)

Enchantments

Method call Returns ParameterTypes
stack.canApplyAtCraftingTable(IEnchantmentDefinition enchantment) A bool. IEnchantmentDefinition
stack.addEnchantment(IEnchantment enchantment) void (nothing) IEnchantment

canItem…

Method call Returns ParameterTypes
stack.canPlaceOn(IBlockDefinition block) A bool that tells if the item can be placed on the block. IBlockDefinition
stack.canDestroy(IBlockDefinition block) A bool that tells if the item can destroy the block. IBlockDefinition
stack.canHarvestBlock(IBlockState block) A bool that tells if the item can harvest the block. IBlockState
stack.getStrengthAgainstBlock(IBlockState block) A float that represents the item’s strength against the block. IBlockState

create IEntityItem

Method call Returns Parameter Types
stack.createEntityItem(IWorld world, int x, int y, int z); A new IEntityItem that corresponds to the newly created item in the world IWorld, int, int, int
stack.createEntityItem(IWorld world, IBlockPos pos); A new IEntityItem that corresponds to the newly created item in the world IWorld, IBlockPos

ItemTransformers and ItemConditions

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

Examples

DisplayName

Globally (translates the item to the new name).

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).

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

Lore

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

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.

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);

Hardness

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

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);

Damage

The damage for items that cannot be damaged is 0.

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);

Tag

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

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

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

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

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

Liquid

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

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

Amount

How many apples are there?

<minecraft:apple>.anyAmount();

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

//2 Apples
val moreApples = apple * 2;

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

Weight

Returns a weightedItemStack with the provided percentage.

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);

Ores

Returns a List of IOreDictEntries referring to this item.

<minecraft:apple>.ores;

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.

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