Interface IInventoryBE<T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>

Type Parameters:
T - The item stack handler (inventory) that the implementing block entity uses.
All Superinterfaces:
net.minecraft.world.Clearable, net.minecraft.world.Container, IBE, net.minecraft.world.inventory.StackedContentsCompatible, net.minecraft.world.WorldlyContainer
All Known Implementing Classes:
AbstractCapacitorBE, AbstractInventoryBE, AbstractSingleTankAndInventoryBE

public interface IInventoryBE<T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>> extends IBE, net.minecraft.world.WorldlyContainer, net.minecraft.world.inventory.StackedContentsCompatible
Provides a large number of helper functions for block entities with inventories.
  • Field Summary

    Fields inherited from interface net.minecraft.world.Container

    DEFAULT_DISTANCE_BUFFER
  • Method Summary

    Modifier and Type
    Method
    Description
    default boolean
    canEjectSlot(int slot)
    Returns true if the item in the given slot can be ejected.
    default boolean
    canPlaceItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, @Nullable net.minecraft.core.Direction direction)
    Controls whether an item can be inserted into the given slot through the given face.
    default boolean
    canTakeItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction direction)
    Controls whether an item can be taken from the given slot through the given face.
    default void
    Clear all items from the inventory.
    static void
    ejectFrom(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int slot, int maxCount)
    Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
    static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
    void
    ejectFrom(IInventoryBE<T> be, int maxAmount)
    Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
    static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>>
    void
    ejectFrom(IInventoryBE<T> be, int slot, int maxAmount)
    Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
    static net.minecraft.world.item.ItemStack
    ejectStack(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, net.minecraft.world.item.ItemStack toEject)
    Ejects an ItemStack into the world or into a valid container.
    default void
    fillStackedContents(net.minecraft.world.entity.player.StackedContents contents)
     
    default int
     
    default net.minecraft.core.Direction
    getEjectDirection(net.minecraft.world.level.block.state.BlockState state)
    Get the Direction to eject items at.
    default int
    Returns the index to the first non-empty ItemStack in the inventory or -1 if no such item exists.
    Get the block entity's inventory
    default T
    getInventory(net.minecraft.core.Direction side)
    Get the inventory on the given side, by default the inventory is non-sided, so this returns the main inventory.
    default net.minecraft.world.item.ItemStack
    getItem(int slot)
    Get the item in the given slot index.
    default int
    getRandomUsedSlot(net.minecraft.util.RandomSource random)
    Gets a random slot with at least 1 item in it.
    default int
    getRandomUsedSlot(net.minecraft.util.RandomSource random, int minimumCount)
    Gets a random slot with at least minimumCount items in it, or a slot where the maximum stack size equals 1.
    default int[]
    getSlotsForFace(net.minecraft.core.Direction side)
    Gets the indexes to any slots accessible on the given side.
    default net.minecraft.world.item.ItemStack
    giveItem(net.minecraft.world.item.ItemStack stack)
    Add an item to the inventory, returning the remainder.
    static net.minecraft.world.item.ItemStack
    insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack)
    Inserts an item into the provided item handler.
    static net.minecraft.world.item.ItemStack
    insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex)
    Inserts an item into the provided item handler.
    default boolean
     
    static boolean
    isFull(net.neoforged.neoforge.items.IItemHandler handler)
    Returns true if the given handler has no empty slots.
    default boolean
    Gets whether the inventory has no empty slots.
    default net.minecraft.world.item.ItemStack
    removeItem(int slot, int amount)
    Removes `amount` items from the given slot and returns the taken ItemStack.
    default net.minecraft.world.item.ItemStack
    Removes the item from the given slot without updating the container.
    default void
    setItem(int slot, net.minecraft.world.item.ItemStack stack)
    Set the ItemStack in the given slot.
    default boolean
    Whether the inventory should eject any items inside its inventory.
    default boolean
    stillValid(net.minecraft.world.entity.player.Player player)
    Returns true if the container is still valid for the player to interact with.

    Methods inherited from interface net.minecraft.world.Container

    canPlaceItem, canTakeItem, countItem, getMaxStackSize, getMaxStackSize, hasAnyMatching, hasAnyOf, setChanged, startOpen, stopOpen

    Methods inherited from interface top.girlkisser.lazuli.api.block.IBE

    getBlockPos, getBlockState, getLevel, setChanged
  • Method Details

    • getInventory

      T getInventory()
      Get the block entity's inventory
      Returns:
      The inventory.
    • getInventory

      default T getInventory(net.minecraft.core.Direction side)
      Get the inventory on the given side, by default the inventory is non-sided, so this returns the main inventory.
      Parameters:
      side - The side to access.
      Returns:
      The inventory for that side.
    • getSlotsForFace

      default int[] getSlotsForFace(net.minecraft.core.Direction side)
      Gets the indexes to any slots accessible on the given side.
      Specified by:
      getSlotsForFace in interface net.minecraft.world.WorldlyContainer
      Parameters:
      side - The side to access.
      Returns:
      An array of slot indexes.
    • canPlaceItemThroughFace

      default boolean canPlaceItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, @Nullable @Nullable net.minecraft.core.Direction direction)
      Controls whether an item can be inserted into the given slot through the given face.
      Specified by:
      canPlaceItemThroughFace in interface net.minecraft.world.WorldlyContainer
      Parameters:
      index - The slot to check.
      stack - The item attempting to be inserted.
      direction - The direction the item is being inserted on.
      Returns:
      `true` if the item can be inserted.
    • canTakeItemThroughFace

      default boolean canTakeItemThroughFace(int index, net.minecraft.world.item.ItemStack stack, net.minecraft.core.Direction direction)
      Controls whether an item can be taken from the given slot through the given face.
      Specified by:
      canTakeItemThroughFace in interface net.minecraft.world.WorldlyContainer
      Parameters:
      index - The slot to check.
      stack - The item attempting to be inserted.
      direction - The direction the item is being inserted on.
      Returns:
      `true` if the item can be inserted.
    • fillStackedContents

      default void fillStackedContents(net.minecraft.world.entity.player.StackedContents contents)
      Specified by:
      fillStackedContents in interface net.minecraft.world.inventory.StackedContentsCompatible
    • isInventoryFull

      default boolean isInventoryFull()
      Gets whether the inventory has no empty slots.
      Returns:
      Whether the inventory has no empty slots or not.
    • getContainerSize

      default int getContainerSize()
      Specified by:
      getContainerSize in interface net.minecraft.world.Container
      Returns:
      The amount of slots in the inventory.
    • isEmpty

      default boolean isEmpty()
      Specified by:
      isEmpty in interface net.minecraft.world.Container
      Returns:
      `true` if all slots in the inventory are empty.
    • getItem

      default net.minecraft.world.item.ItemStack getItem(int slot)
      Get the item in the given slot index.
      Specified by:
      getItem in interface net.minecraft.world.Container
      Parameters:
      slot - The index to access.
      Returns:
      The item stack contained in the slot.
    • removeItem

      default net.minecraft.world.item.ItemStack removeItem(int slot, int amount)
      Removes `amount` items from the given slot and returns the taken ItemStack.
      Specified by:
      removeItem in interface net.minecraft.world.Container
      Parameters:
      slot - The slot to remove items from.
      amount - The amount to remove.
      Returns:
      An ItemStack containing the item removed and the amount removed.
    • removeItemNoUpdate

      default net.minecraft.world.item.ItemStack removeItemNoUpdate(int slot)
      Removes the item from the given slot without updating the container.
      Specified by:
      removeItemNoUpdate in interface net.minecraft.world.Container
      Parameters:
      slot - The slot to remove the item from.
      Returns:
      The item removed.
    • setItem

      default void setItem(int slot, net.minecraft.world.item.ItemStack stack)
      Set the ItemStack in the given slot.
      Specified by:
      setItem in interface net.minecraft.world.Container
      Parameters:
      slot - The slot index.
      stack - The stack.
    • stillValid

      default boolean stillValid(net.minecraft.world.entity.player.Player player)
      Returns true if the container is still valid for the player to interact with. The default implementation checks if the player is within range of the block entity.
      **This method will throw an exception if the level is null.**
      Specified by:
      stillValid in interface net.minecraft.world.Container
      Parameters:
      player - The player to check.
      Returns:
      `true` if the player is still able to access the inventory.
    • clearContent

      default void clearContent()
      Clear all items from the inventory.
      Specified by:
      clearContent in interface net.minecraft.world.Clearable
    • getFirstStackIndex

      default int getFirstStackIndex()
      Returns the index to the first non-empty ItemStack in the inventory or -1 if no such item exists.
      Returns:
      The index.
    • giveItem

      default net.minecraft.world.item.ItemStack giveItem(net.minecraft.world.item.ItemStack stack)
      Add an item to the inventory, returning the remainder. The provided stack is not mutated.
      Parameters:
      stack - The stack to insert.
      Returns:
      The remainder, if the stack could not be fully inserted.
    • shouldEjectItems

      default boolean shouldEjectItems()
      Whether the inventory should eject any items inside its inventory.
      Returns:
      Whether the inventory should eject any items inside its inventory.
    • canEjectSlot

      default boolean canEjectSlot(int slot)
      Returns true if the item in the given slot can be ejected.
      Parameters:
      slot - The slot to check.
      Returns:
      Whether the item in the slot can be ejected.
    • getEjectDirection

      default net.minecraft.core.Direction getEjectDirection(net.minecraft.world.level.block.state.BlockState state)
      Get the Direction to eject items at.
      Parameters:
      state - The BlockState of the implementing block entity.
      Returns:
      The direction to eject items at.
    • getRandomUsedSlot

      default int getRandomUsedSlot(net.minecraft.util.RandomSource random)
      Gets a random slot with at least 1 item in it.
      Parameters:
      random - Random source to use.
      Returns:
      The index to the random slot.
    • getRandomUsedSlot

      default int getRandomUsedSlot(net.minecraft.util.RandomSource random, int minimumCount)
      Gets a random slot with at least minimumCount items in it, or a slot where the maximum stack size equals 1.
      Parameters:
      random - Random source to use.
      minimumCount - The minimum count for a stack to be picked.
      Returns:
      The index to the random slot. Returns to -1 if no slots match.
    • ejectStack

      static net.minecraft.world.item.ItemStack ejectStack(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, net.minecraft.world.item.ItemStack toEject)
      Ejects an ItemStack into the world or into a valid container. This method does not care what the ejecting block is.
      Parameters:
      level - The level.
      pos - The position of the block ejecting the stack.
      direction - The direction to eject in.
      toEject - The stack to eject.
      Returns:
      If the stack could not be ejected (i.e, there is a block in the way or the container was full), this is the remainder.
    • ejectFrom

      static void ejectFrom(net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos, net.minecraft.core.Direction direction, int slot, int maxCount)
      Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
      Parameters:
      level - The level.
      pos - The position of the block ejecting the stack.
      direction - The direction to eject in.
      slot - The slot to eject from.
      maxCount - The maximum amount of items to eject.
    • ejectFrom

      static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>> void ejectFrom(IInventoryBE<T> be, int maxAmount)
      Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
      Type Parameters:
      T - The container type of the block entity.
      Parameters:
      be - The block entity to eject an item from.
      maxAmount - The maximum amount of items to eject.
    • ejectFrom

      static <T extends net.neoforged.neoforge.items.IItemHandler & net.neoforged.neoforge.items.IItemHandlerModifiable & net.neoforged.neoforge.common.util.INBTSerializable<net.minecraft.nbt.CompoundTag>> void ejectFrom(IInventoryBE<T> be, int slot, int maxAmount)
      Ejects an ItemStack into the world or into a valid container from an IInventoryBE.
      Type Parameters:
      T - The container type of the block entity.
      Parameters:
      be - The block entity to eject an item from.
      slot - The slot to eject from.
      maxAmount - The maximum amount of items to eject.
    • insertItemInto

      static net.minecraft.world.item.ItemStack insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack, int startIndex, int endIndex)
      Inserts an item into the provided item handler. Use startIndex and endIndex to only insert into a specific range of slots.
      Parameters:
      itemHandler - The item handler to insert into.
      stack - The stack to insert.
      startIndex - The first index to check (inclusive).
      endIndex - The last index to check (exclusive).
      Returns:
      The remainder item stack if not all items could be inserted.
    • insertItemInto

      static net.minecraft.world.item.ItemStack insertItemInto(net.neoforged.neoforge.items.IItemHandler itemHandler, net.minecraft.world.item.ItemStack stack)
      Inserts an item into the provided item handler. Use startIndex and endIndex to only insert into a specific range of slots.
      Parameters:
      itemHandler - The item handler to insert into.
      stack - The stack to insert.
      Returns:
      The remainder item stack if not all items could be inserted.
    • isFull

      static boolean isFull(net.neoforged.neoforge.items.IItemHandler handler)
      Returns true if the given handler has no empty slots.
      Parameters:
      handler - The handler to check.
      Returns:
      Whether the provided inventory is full.