IItemStack
Link to 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
Link to 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
Link to calling-an-iitemstack
There are several methods that return an IItemStack
- Using the bracket Handler
<minecraft:apple>
- Using the
makeStack()
method on a IItemDefinition object<minecraft:stone>.definition.makeStack(0)
- Using the
stack
getter on a IEntityDrop object - Using the
firstItem
getter on a IOreDictEntry
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
Functions
Link to functions
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()
ZenGetters/ZenSetters
Link to zengetterszensetters
Read how to use them here. Also, check out the examples below.
ZenGetter/ZenMethod | ZenSetter/ZenMethod | Type |
---|---|---|
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 |
Amount
Link to amount
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.anyAmount() | Returns A new IItemStack with any amount for recipes | ParameterTypes |
Method call stack.amount(int amount) | Returns A new IItemStack with the specified amount | ParameterTypes int |
Method call stack.withAmount(int amount) | Returns A new IItemStack with the specified amount | ParameterTypes int |
Method call stack * amount | Returns A new IItemStack with the specified amount | ParameterTypes int |
Method call stack.splitStack(int amount) | Returns The split IItemStack. The old one will be reduced accordingly. | ParameterTypes int |
Weight
Link to weight
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.percent(float chance) | Returns A WeightedItemStack | ParameterTypes float (100 = 100%) |
Method call stack.weight(float chance) | Returns A WeightedItemStack | ParameterTypes float (1 = 100%) |
Damage
Link to damage
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.anyDamage() | Returns A new IItemStack with any damage for recipes | ParameterTypes |
Method call stack.withDamage(int damage) | Returns A new IItemStack with the specified damage | ParameterTypes int |
Method call stack.damageItem(int amount, IEntity entity) | Returns void (nothing) | ParameterTypes int, IEntity |
Tags
Link to tags
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.withEmptyTag() | Returns A new IItemStack with an empty NBT tag | ParameterTypes |
Method call stack.withTag(IData tag) | Returns A new IItemStack with the specified NBT tag | ParameterTypes IData |
Method call stack.withTag(IData tag, bool matchTagExact) | Returns A new IItemStack with the specified NBT tag | ParameterTypes IData, bool |
Method call stack.removeTag(String name) | Returns A new IItemStack with the specified NBT tag removed, if it exists | ParameterTypes string |
Method call stack.updateTag(IData tag) | Returns A new IItemStack with the added NBT tag | ParameterTypes IData |
Method call stack.updateTag(IData tag, bool matchTagExact) | Returns A new IItemStack with the added NBT tag | ParameterTypes IData, bool |
Block Casting
Link to block-casting
Method call | Returns |
---|---|
Method call stack.asBlock() | Returns A new IBlock object. |
Method call stack as IBlock | Returns A new IBlock object. |
Lore/DisplayName
Link to loredisplayname
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.withDisplayName(String name) | Returns A new IItemStack with the specified display name. Unlike the displayName setter, this only applies to this single item. | ParameterTypes string (supports color codes with "§") |
Method call stack.withLore(String[] lore) | Returns A new IItemStack with the specified lore. | ParameterTypes string[] (supports color codes with "§") |
Method call stack.clearCustomName() | Returns void (nothing) | ParameterTypes |
Cap NBT
Link to cap-nbt
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.
Method call | Returns |
---|---|
Method call stack.getCapNBT() | Returns IData |
Method call stack.withCapNBT(IData data) | Returns A new IItemStack with the specified capability NBT |
Enchantments
Link to enchantments
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.canApplyAtCraftingTable(IEnchantmentDefinition enchantment) | Returns A bool. | ParameterTypes IEnchantmentDefinition |
Method call stack.addEnchantment(IEnchantment enchantment) | Returns void (nothing) | ParameterTypes IEnchantment |
canItem...
Link to canitem
Method call | Returns | ParameterTypes |
---|---|---|
Method call stack.canPlaceOn(IBlockDefinition block) | Returns A bool that tells if the item can be placed on the block. | ParameterTypes IBlockDefinition |
Method call stack.canDestroy(IBlockDefinition block) | Returns A bool that tells if the item can destroy the block. | ParameterTypes IBlockDefinition |
Method call stack.canHarvestBlock(IBlockState block) | Returns A bool that tells if the item can harvest the block. | ParameterTypes IBlockState |
Method call stack.getStrengthAgainstBlock(IBlockState block) | Returns A float that represents the item's strength against the block. | ParameterTypes IBlockState |
create IEntityItem
Link to create-ientityitem
Method call | Returns | Parameter Types |
---|---|---|
Method call stack.createEntityItem(IWorld world, float x, float y, float z); | Returns A new IEntityItem that corresponds to the newly created item in the world | Parameter Types IWorld, float, float, float |
Method call stack.createEntityItem(IWorld world, IBlockPos pos); | Returns A new IEntityItem that corresponds to the newly created item in the world | Parameter Types IWorld, IBlockPos |
Mutable
Link to mutable
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.
Method call | Returns |
---|---|
Method call stack.mutable() | Returns 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
Examples
Link to examples
DisplayName
Link to displayname
Globally (translates the item to the new name).
ZenScript Copyval 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");
Lore
Link to lore
<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 Copyval 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
Link to hardness
The Hardness is how long it takes to break the referred block. Only works if the object refers to a block.
ZenScript Copyval 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
Link to damage-1
The damage for items that cannot be damaged is 0.
ZenScript Copyval 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
Link to tag
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});
Liquid
Link to 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.
ZenScript Copyval lav = <minecraft:lava_bucket>;
print(lav.liquid.name);
Amount
Link to amount-1
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;
Weight
Link to weight-1
Returns a weightedItemStack with the provided percentage.
ZenScript Copyval 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
Link to ores
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
Food Properties
Link to food-properties
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