Package net.fabricmc.fabric.api.screenhandler.v1
package net.fabricmc.fabric.api.screenhandler.v1
The Fabric screen handler API for creating screen handlers and screen handler types.
Screen handlers types are used to synchronize screen handlers between the server and the client. Their main job is to create screen handler instances on the client. Screen handlers 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 screen handlers
"Simple" screen handlers are the type of screen handlers 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 screen handlers using vanilla'sScreenHandlerType
.
This module adds extended screen handlers 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 screen handlers using
ExtendedScreenHandlerType
.
Opening screen handlers
Screen handlers can be opened usingPlayerEntity.openHandledScreen(net.minecraft.screen.NamedScreenHandlerFactory)
.
Note that calling it on the logical client does nothing. To open an extended screen handler, the factory passed in
should be an ExtendedScreenHandlerFactory
, or a
SimpleNamedScreenHandlerFactory
that wraps such factory.
Overwriting screen handlers
You might have noticed that callingopenHandledScreen
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 FabricScreenHandlerFactory.shouldCloseCurrentScreen()
on the screen handler factory to return false
and passing that to the
openHandledScreen
method, it will stop closing the screen and instead "overwrites" it.-
ClassDescriptionAn extension of
NamedScreenHandlerFactory
that can write additional data to a screen opening packet.AScreenHandlerType
for an extended screen handler that synchronizes additional data to the client when it is opened.A factory for creating screen handler instances from additional opening data.An extension toNamedScreenHandlerFactory
.