Package net.fabricmc.fabric.api.menu.v1


@NullMarked package net.fabricmc.fabric.api.menu.v1
The Fabric menu API for creating menu and menu types.

Menu types are used to synchronize menus between the server and the client. Their main job is to create menu instances on the client. Menus manage the items and integer properties that are needed to show on screens, such as the items in a chest or the progress of a furnace.

Simple and extended menus

"Simple" menus are the type of menus used in vanilla. They can automatically synchronize items and integer properties between the server and the client, but they don't support having custom data sent in the opening packet. You can create simple menus using vanilla's MenuType.

This module adds extended menus that can synchronize their own custom data when they are opened, which can be useful for defining additional properties of a screen on the server. For example, a mod can synchronize text that will show up as a label. You can create extended menus using ExtendedMenuType.

Opening menus

Menus can be opened using Player.openMenu(net.minecraft.world.MenuProvider). Note that calling it on the logical client does nothing. To open an extended menu, the factory passed in should be an ExtendedMenuProvider, or a SimpleMenuProvider that wraps such factory.

Overwriting menus

You might have noticed that calling openMenu while on another screen will move the cursor to the center of the screen. This is because the current screen gets closed before opening the screen, resetting the cursor position. Since this behavior can be problematic, this API provides a way to disable this. By overriding FabricMenuProvider.shouldCloseCurrentScreen() on the menu factory to return false and passing that to the openMenu method, it will stop closing the screen and instead "overwrites" it.
  • Class
    Description
    An extension of MenuProvider that can write additional data to a screen opening packet.
    ExtendedMenuType<T extends net.minecraft.world.inventory.AbstractContainerMenu, D>
    A MenuType for an extended menus that synchronizes additional data to the client when it is opened.
    ExtendedMenuType.ExtendedFactory<T extends net.minecraft.world.inventory.AbstractContainerMenu, D>
    A factory for creating menu instances from additional opening data.
    An extension to MenuProvider.