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.

ZenScript
Copy
import crafttweaker.api.inventory.IInventory;

Name: clear

Clears this inventory of all items.

Return Type: void

ZenScript
Copy
// IInventory.clear() as void

myIInventory.clear();

Name: closeInventory

Marks the inventory as closed, this is used by chests and barrels to determine if they should have a closed texture / model, but other inventories may use it in a different way.

Return Type: void

ZenScript
Copy
// IInventory.closeInventory(player as MCPlayerEntity) as void

myIInventory.closeInventory(player);
参数类型描述
参数
player
类型
MCPlayerEntity #MC玩家实体
描述
The player that opened the inventory.

Name: count

Counts how many of the given Item is in this inventory.

NOTE: This does not work for IItemStacks, so all NBT will be ignored.

Returns: The amount of the Item in this inventory.
Return Type: int

ZenScript
Copy
// IInventory.count(item as MCItemDefinition) as int

myIInventory.count(<item:minecraft:dirt>);
参数类型描述
参数
item
类型
MCItemDefinition
描述
The Item to look for.

Name: count

Counts how many ItemStacks in this inventory match the given predicate.

Returns: The amount of ItemStacks in this inventory that match the predicate.
Return Type: int

ZenScript
Copy
// IInventory.count(predicate as Predicate<IItemStack>) as int

myIInventory.count((stack) => stack.amount == 2);
参数类型描述
参数
predicate
类型
Predicate<IItemStack>
描述
The predicate to test against

Name: decrStackSize

Decreases the stack size of the stack in the given slot by the given count.

Returns: A new stack with how much was removed.
Return Type: IItemStack

ZenScript
Copy
// IInventory.decrStackSize(index as int, count as int) as IItemStack

myIInventory.decrStackSize(2, 2);
参数类型描述可选DefaultValue
参数
index
类型
int
描述
The slot index to decrement.
可选
false
DefaultValue
参数
count
类型
int
描述
How much should be removed.
可选
true
DefaultValue
1

Link to getInventorySize

Name: getInventorySize

Gets how many slots this inventory has.

Example: A hopper will return 5

Returns: The amount of slots this inventory has.
Return Type: int

ZenScript
Copy
// IInventory.getInventorySize() as int

myIInventory.getInventorySize();

Link to getInventoryStackLimit

Name: getInventoryStackLimit

Gets the max stack size that is allowed in this inventory.

This is nearly always 64, but some inventories like the Beacon and Compostor have a limit of 1.

Returns: The max stack size allowed in the inventory.
Return Type: int

ZenScript
Copy
// IInventory.getInventoryStackLimit() as int

myIInventory.getInventoryStackLimit();

Name: getStackInSlot

Gets the IItemStack in the given slot.

Returns: The IItemStack in the slot.
Return Type: IItemStack

ZenScript
Copy
// IInventory.getStackInSlot(index as int) as IItemStack

myIInventory.getStackInSlot(2);
参数类型描述
参数
index
类型
int
描述
The index to get the stack from.

Name: getStacks

Gets the ItemStacks in this inventory that match the given predicate.

Returns: A list of IItemStacks that match the given predicate.
Return Type: stdlib.List<IItemStack>

ZenScript
Copy
// IInventory.getStacks(predicate as Predicate<IItemStack>) as stdlib.List<IItemStack>

myIInventory.getStacks((stack) => stack.amount == 2;);
参数类型描述
参数
predicate
类型
Predicate<IItemStack>
描述
The predicate to test against.

Name: hasAny

Checks if this inventory has any of the given Items.

NOTE: This does not work for IItemStacks, so all NBT will be ignored.

Returns: True if this inventory has any of the items. False otherwise.
Return Type: boolean

ZenScript
Copy
// IInventory.hasAny(list as stdlib.List<MCItemDefinition>) as boolean

myIInventory.hasAny([<item:minecraft:diamond>]);
参数类型描述
参数
列表
类型
stdlib.List<MCItemDefinition>
描述
The Items to look for.

Name: isEmpty

Checks if this inventory is empty.

Returns: True if this inventory is empty. False otherwise.
Return Type: boolean

ZenScript
Copy
// IInventory.isEmpty() as boolean

myIInventory.isEmpty();

Link to isItemValidForSlot

Name: isItemValidForSlot

Checks if the given stack is valid for the given slot index.

Returns: True if the stack is valid. False otherwise.
Return Type: boolean

ZenScript
Copy
// IInventory.isItemValidForSlot(index as int, stack as IItemStack) as boolean

myIInventory.isItemValidForSlot(2, <item:minecraft:dirt>);
参数类型描述
参数
index
类型
int
描述
The slot index to check.
参数
堆叠
类型
IItemstack
描述
The stack to check.

Link to isUsableByPlayer

Name: isUsableByPlayer

Checks if this IInventory can be used by the player.

Returns: True if the player can use this inventory. False otherwise.
Return Type: boolean

ZenScript
Copy
// IInventory.isUsableByPlayer(player as MCPlayerEntity) as boolean

myIInventory.isUsableByPlayer(player);
参数类型描述
参数
player
类型
MCPlayerEntity #MC玩家实体
描述
The player to check if they can use this inventory.

Name: markDirty

Used by tile entities to ensure that chunks are up to date when they are saved to disk.

Return Type: void

ZenScript
Copy
// IInventory.markDirty() as void

myIInventory.markDirty();

Name: openInventory

Marks the inventory as opened, this is used by chests and barrels to determine if they should have an open texture / model, but other inventories may use it in a different way.

Return Type: void

ZenScript
Copy
// IInventory.openInventory(player as MCPlayerEntity) as void

myIInventory.openInventory(player);
参数类型描述
参数
player
类型
MCPlayerEntity #MC玩家实体
描述
The player that opened the inventory.

Link to removeStackFromSlot

Name: removeStackFromSlot

Removes the IItemStack from the given slot and returns it.

Returns: The removed stack from the slot.
Return Type: IItemStack

ZenScript
Copy
// IInventory.removeStackFromSlot(index as int) as IItemStack

myIInventory.removeStackFromSlot(2);
参数类型描述
参数
index
类型
int
描述
The slot index to remove.

Link to setInventorySlotContents

Name: setInventorySlotContents

Sets the contents of the given slot to the given IItemStack.

Return Type: void

ZenScript
Copy
// IInventory.setInventorySlotContents(index as int, stack as IItemStack) as void

myIInventory.setInventorySlotContents(2, <item:minecraft:diamond>);
参数类型描述
参数
index
类型
int
描述
The slot index to set.
参数
堆叠
类型
IItemstack
描述
The IItemStack to put in the slot.
名称类型可获得可设置描述
名称
inventorySize
类型
int
可获得
true
可设置
false
描述
Gets how many slots this inventory has.

Example:
A hopper will return 5
名称
inventoryStackLimit
类型
int
可获得
true
可设置
false
描述
Gets the max stack size that is allowed in this inventory.

This is nearly always 64, but some inventories like the Beacon and Compostor have a limit of 1.
名称
isEmpty #是否为空
类型
布尔值
可获得
true
可设置
false
描述
Checks if this inventory is empty.