Skip to content

CrTItemHandler

youyihj edited this page Oct 25, 2023 · 3 revisions

CrTItemHandler

@since 1.6.3

CrTItemHandler is like an item container. It can handle some item stacks like chest or players' inventory.

Importing the package

You'd better import the package to avoid errors and write script easier.

import mods.zenutils.ItemHandler;

Getting an instance

  • world.getItemHandler(IBlockPos pos, @Optional IFacing facing) gets item handler from Tile entity's container.
  • player.getPlayerInventoryItemHandler() gets item handler represents player's inventory.
  • player.getPlayerBaubleItemHandler() gets item handler represents player's Baubles inventory.

ZenGetters

  • itemHandler.size Returns the number of slots available.

ZenMethods

  • IItemStack getStackInSlot(int slot)

Returns the ItemStack in a given slot. The result's stack size may be greater than the item stack's max size. If the result is null, then the slot is empty.

  • bool setStackInSlot(int slot, IItemStack stack)

Sets an ItemStack in a given slot. Returns true if the item handler accepts the operation.

  • IItemStack insertItem(int slot, IItemStack stack, bool simulate)

Inserts an ItemStack into the given slot and return the remainder. (if the entire stack is accepted, then return null) If simulate argument is true, the insertion is only simulated.

  • IItemStack extractItem(int slot, int amount, bool simulate)

Extracts an ItemStack from the given slot. The returned value must be null if nothing is extracted, otherwise its stack size must be less than or equal to amount and ItemStack.getMaxStackSize(). If simulate argument is true, the extraction is only simulated.

  • int getSlotLimit(int slot)

Retrieves the maximum stack size allowed to exist in the given slot.

  • bool isItemValid(int slot, IItemStack stack)

returns true if the slot can insert the ItemStack, not considering the current state of the inventory. false if the slot can never insert the ItemStack in any situation.

Iterable<IItemStack>

An ItemHandler is an Iterable<IItemStack>. This means that you can use a for-loop on the container to iterate over its IItemStacks.

Clone this wiki locally