Skip to content

Display Feature

Bogdan T edited this page Jan 29, 2024 · 12 revisions

Basics

Here you will learn how the display feature is organized

Structure

The DisplayRenderer is on the top of the draw hirarchy. It manages the rendering of a DisplayCanvas attached to the renderer.

Besides that, it contains the DisplayData used in canvas and the DisplayTrigger list.

and finally, it implements the InjectablePlaceholderList, so, you can inject placeholders to be used in canvas.

The renderer can be drawn in BaseScreen, in HUD or manually, we will dig into that further

DisplayCanvas is the class that is also a DisplayElement and contains the list of DisplayElements. It controls how the elements are displayed.

All the display element templates, trigger templates and actions(info about actions further) are registered in DisplayManager. This class also holds the link to the HUD canvas and all active canvases(attached to renderer). P.s. I think it will be changed from active canvases to renderers in future updates.

Templates for elements and triggers are just the created implementations with no data or default data. To actually give it some data, you have to get the clone of a template from DisplayManager and then use updateVariables(Config conf) method to apply data from config. After that an element can be used.

First test

Now, after understanding the structure, you can practice a little bit and make the simpliest gui screen.

  • First, create the test.json in your resources(on the top, so, not in assets or any other folder):

    {
      "type": "canvas",
      "config_version": 1,
      "layer": "MIDDLE",
      "elements": {
        "image_main": {
          "settings": {
            "image": "atumodcore:textures/test.png",
            "color": "#aaaaaa"
          },
          "type": "image",
          "layer": "BACKGROUND",
          "posX": 0,
          "posY": 0,
          "width": 1920,
          "height": 1080
        },
        "text_test": {
          "settings": {
            "fontSize": 100,
            "text": "&bHELLO WORLD!",
            "font": "minecraft.otf"
          },
          "type": "text",
          "layer": "MIDDLE",
          "posX": 500,
          "posY": 350,
          "width": 194,
          "height": 52
        }
      },
      "width": 1920,
      "height": 1080
    }

Then, in your main class create the config object attached to the created file. If you dont know how, read the WIKI section about configs.

Once you’ve got a config object, you can compile and register canvas template:

//It basically clones and updates variables of the template elements that are specified in config
//This object can be used as a template with a default data.
DisplayElement element = getDisplayManager().getElementRegistry().compileCanvasTemplate(id,config); // for an id u can use test, or whatever you like
//Register to later access the template
getDisplayManager().getElementRegistry().registerTemplate(id, element);

Nice! Last step left. You need to draw it somewhere. The most simple way is to draw it on GuiScreen.

Lets override the MainMenu screen of the Minecraft:

@SubscribeEvent
public void onGuiOpen(GuiOpenEvent event){
    if(event.getGui() instanceof GuiMainMenu){
        event.setGui(
                new BaseScreen(this,
                        getDisplayManager().getElementRegistry().getDrawableCanvas("yourCanvasId") //returns the cloned canvas template, ready to use
                );
        );
    }
}

Don’t forget to register the class where u put it in Forge EVENT_BUS:

MinecraftForge.EVENT_BUS.register(this)

Its ready to be tested! You should see the cute cat and text in main menu

Now, I highly suggest you to play around the settings.

Tip: Once you made changes to config you can press Shift+S to reload the currently active DisplayRenderer.

If it doesnt work, change the debug state of the AtumMod to true

Clone this wiki locally