ContextMenuScreenFactory
The ContextMenuScreenFactory
interface defines a factory for creating screens to render context menus, allowing custom or skin-specific screens (e.g., MinecraftSkin, ModernSkin
).
Key Methods
create(ContextMenu<?>, ContextMenuProperties): Returns a
Screen
for the given menu and properties.
Usage
Implement for custom screens or use DefaultContextMenuScreenFactory
for standard behavior. Pass to ContextMenu
constructor.
The context menu contains a constructor which takes ContextMenuScreenFactory as the parameter to generate the theme's screen. Default provided is `DefaultContextMenuScreenFactor`
public ContextMenu(int x, int y, T properties) {
this(x, y, properties, new DefaultContextMenuScreenFactory());
}
public ContextMenu(int x, int y, T properties, ContextMenuScreenFactory screenFactory) {
this(x, y, properties, screenFactory, null);
}
// Internally used constructor.
public ContextMenu(int x, int y, @NotNull T properties, ContextMenuScreenFactory screenFactory, @Nullable ContextMenu<?> parentMenu) {
Objects.requireNonNull(screenFactory, "ContextMenuScreenFactory cannot be null!");
Objects.requireNonNull(properties, "ContextMenu Properties cannot be null!");
this.x = x;
this.y = y + properties.getHeightOffset();
this.properties = properties;
this.screenFactory = screenFactory;
this.darkerBackgroundColor = properties.getBackgroundColor().darker().darker().darker().darker().darker().darker();
this.parentMenu = parentMenu;
this.properties.getSkin().setContextMenu(this);
Screen dummy = screenFactory.create(this, properties);
System.registerInstance(new ContextMenuScreenRegistry(dummy.getClass()), DynamicHUD.MOD_ID);
}
Last updated
Was this helpful?