Slot regions
These types tell an inventory tool which of a menu’s slots belong to the player and which to the container, on either side, and let mods and resource packs describe menus the sorting rules get wrong.
At a glance
Section titled “At a glance”| Type | Summary | Status | Since | Side | Thread |
|---|---|---|---|---|---|
ContainerProfile |
How inventory tools treat one menu type, registered with ContainerProfiles. |
Experimental | 2.10.0 | both | any |
ContainerProfiles |
Profiles of menu types, for inventory tools: which menus to leave alone, which draw their own buttons, and how a menu’s container slots split into regions. | Experimental | 2.10.0 | both | setup |
MenuRegions |
One menu’s slots, sorted by SlotRegions#of. |
Experimental | 2.10.0 | both | any |
ProfileRegionFinder |
Finds a menu’s container regions when the menu is sorted, where a ContainerProfile names them by fixed slot indexes. |
Experimental | 2.11.0 | both | any |
SlotRegion |
What a menu slot is for, as SlotRegions#of sorts them. |
Experimental | 2.10.0 | both | any |
SlotRegions |
Sorts a menu’s slots into regions for inventory tools: sorting, moving stacks, drawing buttons beside the right slots. | Experimental | 2.10.0 | both | any |
Quick start
Section titled “Quick start”On the server, with menu the player’s open menu, slot the menu slot index the player
clicked, and Sorter.sortSlots the mod’s own sorting:
MenuRegions.Region region = SlotRegions.of(menu).regionAt(slot);if (region != null && region.plainSlots() && region.kind() == SlotRegion.CONTAINER) { Sorter.sortSlots(menu, region.slots());}SlotRegions
Section titled “SlotRegions”MenuRegions: Experimental · Since 2.10.0 · Side: both · Thread: any
SlotRegions: Experimental · Since 2.10.0 · Side: both · Thread: any
SlotRegions#of sorts a whole menu into a MenuRegions; ask SlotRegions#inventorySlot
where one slot is enough. With LOCKED, the mod’s array of 41 flags by inventory index, in a
SlotOverlayCallback listener
given screen and slot:
// The creative screen's own slots carry other numbers.if (screen instanceof CreativeModeInventoryScreen) return;int index = SlotRegions.inventorySlot(slot);boolean locked = index >= 0 && LOCKED[index];With regions, a menu’s MenuRegions, and region, one of its container regions whose
rows are all as long as its first, on either side:
int columns = regions.columnsAt(region.slot(0));int rows = (region.size() + columns - 1) / columns;ContainerProfiles and ContainerProfile
Section titled “ContainerProfiles and ContainerProfile”ContainerProfile: Experimental · Since 2.10.0 · Side: both · Thread: any
ContainerProfiles: Experimental · Since 2.10.0 · Side: both · Thread: setup
ContainerProfiles holds what a mod or a resource pack says about a menu type: leave it alone,
it draws its own buttons, or its container slots split into regions. With id("sorter") the
mod’s sorter menu type, whose first nine slots are filters, in common initialization:
ContainerProfiles.register(id("sorter"), new ContainerProfile(false, false, List.of( new ContainerProfile.ProfileRegion(SlotRegion.CONTAINER, 9, 35))));ProfileRegionFinder
Section titled “ProfileRegionFinder”Experimental · Since 2.11.0 · Side: both · Thread: any
A menu type whose menus differ in size has no fixed indexes to give, so a mod registers a
ProfileRegionFinder for it, which names the regions of each menu as it is sorted. With
BACKPACK the ID of another mod’s backpack menu type, whose storage comes first and grows
with the backpack’s tier, followed by TOOL_SLOTS tool slots before the player’s inventory,
in common initialization:
ContainerProfiles.registerRegions(BACKPACK, menu -> { int playerSlots = 0; for (Slot slot : menu.slots) { if (SlotRegions.inventorySlot(slot) >= 0) playerSlots++; } int storage = menu.slots.size() - playerSlots - TOOL_SLOTS; return storage > 0 ? List.of(new ContainerProfile.ProfileRegion(SlotRegion.CONTAINER, 0, storage - 1)) : List.of();});See also
Section titled “See also”- Container profile format: the same profiles in a resource pack.
- Container screens and keys:
ContainerKeyCallback, which gives the hovered slot to act on.