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'sMenuType.
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 usingPlayer.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 callingopenMenu 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.-
ClassDescriptionAn extension of
MenuProviderthat can write additional data to a screen opening packet.ExtendedMenuType<T extends net.minecraft.world.inventory.AbstractContainerMenu, D>AMenuTypefor 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 toMenuProvider.