User Tools

Site Tools


tutorial:gamerule

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:gamerule [2021/09/23 16:01] – initial work on gamerule tutorial jummittutorial:gamerule [2021/12/24 22:00] (current) – external edit 127.0.0.1
Line 3: Line 3:
 ==== Registering a Gamerule ==== ==== Registering a Gamerule ====
  
-To create a gamerule you have to register it using the ''GameRuleRegistry'' of the Fabric API:+To create a gameruleregister it using the ''GameRuleRegistry'' of the Fabric API:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-public static final GameRules.Key<GameRules.BooleanRule> DO_SLEEP_CLEAR_WEATHER +// Create and register a boolean game rule with the name "shouldPigsFly" which is true by default. 
-GameRuleRegistry.register("clearWeatherAfterSleep", Category.PLAYER, GameRuleFactory.createBooleanRule(false));+public static final GameRules.Key<GameRules.BooleanRule> SHOULD_PIGS_FLY 
 +GameRuleRegistry.register("shouldPigsFly", Category.MOBS, GameRuleFactory.createBooleanRule(true));
 </code> </code>
  
Line 15: Line 16:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-world.getGameRules().getBoolean(KeepTheRain.DO_SLEEP_CLEAR_WEATHER)+world.getGameRules().getBoolean(SHOULD_PIGS_FLY)
 </code> </code>
  
 +==== 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 [[tutorial:lang|lang]] for more info):
 +
 +<code json>
 +{
 +  "gamerule.shouldPigsFly": "Pigs should fly"
 +}
 +</code>
tutorial/gamerule.1632412868.txt.gz · Last modified: 2021/09/23 16:01 by jummit