Home Migration Guide Getting Started With Scripts Commands Examples
BracketHandlers

PlayerInventory

Importing the class

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 at the very top of the file.

script.zs
import crafttweaker.api.inventory.PlayerInventory;

Implemented Interfaces

PlayerInventory implements the following interfaces. That means all methods defined in these interfaces are also available in PlayerInventory

Methods

Adds the stack to the given slot in the player’s inventory.

Returns: True if the stack was inserted. False otherwise.
Return Type: boolean

script.zs
PlayerInventory.add(slot as int, stack as IItemStack) as boolean
ParameterTypeDescription
Parameter
slot
Type
int
Description
The slot to put the stack.
Parameter
stack
Type
IItemStack
Description
The stack to add.

Adds the stack to the first empty slot in the player’s inventory.

Returns: True if the stack was added. False otherwise.
Return Type: boolean

script.zs
// PlayerInventory.addIItemStackToInventory(stack as IItemStack) as boolean
myPlayerInventory.addIItemStackToInventory(<item:minecraft:diamond>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to add.

Checks if a stack can be stored in the player’s inventory. It first tries to place it in the selected slot in the player’s hotbar, then the offhand slot, then any available/empty slot in the player’s inventory.

Returns: The slot that the stack can be stored in, or -1 if it can’t be stored.
Return Type: int

script.zs
// PlayerInventory.canStoreIItemStack(stack as IItemStack) as int
myPlayerInventory.canStoreIItemStack(<item:minecraft:diamond>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to store.

Removes the first instance of the given stack from the inventory.

Return Type: void

script.zs
// PlayerInventory.deleteStack(stack as IItemStack) as void
myPlayerInventory.deleteStack(<item:minecraft:diamond>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to remove.

Drop all items in the inventory..

Return Type: void

script.zs
// PlayerInventory.dropAllItems() as void
myPlayerInventory.dropAllItems();

Gets the currently held item by the player.

Returns: The currently held stack by the player.
Return Type: IItemStack

script.zs
// PlayerInventory.getCurrentItem() as IItemStack
myPlayerInventory.getCurrentItem();

Gets the first slot in the inventory that is empty.

If no slot is found, it returns -1.

Returns: The found slot or -1 if no slot is found.
Return Type: int

script.zs
// PlayerInventory.getFirstEmptyStack() as int
myPlayerInventory.getFirstEmptyStack();

Gets the IItemStack that is being held by the mouse in a Gui/Container.

Returns: The held IItemStack
Return Type: IItemStack

script.zs
// PlayerInventory.getIItemStack() as IItemStack
myPlayerInventory.getIItemStack();

Checks if any of the ItemStacks in the inventory match the given ingredient.

Returns: True if any of the stacks match. False otherwise.
Return Type: boolean

script.zs
PlayerInventory.hasIItemStack(ingredient as IIngredient) as boolean
ParameterTypeDescription
Parameter
ingredient
Type
IIngredient
Description
The ingredient to check against..

Removes all stacks that match the ingredient.

Returns: True if anything was removed. False otherwise.
Return Type: boolean

script.zs
// PlayerInventory.remove(ingredient as IIngredient) as boolean
myPlayerInventory.remove(<item:minecraft:diamond>);
ParameterTypeDescription
Parameter
ingredient
Type
IIngredient
Description
The ingredient to match against.

Sets the IItemStack that is being held by the mouse in a Gui/Container.

Return Type: void

script.zs
// PlayerInventory.setIItemStack(stack as IItemStack) as void
myPlayerInventory.setIItemStack(<item:minecraft:dirt>);
ParameterTypeDescription
Parameter
stack
Type
IItemStack
Description
The stack to hold.

Properties

NameTypeHas GetterHas SetterDescription
Name
currentItem
Type
IItemStack
Has Getter
true
Has Setter
false
Description
Gets the currently held item by the player.
Name
firstEmptyStack
Type
int
Has Getter
true
Has Setter
false
Description
Gets the first slot in the inventory that is empty.

If no slot is found, it returns -1.
Name
itemStack
Type
IItemStack
Has Getter
true
Has Setter
true
Description
Gets the IItemStack that is being held by the mouse in a Gui/Container.