Table of Contents

Adding a Gamerule

Registering a Gamerule

To create a gamerule, build and register it using the GameRuleBuilder of the Fabric API:

  1. // Create and register a boolean gamerule, enabled by default
  2. private static final Identifier GAMERULE_IDENTIFIER = Identifier.of("custom_mod_name","gamerule_name");
  3. public static final GameRule<Boolean> CUSTOM_BOOLEAN_GAMERULE = GameRuleBuilder
  4. .forBoolean(true) //default value declaration
  5. .category(GameRuleCategory.MISC)
  6. .buildAndRegister(GAMERULE_IDENTIFIER)
  7. ;

Using the gamerule

To get access to the value of a gamerule, use a server-world:

  1. serverWorld.getGameRules().getValue(CUSTOM_GAMERULE);

Translation

The registered gamerule shows up untranslated in the gamerule list, which can be opened in the world creation screen. To translate the name, add an entry in the lang-file (see lang for more info):

{
  "gamerule.custom_mod_name.gamerule_name": "Gamerule Name"
}