How to create a custom widget
Creating a Custom Widget
Example: Custom Widget
public class MyWidget extends DynamicValueWidget {
public static WidgetData<MyWidget> DATA = new WidgetData<>("MyWidget", "Custom widget", MyWidget::new);
public MyWidget(String modId, String registryID, String registryKey) {
super(DATA, modId, registryID, registryKey);
}
@Override
public void renderWidget(DrawContext context, int mouseX, int mouseY) {
String text = (String) getValue();
DrawHelper.drawText(context, text, x, y, 0xFFFFFF);
}
@Override
public Object getValue() {
return valueSupplier != null ? valueSupplier.get() : "";
}
public static class Builder extends DynamicValueWidgetBuilder<Builder, MyWidget> {
@Override
public MyWidget build() {
return new MyWidget(modID, registryID, registryKey)
.setPosition(x, y)
.setDisplay(display)
.setDraggable(isDraggable)
.setShouldScale(shouldScale);
}
}
}Saving and Loading
Last updated