User Tools

Site Tools


tutorial:gamerule

This is an old revision of the document!


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 now shows up untranslated in the game rule list, which can be opened in the world creation screen. To translate the name, add a gamerule.gameruleName entry (see lang for more info):

{
  "gamerule.shouldPigsFly": "Pigs should fly"
}
tutorial/gamerule.1765306757.txt.gz · Last modified: 2025/12/09 18:59 by solacekairos