Class GameRuleFactory

java.lang.Object
net.fabricmc.fabric.api.gamerule.v1.GameRuleFactory

public final class GameRuleFactory extends Object
A utility class containing factory methods to create game rule types. A game rule is a persisted, per server data value which may control gameplay aspects.

Some factory methods allow specification of a callback that is invoked when the value of a game rule has changed. Typically, the callback is used for game rules which may influence game logic, such as disabling raids.

To register a game rule, you can use GameRuleRegistry.register(String, GameRules.Category, GameRules.Type). For example, to register a game rule that is an integer where the acceptable values are between 0 and 10, one would use the following:

 public static final GameRules.Key<GameRules.IntRule> EXAMPLE_INT_RULE = GameRuleRegistry.register("exampleIntRule", GameRules.Category.UPDATES, GameRuleFactory.createIntRule(1, 10));
 

To register a game rule in a custom category, GameRuleRegistry.register(String, CustomGameRuleCategory, GameRules.Type) should be used.

See Also:
  • Method Details

    • createBooleanRule

      public static GameRules.Type<GameRules.BooleanRule> createBooleanRule(boolean defaultValue)
      Creates a boolean rule type.
      Parameters:
      defaultValue - the default value of the game rule
      Returns:
      a boolean rule type
    • createBooleanRule

      public static GameRules.Type<GameRules.BooleanRule> createBooleanRule(boolean defaultValue, BiConsumer<MinecraftServer,GameRules.BooleanRule> changedCallback)
      Creates a boolean rule type.
      Parameters:
      defaultValue - the default value of the game rule
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      a boolean rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      Returns:
      an integer rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue, int minimumValue)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      Returns:
      an integer rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue, int minimumValue, BiConsumer<MinecraftServer,GameRules.IntRule> changedCallback)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      an integer rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue, int minimumValue, int maximumValue)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      maximumValue - the maximum value the game rule may accept
      Returns:
      an integer rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue, BiConsumer<MinecraftServer,GameRules.IntRule> changedCallback)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      an integer rule type
    • createIntRule

      public static GameRules.Type<GameRules.IntRule> createIntRule(int defaultValue, int minimumValue, int maximumValue, @Nullable @Nullable BiConsumer<MinecraftServer,GameRules.IntRule> changedCallback)
      Creates an integer rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      maximumValue - the maximum value the game rule may accept
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      an integer rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      Returns:
      a double rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      Returns:
      a double rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue, BiConsumer<MinecraftServer,DoubleRule> changedCallback)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      a double rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue, double maximumValue)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      maximumValue - the maximum value the game rule may accept
      Returns:
      a double rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, BiConsumer<MinecraftServer,DoubleRule> changedCallback)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      a double rule type
    • createDoubleRule

      public static GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue, double maximumValue, BiConsumer<MinecraftServer,DoubleRule> changedCallback)
      Creates a double rule type.
      Parameters:
      defaultValue - the default value of the game rule
      minimumValue - the minimum value the game rule may accept
      maximumValue - the maximum value the game rule may accept
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      a double rule type
    • createEnumRule

      public static <E extends Enum<E>> GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue)
      Creates an enum rule type.

      All enum values are supported.

      Type Parameters:
      E - the type of enum this game rule stores
      Parameters:
      defaultValue - the default value of the game rule
      Returns:
      an enum rule type
    • createEnumRule

      public static <E extends Enum<E>> GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue, BiConsumer<MinecraftServer,EnumRule<E>> changedCallback)
      Creates an enum rule type.

      All enum values are supported.

      Type Parameters:
      E - the type of enum this game rule stores
      Parameters:
      defaultValue - the default value of the game rule
      changedCallback - a callback that is invoked when the value of a game rule has changed
      Returns:
      an enum rule type
    • createEnumRule

      public static <E extends Enum<E>> GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue, E[] supportedValues)
      Creates an enum rule type.
      Type Parameters:
      E - the type of enum this game rule stores
      Parameters:
      defaultValue - the default value of the game rule
      supportedValues - the values the game rule may support
      Returns:
      an enum rule type
    • createEnumRule

      public static <E extends Enum<E>> GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue, E[] supportedValues, BiConsumer<MinecraftServer,EnumRule<E>> changedCallback)
      Creates an enum rule type.
      Type Parameters:
      E - the type of enum this game rule stores
      Parameters:
      defaultValue - the default value of the game rule
      supportedValues - the values the game rule may support
      changedCallback - a callback that is invoked when the value of a game rule has changed.
      Returns:
      an enum rule type