Class ItemHandlerHelper

java.lang.Object
net.neoforged.neoforge.items.ItemHandlerHelper

public class ItemHandlerHelper extends Object
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    This method uses the standard vanilla algorithm to calculate a comparator output for how "full" the inventory is.
    static void
    giveItemToPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
    giveItemToPlayer without preferred slot
    static void
    giveItemToPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, int preferredSlot)
    Inserts the given itemstack into the players inventory.
    static net.minecraft.world.item.ItemStack
    insertItem(IItemHandler dest, net.minecraft.world.item.ItemStack stack, boolean simulate)
     
    static net.minecraft.world.item.ItemStack
    insertItemStacked(IItemHandler inventory, net.minecraft.world.item.ItemStack stack, boolean simulate)
    Inserts the ItemStack into the inventory, filling up already present stacks first.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ItemHandlerHelper

      public ItemHandlerHelper()
  • Method Details

    • insertItem

      public static net.minecraft.world.item.ItemStack insertItem(IItemHandler dest, net.minecraft.world.item.ItemStack stack, boolean simulate)
    • insertItemStacked

      public static net.minecraft.world.item.ItemStack insertItemStacked(IItemHandler inventory, net.minecraft.world.item.ItemStack stack, boolean simulate)
      Inserts the ItemStack into the inventory, filling up already present stacks first. This is equivalent to the behaviour of a player picking up an item. Note: This function stacks items without subtypes with different metadata together.
    • giveItemToPlayer

      public static void giveItemToPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack)
      giveItemToPlayer without preferred slot
    • giveItemToPlayer

      public static void giveItemToPlayer(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack stack, int preferredSlot)
      Inserts the given itemstack into the players inventory. If the inventory can't hold it, the item will be dropped in the world at the players position.
      Parameters:
      player - The player to give the item to
      stack - The itemstack to insert
    • calcRedstoneFromInventory

      public static int calcRedstoneFromInventory(@Nullable @Nullable IItemHandler inv)
      This method uses the standard vanilla algorithm to calculate a comparator output for how "full" the inventory is. This method is an adaptation of Container#calcRedstoneFromInventory(IInventory).
      Parameters:
      inv - The inventory handler to test.
      Returns:
      A redstone value in the range [0,15] representing how "full" this inventory is.