Interface Containers.View
- Enclosing interface:
Containers
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 TypeMethodDescriptionarrange(Containers.Arrangement arrangement) Makes some of the menu's slots hold an exact layout (seeContainers.Arrangement): sorting, filling a kit, putting a hotbar back.booleanbyHand()Whether you opened it yourself (or the server did), rather than code throughContainers.open(BlockPos, int).voidclick(int screenSlot, int button, net.minecraft.world.inventory.ContainerInput action) Any click, with a raw screen slot id (-999for outside the window), button and input, ashandleContainerInputtakes them.voidclose()Containers.close()if this is still the open container; otherwise nothing.intTotal count of matching items in the container.voiddrop(int slot, boolean wholeStack) Drops a container slot's stack (or one item).intFirst empty container slot, or -1 if it's full.intFirst container slot whose stack matches (empty slots are skipped), or -1.net.minecraft.world.inventory.AbstractContainerMenuhandler()The game's menu for it, with every slot of its screen (the container's own, then your inventory's).booleanisLoaded()Whether the contents have arrived.booleanisOpen()Whether this container is still the one open (the server can close it, or another can open over it).@Nullable Objectopener()The owner that opened it throughContainers.open(Object, BlockPos, int), or null: opened by hand, by the server, or throughContainers.open(BlockPos, int)without an owner (seebyHand()).intplayerSlot(int inventoryIndex) The screen slot id for an inventory index (0-35) in this container's screen, forclick(int, int, ContainerInput)andContainers.Arrangements.@Nullable net.minecraft.core.BlockPospos()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) Liketake(Predicate, Containers.Transfer), the other way: itemswhataccepts from your inventory into the container.voidquickMove(int slot) Shift-clicks a container slot: moves its stack into your inventory.voidquickMoveFromPlayer(int inventoryIndex) Shift-clicks your inventory index (0-35): moves that stack 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 (seeInventory.refresh()).run(Containers.Planner planner) Runs your ownContainers.Planner's clicks the wayarrange(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.intsize()Number of the container's own slots (the player's inventory below them isn't counted).net.minecraft.world.item.ItemStackstack(int slot) What container slotslotholds; an empty stack outside0..size()-1.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).voidswapWithHotbar(int slot, int hotbarSlot) Swaps a container slot with a hotbar slot (0-8), like pressing a number key over it.intsyncId()The menu's id, as the server's packets name it (containerId).take(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how) Moves itemswhataccepts from the container into your inventory, as many ashowallows 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 throughContainers.open(Object, BlockPos, int), or null: opened by hand, by the server, or throughContainers.open(BlockPos, int)without an owner (seebyHand()). -
byHand
boolean byHand()Whether you opened it yourself (or the server did), rather than code throughContainers.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 slotslotholds; an empty stack outside0..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
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
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, forclick(int, int, ContainerInput)andContainers.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 (-999for outside the window), button and input, ashandleContainerInputtakes them. -
take
CompletableFuture<Integer> take(Predicate<net.minecraft.world.item.ItemStack> what, Containers.Transfer how) Moves itemswhataccepts from the container into your inventory, as many ashowallows 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) Liketake(Predicate, Containers.Transfer), the other way: itemswhataccepts from your inventory into the container. -
refresh
CompletableFuture<Containers.View> 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 (seeInventory.refresh()). Fails if the container has closed. -
arrange
Makes some of the menu's slots hold an exact layout (seeContainers.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 withtake(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 ownContainers.Planner's clicks the wayarrange(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 withContainers.Planner.done(). Fails if the container closes, or has. -
close
void close()Containers.close()if this is still the open container; otherwise nothing.
-