Class ScreenHandlerRegistry

java.lang.Object
net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry

public final class ScreenHandlerRegistry extends Object
An API for creating and registering screen handler types.

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.

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.

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.

Example

 
 // 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
 
 
See Also:
  • Method Details

    • registerSimple

      public static <T extends net.minecraft.screen.ScreenHandler> net.minecraft.screen.ScreenHandlerType<T> 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.
      Type Parameters:
      T - the screen handler type
      Parameters:
      id - the registry ID
      factory - the client-sided screen handler factory
      Returns:
      the created type object
    • registerExtended

      public static <T extends net.minecraft.screen.ScreenHandler> net.minecraft.screen.ScreenHandlerType<T> 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.

      These screen handlers must be opened with a ExtendedScreenHandlerFactory.

      Type Parameters:
      T - the screen handler type
      Parameters:
      id - the registry ID
      factory - the client-sided screen handler factory
      Returns:
      the created type object