Creating a Gamemode - Entropy159/Entropy-Arena GitHub Wiki

To create a gamemode, you need to first create a new class that extends ArenaGamemode or one of it's subclasses.

In the API package there's a gamemode subfolder with lots of classes; most of them are subclasses of ArenaGamemode. It's recommended to choose one of these, but if for some reason none of them do what you need, you can instantiate ArenaGamemode directly.

The minimum gamemode class simply has a constructor with no arguments that calls the super constructor. The super constructor takes two arguments: a resource location representing the ID for the gamemode (this should be unique), and the English name used in datagen for translation.

A minimal setup should look similar to this:

public class FreeForAll extends FFAGamemode {
    public FreeForAll() {
        super(EntropyArena.id("free_for_all"), "Free for All");
    }
}

Once your gamemode class exists, you can then register it. You can either do this directly in your mod's constructor, or create a class like ArenaGamemodes to register them, then call the registry method in your mod's constructor.

There is one important thing to keep in mind when creating a gamemode: the gamemode class itself is a packet. The ArenaGamemode class has sendToAll() and sendToPlayer(ServerPlayer player) utility functions. If your gamemode has any data that should be sent to the clientside copy, then make sure to override encodeData() and decodeData() while calling the super functions. Because of the way ByteBuf works, you need to make sure to read and write things in the same order.

One other important function is generateLang(). This is called during data generation, and can be used to create language translations per-gamemode. Any language keys that are specifically for the gamemode should be created here.

From here, you can look at ArenaGamemode itself and it's subclasses to find out what all you can do with the gamemodes. Check out the default ones here for some examples.