tutorial:gamerule
This is an old revision of the document!
Table of Contents
Adding a Gamerule
Registering a Gamerule
To create a gamerule you have to register it using the GameRuleRegistry
of the Fabric API:
// Create and register a boolean game rule with the name "shouldPigsFly" which is true by default. public static final GameRules.Key<GameRules.BooleanRule> SHOULD_PIGS_FLY = GameRuleRegistry.register("shouldPigsFly", Category.MOBS, GameRuleFactory.createBooleanRule(true));
Using the gamerule
To get access to the value of a game rule you need to get the server world:
world.getGameRules().getBoolean(SHOULD_PIGS_FLY)
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.1632413362.txt.gz · Last modified: 2021/09/23 16:09 by jummit