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:08] – change game rule name and add translation section 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"]>
 // Create and register a boolean game rule with the name "shouldPigsFly" which is true by default. // 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 = public static final GameRules.Key<GameRules.BooleanRule> SHOULD_PIGS_FLY =
-GameRuleRegistry.register("shouldPigsFly", Category.PLAYER, GameRuleFactory.createBooleanRule(true));+GameRuleRegistry.register("shouldPigsFly", Category.MOBS, GameRuleFactory.createBooleanRule(true));
 </code> </code>
  
Line 16: Line 16:
  
 <code java [enable_line_numbers="true"]> <code java [enable_line_numbers="true"]>
-world.getGameRules().getBoolean(KeepTheRain.SHOULD_PIGS_FLY)+world.getGameRules().getBoolean(SHOULD_PIGS_FLY)
 </code> </code>
  
tutorial/gamerule.1632413326.txt.gz · Last modified: 2021/09/23 16:08 by jummit