Class InventoryUtil

java.lang.Object
my.celium.org.util.InventoryUtil

public final class InventoryUtil extends Object
Small cohesive inventory helpers over vanilla Container. Slot counts are small; all scans are linear and allocation-free in spirit.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    contains(net.minecraft.world.Container container, net.minecraft.world.item.Item item, int amount)
     
    static int
    count(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter)
     
    static int
    count(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> filter)
     
    static int
    countItem(net.minecraft.world.Container container, net.minecraft.world.item.Item item)
     
    static int
    findSlot(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter)
    First slot matching the filter, or -1.
    static boolean
    holdOne(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> filter)
    Deprecated, for removal: This API element is subject to removal in a future version.
    despite its name this never moved anything into the hand; it only reports whether a match exists.
    static net.minecraft.world.item.ItemStack
    insert(net.minecraft.world.Container container, net.minecraft.world.item.ItemStack stack)
    Inserts stack, merging with existing stacks first.
    static int
    remove(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter, int amount)
    Removes up to amount matching items.
    static int
    removeItem(net.minecraft.world.Container container, net.minecraft.world.item.Item item, int amount)
     

    Methods inherited from class Object

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

    • count

      public static int count(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter)
    • count

      public static int count(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> filter)
    • countItem

      public static int countItem(net.minecraft.world.Container container, net.minecraft.world.item.Item item)
    • contains

      public static boolean contains(net.minecraft.world.Container container, net.minecraft.world.item.Item item, int amount)
    • remove

      public static int remove(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter, int amount)
      Removes up to amount matching items. Returns how many were actually removed.
    • removeItem

      public static int removeItem(net.minecraft.world.Container container, net.minecraft.world.item.Item item, int amount)
    • insert

      public static net.minecraft.world.item.ItemStack insert(net.minecraft.world.Container container, net.minecraft.world.item.ItemStack stack)
      Inserts stack, merging with existing stacks first. Returns the leftover (possibly empty). The passed stack is consumed.
    • findSlot

      public static int findSlot(net.minecraft.world.Container container, Predicate<net.minecraft.world.item.ItemStack> filter)
      First slot matching the filter, or -1.
    • holdOne

      @Deprecated(since="1.4.0", forRemoval=true) public static boolean holdOne(net.minecraft.world.entity.player.Player player, Predicate<net.minecraft.world.item.ItemStack> filter)
      Deprecated, for removal: This API element is subject to removal in a future version.
      despite its name this never moved anything into the hand; it only reports whether a match exists. Use findSlot(Container, Predicate) instead. Removed in Mycel 2.0.
      Whether the player's inventory holds an item matching filter.