Hooks

Hooks allow mods to inject their own code into some of Zeta’s functions.

Example

For example, Zeta provides a hook into the constructor of the LevelRenderer class. In order to hook into that constructor, you need to use the HookManager object in that class, called LevelRenderer.constructorHM. It has two methods that you can use, addPreHook and addPostHook. If you add a hook using addPreHook, your code will be executed just before the default behaviour in the constructor. If you instead use addPostHook, your code will be executed just after the object initialises. Here is an example of using this hook to change the background colour of the render engine.

LevelRenderer.constructorHM.addPostHook(args -> {

    LevelRenderer levelRenderer = args.getA1();
    Level level = args.getA2();

    levelRenderer.setGlClearColour(Color.MAGENTA);

    return null;
});

Add the above code to your mod’s init method to try it out. Note that the arguments to the function (including the ‘this’ pointer to the LevelRenderer) are encapsulated inside an args variable.