public final class ScreenHandlerRegistry extends Object
This class exposes the private ScreenHandlerType
constructor,
as well as adds support for creating types using Fabric's extended screen handler API.
Screen handlers types are used to synchronize screen handlers between the server and 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.
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.
// Creating the screen handler type
public static final ScreenHandlerType<OvenScreenHandler> OVEN = ScreenHandlerRegistry.registerSimple(new Identifier("my_mod", "oven"), OvenScreenHandler::new);
// Screen handler class
public class OvenScreenHandler extends ScreenHandler {
public OvenScreenHandler(int syncId) {
super(MyScreenHandlers.OVEN, syncId);
}
}
// Opening the screen
NamedScreenHandlerFactory factory = ...;
player.openHandledScreen(factory); // only works on ServerPlayerEntity instances
registering screens for screen handlers
Modifier and Type | Class and Description |
---|---|
static interface |
ScreenHandlerRegistry.ExtendedClientHandlerFactory<T extends net.minecraft.screen.ScreenHandler>
A factory for client-sided screen handler instances
with additional screen opening data.
|
static interface |
ScreenHandlerRegistry.SimpleClientHandlerFactory<T extends net.minecraft.screen.ScreenHandler>
A factory for client-sided screen handler instances.
|
Modifier and Type | Method and Description |
---|---|
static <T extends net.minecraft.screen.ScreenHandler> |
registerExtended(net.minecraft.util.Identifier id,
ScreenHandlerRegistry.ExtendedClientHandlerFactory<T> factory)
Creates and registers a new
ScreenHandlerType that creates client-sided screen handlers with additional
networked opening data. |
static <T extends net.minecraft.screen.ScreenHandler> |
registerSimple(net.minecraft.util.Identifier id,
ScreenHandlerRegistry.SimpleClientHandlerFactory<T> factory)
Creates and registers a new
ScreenHandlerType that creates client-sided screen handlers using the factory. |
public static <T extends net.minecraft.screen.ScreenHandler> net.minecraft.screen.ScreenHandlerType<T> registerSimple(net.minecraft.util.Identifier id, ScreenHandlerRegistry.SimpleClientHandlerFactory<T> factory)
ScreenHandlerType
that creates client-sided screen handlers using the factory.T
- the screen handler typeid
- the registry IDfactory
- the client-sided screen handler factorypublic static <T extends net.minecraft.screen.ScreenHandler> net.minecraft.screen.ScreenHandlerType<T> registerExtended(net.minecraft.util.Identifier id, ScreenHandlerRegistry.ExtendedClientHandlerFactory<T> factory)
ScreenHandlerType
that creates client-sided screen handlers with additional
networked opening data.
These screen handlers must be opened with a ExtendedScreenHandlerFactory
.
T
- the screen handler typeid
- the registry IDfactory
- the client-sided screen handler factory