Class ItemContainers

java.lang.Object
net.ixdarklord.coolcatcore.api.container.ItemContainers

public final class ItemContainers extends Object
Inventories kept in an item stack's NBT, as vanilla keeps them: an Items list in the stack's BlockEntityTag for block items (as shulker boxes keep theirs, so placing the block restores the contents), and in the stack's own tag for other items (as bundles do).

 SlotContainer pouch = ItemContainers.of(stack, POUCH_LAYOUT);
 pouch.insert(new ItemStack(Items.DIAMOND), false);   // written back to the stack right away
 player.openMenu(new SimpleMenuProvider((id, inventory, p) -> new PouchMenu(id, inventory, pouch), title));
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The list holding the contents, in ContainerHelper.saveAllItems(net.minecraft.nbt.CompoundTag, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>) format.
  • Method Summary

    Modifier and Type
    Method
    Description
    static @Nullable net.minecraft.nbt.CompoundTag
    contentsTag(net.minecraft.world.item.ItemStack stack)
    The tag holding the stack's Items list: its BlockEntityTag for block items, its own tag otherwise; null when there's none.
    static @Nullable SlotContainer
    of(net.minecraft.world.item.ItemStack stack)
    The inventory of a ContainerItem's stack, or null for other items.
    of(net.minecraft.world.item.ItemStack stack, ContainerLayout layout)
    The stack's inventory: reads the stack now and writes every change back to it.

    Methods inherited from class java.lang.Object

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

    • ITEMS_TAG

      public static final String ITEMS_TAG
      The list holding the contents, in ContainerHelper.saveAllItems(net.minecraft.nbt.CompoundTag, net.minecraft.core.NonNullList<net.minecraft.world.item.ItemStack>) format.
      See Also:
  • Method Details

    • of

      public static SlotContainer of(net.minecraft.world.item.ItemStack stack, ContainerLayout layout)
      The stack's inventory: reads the stack now and writes every change back to it. Keep it only as long as the stack is the one in use (a menu should check the player still holds it).
    • of

      @Nullable public static @Nullable SlotContainer of(net.minecraft.world.item.ItemStack stack)
      The inventory of a ContainerItem's stack, or null for other items.
    • contentsTag

      @Nullable public static @Nullable net.minecraft.nbt.CompoundTag contentsTag(net.minecraft.world.item.ItemStack stack)
      The tag holding the stack's Items list: its BlockEntityTag for block items, its own tag otherwise; null when there's none.