Skip to content

Getting Started

MoSadie edited this page Nov 19, 2024 · 5 revisions

Example Mod

I've written a quick example mod that shows the basics of how to use the mod. Check it out here! Or if you want a real-world use of the mod, check out Island Menu!

Adding to an existing mod

Step 0: Adding the Modrinth Maven Repository

If you haven't already, add the Modrinth Maven Repository following their instructions here

Then use this to add the dependency on ServerMainMenu-Lib:

dependencies {
    modApi "maven.modrinth:smm-lib:2.0.3"
}

Step 1: Creating a Theme

A theme is an instance of the MenuTheme interface, which has a few methods that need to be overridden:

  • getId() returns an unique (to your mod) identifier for your mod
  • getPanorama() returns an Identifier that points to the panorama pictures. (See the example mod for a good example)
  • getSplashText() returns the splash text
  • getJoinServerButtonText() returns a Text object that is shown on the button, I recommend using Text.translatable or Text.literal
  • getServerInfo() returns a ServerInfo object that determines the server connected to when the button is clicked
  • rollOdds() returns true if the theme should be selected, false otherwise. It is up to your code to determine if the theme wants to be selected.
  • getPriority() indicates the priority of the theme, larger number = higher priority. The highest priority theme that returns true for rollOdds will be the final selected theme.

RollOdds Utilities

To give some turn-key utilities, there are some pre-programmed methods available in the Util class, they are:

  • rollOddsFlipCoin which randomly returns true about half the time
  • rollOddsMonthDay which returns true more often when close to a date, and false when far away.

Of course you are free to put whatever logic you want in the rollOdds method, these are just some easy tools that return values can be used directly. (ex you can just do return rollOddsFlipCoin(); if you want)

Step 2: Registering the Theme(s)

In your main client class, you'll need to register the themes with the custom theme registry. Say you have an instance of your theme saved as the variable themeObj, you can register it in the onInitializeClient() method like this:

Registry.register(ServerMainMenuLibClient.registry, new Identifier("your-mod-id", "theme-id"), themeObj);

Step 3: Adding Panorama Pictures

In your mod's asset folder, you'll need to add 6 png pictures, one for each direction of the panorama!

(WIP: Will add a guide for taking ReplayMod screenshots and converting theme here soon)

Make sure that the identifier you use for the getPanorama() method is the name of the files minus the number at the end of the filename!

And that's it! Your theme is all configured! If you need to force a theme for testing you can use the configuration options in Mod Menu to override the theme selector using the namespace and theme id from your registration.