Item Stack
Scripting with the ItemStack class.
Representation of a stack of items. This is the main object used for storing items in the inventory.
Fields & Properties
item
The item.
Item
public
amount
The number of duplicate items in this stack.
int
public
placement
The placement of this item stack in the inventory.
ItemStack.Placement
public
enchants
A list of enchantments applied to this item stack. Stackable item types cannot be enchanted.
List<Enchantment>
public
BuyingPrice
The buying price of this item stack.
Currency
public
SellingPrice
The selling price of this item stack.
Currency
public
IsEmpty
If this item stack has no items.
bool
public
IsFull
If this item stack has reached the max capacity.
bool
public
IsEquipped
If this item stack is currently equipped.
bool
public
IsKeyItem
If this is a key item.
bool
public
Creating Item Stacks
Constructor
To create an ItemStack
, you need a reference to an Item.
Copy
You can create a copy of an ItemStack
with the CreateCopy
method.
Managing Amounts
When managing item amounts, it's recommended to use the methods below instead of just editing the amount
field.
Add
The Add
method increases the item stack's amount. It returns an int that represents the excess amount (the amount not added due to the item stack becoming full).
Remove
The Remove
method decreases the item stack's amount. It returns an int that represents the excess amount (the amount not removed due to the item stack becoming empty).
Split
The Split
method does 3 things: creates a copy of an ItemStack
, gives half of the item to the copy, and returns the copy. So, if you have an ItemStack with it's amount equally to 20, using Split
on it will cut the amount down to 10.
Combine
The Combine
method takes the amount from another ItemStack
as much as possible. This may result in the other item stack becoming empty. The method returns true if any amount of taken from the other item stack, otherwise, false will be returned.
Operators
ItemStack
's support some operators that you can use to change the amount field. The operators will clamp the amount within 0 and the max item stack amount.
Enchanting
Enchanting item stacks can be handled with the ItemStack
class itself, as long as you have a reference to an enchanter ItemStack
. Use the TryEnchant
method for this purpose.
TryEnchant
returns true if the enchant was successful. The enchant may fail if the item types were incorrect. Only enchanter items can enchant enchantable items. Learn more about enchanting here.
You can choose to apply the enchanting (currency) cost by passing true
as the second parameter.
Action Menu Options
By default, item stacks' UI counterpart logically display item options for the Action Menu. You can override these options by editing the ItemStack.actionMenuOptionsGetter
field.
Here's an example of how you can override these options:
You can call the GetActionMenuOptions
method to get the options.
Last updated