Interface SlotGroupResolver

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface SlotGroupResolver
Maps one menu class's instances to slot groups by SlotGroupCategory, as slot indices (positions in menu.slots). The library turns indices into Slots itself (SlotGroupCategories.of(AbstractContainerMenu)), so a consumer never holds a raw vanilla Slot.

The vanilla resolvers ship with SlotKit (registered at its init). A mod registers resolvers for its own menu classes with SlotGroupCategories.register(Class, SlotGroupResolver).

SlotGroupPanelAdapter turns the returned index arrays into slot-group bounding boxes each frame. Each slot should appear in exactly one category's array: one category has many slots, and a slot has one category.

Resolution runs once per screen open, and the result is kept for the screen's lifetime. Menus whose slot set changes while open are not supported.

Indices, not raw slots

This interface used to return List<Slot>, the one place MenuKit handed a consumer raw vanilla slots. Now a consumer describes a group by index and never reads menu.slots. Two cases cover every need:
  • Vanilla slot groups (the hotbar, a furnace's input, the crafting grid) already ship as built-in SlotGroupCategory constants (VanillaSlotGroupResolvers). A consumer anchors to SlotGroupCategory.PLAYER_HOTBAR directly, with no resolver.
  • A consumer's own menu: the consumer built it, so its slot order is the consumer's own. int[] indices into that order refer to the consumer's layout, not vanilla's.
So a consumer writes resolvers only for its own menu classes, in its own index space. See also SlotGroupCategories.
  • Method Summary

    Modifier and Type
    Method
    Description
    resolve(net.minecraft.world.inventory.AbstractContainerMenu menu)
    Maps the given menu instance's slots to category-keyed index arrays.
  • Method Details

    • resolve

      Map<SlotGroupCategory, int[]> resolve(net.minecraft.world.inventory.AbstractContainerMenu menu)
      Maps the given menu instance's slots to category-keyed index arrays. Returns an empty map for categories the menu doesn't contain (rather than populating with empty arrays). SlotGroupCategories.of(AbstractContainerMenu) skips out-of-range indices when it reads the slots.