Class StorageMenuDefinition

java.lang.Object
net.ixdarklord.coolcatcore.api.menu.StorageMenuDefinition

public final class StorageMenuDefinition extends Object
A menu for the inventory of a block or an item, declared once: where its slots go, what else the screen shows, and what its buttons do. It makes the MenuType to register, opens the menu, and keeps it in sync.
// A 9-slot crate, with the number of times it was used shown on the screen.
public static final StorageMenuDefinition CRATE = StorageMenuDefinition.grid(9, 1)
        .sync(CRATE_USES)
        .button(0, (menu, player) -> menu.getContainer().clearContent())
        .build();
public static final RegistryEntry<MenuType<StorageMenu>> CRATE_MENU = MENUS.register("crate", CRATE::createMenuType);

// Server, when the block is used:
CRATE.open(serverPlayer, crateBlockEntity, Component.translatable("container.mymod.crate"));
// Client, while it initialises:
MenuScreenRegistry.register(CRATE_MENU, StorageScreen::new);
Slots follow the container's ContainerLayout (filters, limits, output slots) and move with shift-click; the menu closes when the block is removed or the player walks away, or when an item's stack leaves its slot (which the menu locks meanwhile). Slot contents sync as in any vanilla menu; StorageMenuDefinition.Builder.sync(Attachment) values reach the screen too.
  • Method Details

    • builder

      public static StorageMenuDefinition.Builder builder()
      An empty definition: place the slots yourself. The player inventory goes at (8, 84) unless moved.
    • grid

      public static StorageMenuDefinition.Builder grid(int columns, int rows)
      The usual chest-like screen: columns by rows slots (container slots 0 upward), centred, with the player inventory below them.
    • createMenuType

      public net.minecraft.world.inventory.MenuType<StorageMenu> createMenuType()
      The menu type to register in Registries.MENU, e.g. MENUS.register("crate", CRATE::createMenuType).
    • open

      public void open(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.level.block.entity.BlockEntity blockEntity, net.minecraft.network.chat.Component title)
      Opens the menu on a block's inventory: an ExtendedContainerBlockEntity's, or any container HandlerTypes.CONTAINER finds there (a vanilla chest...).
    • open

      public void open(net.minecraft.server.level.ServerPlayer player, net.minecraft.world.InteractionHand hand, net.minecraft.network.chat.Component title)
      Opens the menu on the ContainerItem held in a hand.
    • open

      public void open(net.minecraft.server.level.ServerPlayer player, int inventorySlot, net.minecraft.network.chat.Component title)
      Opens the menu on the ContainerItem in one of the player's inventory slots.
    • open

      public void open(net.minecraft.server.level.ServerPlayer player, int inventorySlot, ContainerLayout layout, net.minecraft.network.chat.Component title)
      Opens the menu on the inventory kept in the stack in one of the player's slots, with the given layout.
    • slots

    • inventoryX

      public int inventoryX()
    • inventoryY

      public int inventoryY()
    • width

      public int width()
      The screen's width.
    • height

      public int height()
      The screen's height.