Class InventoryHelpers

java.lang.Object
org.cyclops.cyclopscore.helper.InventoryHelpers

public class InventoryHelpers extends Object
Contains helper methods involving ContainerS.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addStackToList(net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> itemStacks, net.minecraft.world.item.ItemStack itemStack)
    Add the given stack to the given list, by attempting to increase the stacksize of equal stacks that are already present.
    static net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>
    addToInventory(net.minecraft.world.Container inventory, int[] slots, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> itemStacks, boolean simulate)
    Try to add the given item to any of the given slots.
    static boolean
    addToSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack)
    Try to add the given item to the given slot.
    static boolean
    addToSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack, boolean simulate)
    Try to add the given item to the given slot.
    static net.minecraft.world.item.ItemStack
    addToStack(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.ItemStack toAdd)
    Tries to merge the given stacks.
    static void
    clearInventory(net.minecraft.world.Container inventory)
    Erase a complete inventory
    static void
    dropItems(net.minecraft.world.level.Level world, net.minecraft.world.Container inventory, net.minecraft.core.BlockPos blockPos)
    Drop an ItemStack into the world
    static net.minecraft.world.item.ItemStack
    fillSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack, boolean simulate)
    Try to add the given item to the given slot.
    static net.minecraft.world.item.ItemStack
    getItemFromIndex(net.minecraft.world.entity.player.Player player, int itemIndex)
    Deprecated.
    static net.minecraft.world.item.ItemStack
    getItemFromIndex(net.minecraft.world.entity.player.Player player, int itemIndex, net.minecraft.world.InteractionHand hand)
    Deprecated.
    Use IInventoryLocation
    static void
    readFromNBT(net.minecraft.world.Container inventory, net.minecraft.nbt.CompoundTag data, String tagName)
    Read an inventory from NBT.
    static void
    setItemAtIndex(net.minecraft.world.entity.player.Player player, int itemIndex, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack itemStack)
    Deprecated.
    Use IInventoryLocation
    static void
    tryReAddToStack(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack originalStack, net.minecraft.world.item.ItemStack newStackPart)
    Deprecated.
    static void
    tryReAddToStack(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack originalStack, net.minecraft.world.item.ItemStack newStackPart, net.minecraft.world.InteractionHand hand)
    Try adding a new item stack originating from the given original stack to the same original stack.
    static void
    validateNBTStorage(net.minecraft.world.Container inventory, net.minecraft.world.item.ItemStack itemStack, String tagName)
    Validate the NBT storage of the given inventory in the given item.
    static void
    writeToNBT(net.minecraft.world.Container inventory, net.minecraft.nbt.CompoundTag data, String tagName)
    Write the given inventory to NBT.

    Methods inherited from class java.lang.Object

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

    • InventoryHelpers

      public InventoryHelpers()
  • Method Details

    • dropItems

      public static void dropItems(net.minecraft.world.level.Level world, net.minecraft.world.Container inventory, net.minecraft.core.BlockPos blockPos)
      Drop an ItemStack into the world
      Parameters:
      world - the world
      inventory - inventory with ItemStacks
      blockPos - The position.
    • clearInventory

      public static void clearInventory(net.minecraft.world.Container inventory)
      Erase a complete inventory
      Parameters:
      inventory - inventory to clear
    • tryReAddToStack

      @Deprecated public static void tryReAddToStack(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack originalStack, net.minecraft.world.item.ItemStack newStackPart)
      Deprecated.
      Try adding a new item stack originating from the given original stack to the same original stack. The original item stack should not have it's stack-size decreased yet, this method does this. Otherwise it will add the new stack to another inventory slot and in the worst case drop it on the floor.
      Parameters:
      player - The player.
      originalStack - The original item stack from which the new item stack originated.
      newStackPart - The new item stack.
    • tryReAddToStack

      public static void tryReAddToStack(net.minecraft.world.entity.player.Player player, net.minecraft.world.item.ItemStack originalStack, net.minecraft.world.item.ItemStack newStackPart, net.minecraft.world.InteractionHand hand)
      Try adding a new item stack originating from the given original stack to the same original stack. The original item stack should not have it's stack-size decreased yet, this method does this. Otherwise it will add the new stack to another inventory slot and in the worst case drop it on the floor.
      Parameters:
      player - The player.
      originalStack - The original item stack from which the new item stack originated.
      newStackPart - The new item stack.
      hand - The hand for which the stack should be re-added
    • validateNBTStorage

      public static void validateNBTStorage(net.minecraft.world.Container inventory, net.minecraft.world.item.ItemStack itemStack, String tagName)
      Validate the NBT storage of the given inventory in the given item. Should be called in constructors of inventories.
      Parameters:
      inventory - The inventory.
      itemStack - The item stack to read/write.
      tagName - The tag name to read from.
    • readFromNBT

      public static void readFromNBT(net.minecraft.world.Container inventory, net.minecraft.nbt.CompoundTag data, String tagName)
      Read an inventory from NBT.
      Parameters:
      inventory - The inventory.
      data - The tag to read from.
      tagName - The tag name to read from.
    • writeToNBT

      public static void writeToNBT(net.minecraft.world.Container inventory, net.minecraft.nbt.CompoundTag data, String tagName)
      Write the given inventory to NBT.
      Parameters:
      inventory - The inventory.
      data - The tag to write to.
      tagName - The tag name to write into.
    • getItemFromIndex

      @Deprecated public static net.minecraft.world.item.ItemStack getItemFromIndex(net.minecraft.world.entity.player.Player player, int itemIndex)
      Deprecated.
      Get the item stack from the given index in the player inventory.
      Parameters:
      player - The player.
      itemIndex - The index of the item in the inventory.
      Returns:
      The item stack.
    • getItemFromIndex

      @Deprecated public static net.minecraft.world.item.ItemStack getItemFromIndex(net.minecraft.world.entity.player.Player player, int itemIndex, net.minecraft.world.InteractionHand hand)
      Deprecated.
      Use IInventoryLocation
      Get the item stack from the given index in the player inventory.
      Parameters:
      player - The player.
      itemIndex - The index of the item in the inventory.
      hand - The hand the item is in.
      Returns:
      The item stack.
    • setItemAtIndex

      @Deprecated public static void setItemAtIndex(net.minecraft.world.entity.player.Player player, int itemIndex, net.minecraft.world.InteractionHand hand, net.minecraft.world.item.ItemStack itemStack)
      Deprecated.
      Use IInventoryLocation
      Set the item stack at the given index in the player inventory.
      Parameters:
      player - The player.
      itemIndex - The index of the item in the inventory.
      hand - The hand the item is in.
      itemStack - The new item stack.
    • addToSlot

      public static boolean addToSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack)
      Try to add the given item to the given slot.
      Parameters:
      inventory - The inventory.
      slot - The slot to add to.
      itemStack - The item to try to put in the production slot.
      Returns:
      If the item could be added or joined in the production slot.
    • addToStack

      public static net.minecraft.world.item.ItemStack addToStack(net.minecraft.world.item.ItemStack itemStack, net.minecraft.world.item.ItemStack toAdd)
      Tries to merge the given stacks.
      Parameters:
      itemStack - The stack to mutate and add to.
      toAdd - The stack to add.
      Returns:
      The remainder of the added stack
    • fillSlot

      public static net.minecraft.world.item.ItemStack fillSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack, boolean simulate)
      Try to add the given item to the given slot.
      Parameters:
      inventory - The inventory.
      slot - The slot to add to.
      itemStack - The item to try to put in the production slot.
      simulate - If the operation should be simulated.
      Returns:
      The remaining itemstack that could not be added anymore.
    • addToSlot

      public static boolean addToSlot(net.minecraft.world.Container inventory, int slot, net.minecraft.world.item.ItemStack itemStack, boolean simulate)
      Try to add the given item to the given slot.
      Parameters:
      inventory - The inventory.
      slot - The slot to add to.
      itemStack - The item to try to put in the production slot.
      simulate - If the operation should be simulated.
      Returns:
      If the item could be added or joined in the production slot.
    • addToInventory

      public static net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> addToInventory(net.minecraft.world.Container inventory, int[] slots, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> itemStacks, boolean simulate)
      Try to add the given item to any of the given slots.
      Parameters:
      inventory - The inventory.
      slots - The slots
      itemStacks - The items to try to put in the inventory.
      simulate - If the operation should be simulated.
      Returns:
      The remaining itemstack that could not be added anymore.
    • addStackToList

      public static void addStackToList(net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack> itemStacks, net.minecraft.world.item.ItemStack itemStack)
      Add the given stack to the given list, by attempting to increase the stacksize of equal stacks that are already present.
      Parameters:
      itemStacks - The list of stacks.
      itemStack - The stack to add to the list.