Interface IInventoryAccess

All Known Implementing Classes:
ContainerInventoryAccess, ItemHandlerInventoryAccess, WorldlyContainerInventoryAccess

public interface IInventoryAccess
This interface provides a loader neutral way to interact with different types of inventories.

TODO mention getter

  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    canExtract(int slot, int amount)
    Checks if items can be extracted from the specified slot of the inventory.
    default boolean
    canExtract(int slot, int amount, net.minecraft.core.Direction side)
    Checks if items can be extracted from the specified slot of the inventory.
    default boolean
    canInsert(int slot, net.minecraft.world.item.ItemStack stack)
    Checks if an ItemStack can be inserted into the given slot.
    default boolean
    canInsert(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side)
    Checks if an ItemStack can be inserted into the given slot.
    default net.minecraft.world.item.ItemStack
    extract(int slot, int amount)
    Attempts to extract items from the specified amount.
    default net.minecraft.world.item.ItemStack
    extract(int slot, int amount, net.minecraft.core.Direction side)
    Attempts to extract items from the specified amount.
    net.minecraft.world.item.ItemStack
    extract(int slot, int amount, net.minecraft.core.Direction side, boolean modify)
    Attempts to extract items from the specified amount.
    default void
    forEachSlot(IntConsumer slotAction, net.minecraft.core.Direction side)
     
    default int[]
    Gets an array of accessible slot IDs for the inventory.
    int[]
    getAvailableSlots(net.minecraft.core.Direction side)
    Gets an array of accessible slot IDs for a given side of the inventory.
    int
    getSlotSize(int slot)
    Get the amount of items that can be held by a given slot.
    net.minecraft.world.item.ItemStack
    getStackInSlot(int slot)
    Gets the ItemStack in a given slot within the inventory.
    default net.minecraft.world.item.ItemStack
    insert(int slot, net.minecraft.world.item.ItemStack stack)
    Attempts to insert an ItemStack into the given slot.
    default net.minecraft.world.item.ItemStack
    insert(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side)
    Attempts to insert an ItemStack into the given slot.
    net.minecraft.world.item.ItemStack
    insert(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side, boolean modify)
    Attempts to insert an ItemStack into the given slot.
    default boolean
    isValidForSlot(int slot, net.minecraft.world.item.ItemStack stack)
    Checks if an ItemStack is the right type of item for a slot.
    boolean
    isValidForSlot(int slot, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction side)
    Checks if an ItemStack is the right type of item for a slot.
  • Method Details

    • getAvailableSlots

      default int[] getAvailableSlots()
      Gets an array of accessible slot IDs for the inventory.
      Returns:
      An array of accessible slot IDs.
    • getAvailableSlots

      int[] getAvailableSlots(@Nullable net.minecraft.core.Direction side)
      Gets an array of accessible slot IDs for a given side of the inventory.
      Parameters:
      side - The side of the inventory being accessed. This is only relevant when accessing directional inventories.
      Returns:
      An array of accessible slot IDs.
    • getStackInSlot

      net.minecraft.world.item.ItemStack getStackInSlot(int slot)
      Gets the ItemStack in a given slot within the inventory. The resulting ItemStack should be considered immutable.
      Parameters:
      slot - The ID of the slot to access.
      Returns:
      The ItemStack in the given slot. This should be considered immutable.
    • canInsert

      default boolean canInsert(int slot, net.minecraft.world.item.ItemStack stack)
      Checks if an ItemStack can be inserted into the given slot.
      Parameters:
      slot - The ID of the slot to insert into.
      stack - The ItemStack to insert.
      Returns:
      Whether the item can be inserted or not.
    • canInsert

      default boolean canInsert(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side)
      Checks if an ItemStack can be inserted into the given slot.
      Parameters:
      slot - The ID of the slot to insert into.
      stack - The ItemStack to insert.
      side - The side of the inventory the item is being inserted through.
      Returns:
      Whether the item can be inserted or not.
    • insert

      default net.minecraft.world.item.ItemStack insert(int slot, net.minecraft.world.item.ItemStack stack)
      Attempts to insert an ItemStack into the given slot. If the ItemStack will not fully fit a partial insertion will be done instead.
      Parameters:
      slot - The ID of the slot to insert into.
      stack - The ItemStack to insert.
      Returns:
      The remaining ItemStack that was not inserted. An empty stack indicates that the item was fully inserted.
    • insert

      default net.minecraft.world.item.ItemStack insert(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side)
      Attempts to insert an ItemStack into the given slot. If the ItemStack will not fully fit a partial insertion will be done instead.
      Parameters:
      slot - The ID of the slot to insert into.
      stack - The ItemStack to insert.
      side - The side of the inventory the item is being inserted through.
      Returns:
      The remaining ItemStack that was not inserted. An empty stack indicates that the item was fully inserted.
    • insert

      net.minecraft.world.item.ItemStack insert(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side, boolean modify)
      Attempts to insert an ItemStack into the given slot. If the ItemStack will not fully fit a partial insertion will be done instead.
      Parameters:
      slot - The ID of the slot to insert into.
      stack - The ItemStack to insert.
      side - The side of the inventory the item is being inserted through.
      modify - Should the contents of the inventory actually be modified?
      Returns:
      The remaining ItemStack that was not inserted. An empty stack indicates that the item was fully inserted.
    • canExtract

      default boolean canExtract(int slot, int amount)
      Checks if items can be extracted from the specified slot of the inventory.
      Parameters:
      slot - The ID of the slot to extract from.
      amount - The amount of items to extract.
      Returns:
      Whether the items could be extracted or not.
    • canExtract

      default boolean canExtract(int slot, int amount, @Nullable net.minecraft.core.Direction side)
      Checks if items can be extracted from the specified slot of the inventory.
      Parameters:
      slot - The ID of the slot to extract from.
      amount - The amount of items to extract.
      side - The side the items are extracted from.
      Returns:
      Whether the items could be extracted or not.
    • extract

      default net.minecraft.world.item.ItemStack extract(int slot, int amount)
      Attempts to extract items from the specified amount. You are not guaranteed to receive an item or as many of the item as you requested.
      Parameters:
      slot - The ID of the slot to extract from.
      amount - The amount of items to extract.
      Returns:
      The extracted items.
    • extract

      default net.minecraft.world.item.ItemStack extract(int slot, int amount, @Nullable net.minecraft.core.Direction side)
      Attempts to extract items from the specified amount. You are not guaranteed to receive an item or as many of the item as you requested.
      Parameters:
      slot - The ID of the slot to extract from.
      amount - The amount of items to extract.
      side - The side the items are extracted from.
      Returns:
      The extracted items.
    • extract

      net.minecraft.world.item.ItemStack extract(int slot, int amount, @Nullable net.minecraft.core.Direction side, boolean modify)
      Attempts to extract items from the specified amount. You are not guaranteed to receive an item or as many of the item as you requested.
      Parameters:
      slot - The ID of the slot to extract from.
      amount - The amount of items to extract.
      side - The side the items are extracted from.
      modify - Should the contents of the inventory actually be modified?
      Returns:
      The extracted items.
    • getSlotSize

      int getSlotSize(int slot)
      Get the amount of items that can be held by a given slot.
      Parameters:
      slot - The ID of the slot to query.
      Returns:
      The amount of items that can be held by the slot.
    • isValidForSlot

      default boolean isValidForSlot(int slot, net.minecraft.world.item.ItemStack stack)
      Checks if an ItemStack is the right type of item for a slot. This only validates the item and not the state of the inventory itself. For example a brewing stand fuel slot will return true on blaze powder even if the slot is full.

      This check is performed automatically when inserting an item.

      Parameters:
      slot - The ID of the slot to query.
      stack - The stack to test.
      Returns:
      Whether the item is valid for the slot or not.
    • isValidForSlot

      boolean isValidForSlot(int slot, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction side)
      Checks if an ItemStack is the right type of item for a slot. This only validates the item and not the state of the inventory itself. For example a brewing stand fuel slot will return true on blaze powder even if the slot is full.

      This check is performed automatically when inserting an item.

      Parameters:
      slot - The ID of the slot to query.
      stack - The stack to test.
      side - The side of the inventory being accessed.
      Returns:
      Whether the item is valid for the slot or not.
    • forEachSlot

      default void forEachSlot(IntConsumer slotAction, @Nullable net.minecraft.core.Direction side)