Class Inventories

java.lang.Object
net.minecraft.inventory.Inventories

public class Inventories extends Object
Contains utility methods used by Inventory implementations or for working with inventories.
Mappings:
Namespace Name
official bjv
intermediary net/minecraft/class_1262
named net/minecraft/inventory/Inventories
  • Constructor Details

    • Inventories

      public Inventories()
  • Method Details

    • splitStack

      public static ItemStack splitStack(List<ItemStack> stacks, int slot, int amount)
      Returns the copy of the stack split from the stack at slot.

      This returns ItemStack.EMPTY when slot is out of bounds, the stack at the slot is empty, or when amount <= 0.

      Returns:
      the copy of the stack split from the stack at slot
      See Also:
      API Note:
      This is used to implement Inventory.removeStack(int, int). This should not otherwise be used directly.
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Ljava/util/List;II)Lcmy;
      intermediary method_5430 Lnet/minecraft/class_1262;method_5430(Ljava/util/List;II)Lnet/minecraft/class_1799;
      named splitStack Lnet/minecraft/inventory/Inventories;splitStack(Ljava/util/List;II)Lnet/minecraft/item/ItemStack;
    • removeStack

      public static ItemStack removeStack(List<ItemStack> stacks, int slot)
      Sets the stack at slot to ItemStack.EMPTY and returns the old stack.

      This returns ItemStack.EMPTY when slot is out of bounds.

      Returns:
      the stack previously at slot
      API Note:
      This is used to implement Inventory.removeStack(int). This should not otherwise be used directly.
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Ljava/util/List;I)Lcmy;
      intermediary method_5428 Lnet/minecraft/class_1262;method_5428(Ljava/util/List;I)Lnet/minecraft/class_1799;
      named removeStack Lnet/minecraft/inventory/Inventories;removeStack(Ljava/util/List;I)Lnet/minecraft/item/ItemStack;
    • writeNbt

      public static NbtCompound writeNbt(NbtCompound nbt, DefaultedList<ItemStack> stacks)
      Writes the inventory to nbt. This method will always write to the NBT, even if stacks only contains empty stacks.

      See writeNbt(NbtCompound, DefaultedList, boolean) for the serialization format.

      Returns:
      the passed nbt
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Lsn;Liq;)Lsn;
      intermediary method_5426 Lnet/minecraft/class_1262;method_5426(Lnet/minecraft/class_2487;Lnet/minecraft/class_2371;)Lnet/minecraft/class_2487;
      named writeNbt Lnet/minecraft/inventory/Inventories;writeNbt(Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/util/collection/DefaultedList;)Lnet/minecraft/nbt/NbtCompound;
    • writeNbt

      public static NbtCompound writeNbt(NbtCompound nbt, DefaultedList<ItemStack> stacks, boolean setIfEmpty)
      Writes the inventory to nbt.

      The inventory is serialized as a list of non-empty item stacks. In addition, each compound has a byte entry with the key Slot, indicating the slot. The list is then written to nbt under the key Items.

      If setIfEmpty is false and each stack in stacks is empty, then nbt will not be modified at all. Otherwise, the Items entry will always be present.

      Returns:
      the passed nbt
      See Also:
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Lsn;Liq;Z)Lsn;
      intermediary method_5427 Lnet/minecraft/class_1262;method_5427(Lnet/minecraft/class_2487;Lnet/minecraft/class_2371;Z)Lnet/minecraft/class_2487;
      named writeNbt Lnet/minecraft/inventory/Inventories;writeNbt(Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/util/collection/DefaultedList;Z)Lnet/minecraft/nbt/NbtCompound;
    • readNbt

      public static void readNbt(NbtCompound nbt, DefaultedList<ItemStack> stacks)
      Reads nbt and sets the elements of stacks accordingly.

      See writeNbt(NbtCompound, DefaultedList, boolean) for the serialization format. If the slot is out of bounds, it is ignored.

      See Also:
      Mappings:
      Namespace Name Mixin selector
      official b Lbjv;b(Lsn;Liq;)V
      intermediary method_5429 Lnet/minecraft/class_1262;method_5429(Lnet/minecraft/class_2487;Lnet/minecraft/class_2371;)V
      named readNbt Lnet/minecraft/inventory/Inventories;readNbt(Lnet/minecraft/nbt/NbtCompound;Lnet/minecraft/util/collection/DefaultedList;)V
    • remove

      public static int remove(Inventory inventory, Predicate<ItemStack> shouldRemove, int maxCount, boolean dryRun)
      Removes a number, not exceeding maxCount, of items from an inventory based on a predicate and returns that number.
      Parameters:
      dryRun - whether to return the number of items which would have been removed without actually removing them
      Returns:
      the number of items removed
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Lbju;Ljava/util/function/Predicate;IZ)I
      intermediary method_29234 Lnet/minecraft/class_1262;method_29234(Lnet/minecraft/class_1263;Ljava/util/function/Predicate;IZ)I
      named remove Lnet/minecraft/inventory/Inventories;remove(Lnet/minecraft/inventory/Inventory;Ljava/util/function/Predicate;IZ)I
    • remove

      public static int remove(ItemStack stack, Predicate<ItemStack> shouldRemove, int maxCount, boolean dryRun)
      Removes a number, not exceeding maxCount, of items from an item stack based on a predicate and returns that number.
      Parameters:
      dryRun - whether to return the number of items which would have been removed without actually removing them
      Returns:
      the number of items removed
      Mappings:
      Namespace Name Mixin selector
      official a Lbjv;a(Lcmy;Ljava/util/function/Predicate;IZ)I
      intermediary method_29235 Lnet/minecraft/class_1262;method_29235(Lnet/minecraft/class_1799;Ljava/util/function/Predicate;IZ)I
      named remove Lnet/minecraft/inventory/Inventories;remove(Lnet/minecraft/item/ItemStack;Ljava/util/function/Predicate;IZ)I