Interface Containers.View

Enclosing interface:
Containers

@NonExtendable public static interface Containers.View
A container that's open (or was), from Containers.current() or Containers.open(BlockPos, int): usable while isOpen(), and a stale handle after (its clicks do nothing and the futures it starts fail). Slot numbers are the container's own (0 = its first slot), unless noted.

The single clicks (quickMove(int), quickMoveFromPlayer(int), swapWithHotbar(int, int), drop(int, boolean), click(int, int, ContainerInput)) do nothing once the container has closed, or on a tick the server would refuse them (while you move, see Inventory.safeToClick()); your keys are then released for the next tick, so a click asked for again then works. They don't check the click budget or wait for the server's answer to the last click: before a run of clicks that belong together, check Inventory.prepareClick() and Myriad.limits().canSend(PacketLimits.Kind.INVENTORY, n) (2b2t disconnects you for too many). take(Predicate, Containers.Transfer) and put(Predicate, Containers.Transfer) do all of that themselves.

  • Method Summary

    Modifier and Type
    Method
    Description
    Makes some of the menu's slots hold an exact layout (see Containers.Arrangement): sorting, filling a kit, putting a hotbar back.
    boolean
    Whether you opened it yourself (or the server did), rather than code through Containers.open(BlockPos, int).
    void
    click(int screenSlot, int button, net.minecraft.world.inventory.ContainerInput action)
    Any click, with a raw screen slot id (-999 for outside the window), button and input, as handleContainerInput takes them.
    void
    Containers.close() if this is still the open container; otherwise nothing.
    int
    count(Predicate<net.minecraft.world.item.ItemStack> predicate)
    Total count of matching items in the container.
    void
    drop(int slot, boolean wholeStack)
    Drops a container slot's stack (or one item).
    int
    First empty container slot, or -1 if it's full.
    int
    find(Predicate<net.minecraft.world.item.ItemStack> predicate)
    First container slot whose stack matches (empty slots are skipped), or -1.
    net.minecraft.world.inventory.AbstractContainerMenu
    The game's menu for it, with every slot of its screen (the container's own, then your inventory's).
    boolean
    Whether the contents have arrived.
    boolean
    Whether this container is still the one open (the server can close it, or another can open over it).
    @Nullable Object
    The owner that opened it through Containers.open(Object, BlockPos, int), or null: opened by hand, by the server, or through Containers.open(BlockPos, int) without an owner (see byHand()).
    int
    playerSlot(int inventoryIndex)
    The screen slot id for an inventory index (0-35) in this container's screen, for click(int, int, ContainerInput) and Containers.Arrangements.
    @Nullable net.minecraft.core.BlockPos
    pos()
    The block it was opened from, when known (it was opened by clicking a block just before).
    put(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how)
    Like take(Predicate, Containers.Transfer), the other way: items what accepts from your inventory into the container.
    void
    quickMove(int slot)
    Shift-clicks a container slot: moves its stack into your inventory.
    void
    quickMoveFromPlayer(int inventoryIndex)
    Shift-clicks your inventory index (0-35): moves that stack into the container.
    Asks the server for the container's contents (and your inventory's) and completes once they're here: what the client shows is then what the server has (see Inventory.refresh()).
    Runs your own Containers.Planner's clicks the way arrange(Containers.Arrangement) runs its own: at tick starts, within the budget and the server's rules, then checked against the server, three rounds at most.
    int
    Number of the container's own slots (the player's inventory below them isn't counted).
    net.minecraft.world.item.ItemStack
    stack(int slot)
    What container slot slot holds; an empty stack outside 0..size()-1.
    List<net.minecraft.world.item.ItemStack>
    The container's own slots in order, as a new list of the menu's stacks (don't change the stacks).
    void
    swapWithHotbar(int slot, int hotbarSlot)
    Swaps a container slot with a hotbar slot (0-8), like pressing a number key over it.
    int
    The menu's id, as the server's packets name it (containerId).
    take(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how)
    Moves items what accepts from the container into your inventory, as many as how allows and there is room for, and completes with how many went by the server's count.
  • Method Details

    • handler

      net.minecraft.world.inventory.AbstractContainerMenu handler()
      The game's menu for it, with every slot of its screen (the container's own, then your inventory's).
    • syncId

      int syncId()
      The menu's id, as the server's packets name it (containerId).
    • pos

      @Nullable net.minecraft.core.BlockPos pos()
      The block it was opened from, when known (it was opened by clicking a block just before).
    • isLoaded

      boolean isLoaded()
      Whether the contents have arrived. Before that, slots read as empty.
    • isOpen

      boolean isOpen()
      Whether this container is still the one open (the server can close it, or another can open over it).
    • opener

      @Nullable Object opener()
      The owner that opened it through Containers.open(Object, BlockPos, int), or null: opened by hand, by the server, or through Containers.open(BlockPos, int) without an owner (see byHand()).
    • byHand

      boolean byHand()
      Whether you opened it yourself (or the server did), rather than code through Containers.open(BlockPos, int).
    • size

      int size()
      Number of the container's own slots (the player's inventory below them isn't counted).
    • stack

      net.minecraft.world.item.ItemStack stack(int slot)
      What container slot slot holds; an empty stack outside 0..size()-1. The menu's own stack: don't change it.
    • stacks

      List<net.minecraft.world.item.ItemStack> stacks()
      The container's own slots in order, as a new list of the menu's stacks (don't change the stacks).
    • find

      int find(Predicate<net.minecraft.world.item.ItemStack> predicate)
      First container slot whose stack matches (empty slots are skipped), or -1.
    • emptySlot

      int emptySlot()
      First empty container slot, or -1 if it's full.
    • count

      int count(Predicate<net.minecraft.world.item.ItemStack> predicate)
      Total count of matching items in the container.
    • playerSlot

      int playerSlot(int inventoryIndex)
      The screen slot id for an inventory index (0-35) in this container's screen, for click(int, int, ContainerInput) and Containers.Arrangements.
      Throws:
      IllegalArgumentException - for armour or the off hand, which container screens don't show
    • quickMove

      void quickMove(int slot)
      Shift-clicks a container slot: moves its stack into your inventory.
    • quickMoveFromPlayer

      void quickMoveFromPlayer(int inventoryIndex)
      Shift-clicks your inventory index (0-35): moves that stack into the container.
    • swapWithHotbar

      void swapWithHotbar(int slot, int hotbarSlot)
      Swaps a container slot with a hotbar slot (0-8), like pressing a number key over it.
    • drop

      void drop(int slot, boolean wholeStack)
      Drops a container slot's stack (or one item).
    • click

      void click(int screenSlot, int button, net.minecraft.world.inventory.ContainerInput action)
      Any click, with a raw screen slot id (-999 for outside the window), button and input, as handleContainerInput takes them.
    • take

      CompletableFuture<Integer> take(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how)
      Moves items what accepts from the container into your inventory, as many as how allows and there is room for, and completes with how many went by the server's count. Whole stacks go with a shift click; part of one is picked up and shared out (onto stacks of the same item first), and the cursor is empty again after each stack. The clicks wait for ticks the server takes them on, within the packet budget (PacketLimits), so a large move takes a few seconds. Once the planned clicks are made, the server is asked what it has (refresh()); a click it never took or a slot someone else changed meanwhile gets another round, up to three.

      Moves on one container run one after another. It fails if the container closes (also when it's closed already), or another click (yours, or a module's) moves the cursor's items while it runs.

    • put

      CompletableFuture<Integer> put(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how)
      Like take(Predicate, Containers.Transfer), the other way: items what accepts from your inventory into the container.
    • refresh

      Asks the server for the container's contents (and your inventory's) and completes once they're here: what the client shows is then what the server has (see Inventory.refresh()). Fails if the container has closed.
    • arrange

      Makes some of the menu's slots hold an exact layout (see Containers.Arrangement): sorting, filling a kit, putting a hotbar back. Planned one click at a time from the menu as it is, so a click the server didn't take or a slot that changed is planned around; once there's nothing more to click the server is asked what it has, and if that isn't the layout it goes again, three rounds at most. Slots are put right in order: everything before the first wrong one stays put and what's after it is room to work in, so a full container sorts without a free slot of yours. Clicks wait for ticks the server takes them on, within the packet budget, queued with take(Predicate, Containers.Transfer)/put(Predicate, Containers.Transfer) on this container so they never interleave.

      Completes with whether the layout was reached; fails if the container closes, or another click moves the cursor's items meanwhile.

    • run

      Runs your own Containers.Planner's clicks the way arrange(Containers.Arrangement) runs its own: at tick starts, within the budget and the server's rules, then checked against the server, three rounds at most. Completes with Containers.Planner.done(). Fails if the container closes, or has.
    • close

      void close()
      Containers.close() if this is still the open container; otherwise nothing.