tutorial:gamerule
This is an old revision of the document!
Table of Contents
Adding a Gamerule
Registering a Gamerule
To create a gamerule, build and register it using the GameRuleBuilder of the Fabric API:
// Create and register a boolean gamerule, enabled by default private static final Identifier GAMERULE_IDENTIFIER = Identifier.of("custom_mod_name","gamerule_name"); public static final GameRule<Boolean> CUSTOM_BOOLEAN_GAMERULE = GameRuleBuilder .forBoolean(true) //default value declaration .category(GameRuleCategory.MISC) .buildAndRegister(GAMERULE_IDENTIFIER) ;
Using the gamerule
To get access to the value of a gamerule, use a server-world:
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