How to create a custom widget
Here’s an example of how you might create your own widget and use the WidgetBuilder
to create a custom widget:
In this example, MyWidget
is a custom widget that displays some text. The Builder
nested class is used to construct instances of MyWidget
. The setText
method is used to set the text that the widget will display, and the build
method creates a new MyWidget
instance with the specified properties.
Saving and loading widget
Now we will save and load the fields of a widget.
To save override, the writeToTag()
method.
Do not remove the super call otherwise the basic properties of widgets won't be saved or loaded like its position, name, modID, etc.
To load fields, override the readFromTag()
method.
Last updated
Was this helpful?