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 Summary

    Modifier and Type
    Method
    Description
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.BooleanRule>
    createBooleanRule(boolean defaultValue)
    Creates a boolean rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.BooleanRule>
    createBooleanRule(boolean defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.GameRules.BooleanRule> changedCallback)
    Creates a boolean rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue)
    Creates a double rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue, double minimumValue)
    Creates a double rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue, double minimumValue, double maximumValue)
    Creates a double rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue, double minimumValue, double maximumValue, BiConsumer<net.minecraft.server.MinecraftServer,DoubleRule> changedCallback)
    Creates a double rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue, double minimumValue, BiConsumer<net.minecraft.server.MinecraftServer,DoubleRule> changedCallback)
    Creates a double rule type.
    static net.minecraft.world.GameRules.Type<DoubleRule>
    createDoubleRule(double defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,DoubleRule> changedCallback)
    Creates a double rule type.
    static <E extends Enum<E>>
    net.minecraft.world.GameRules.Type<EnumRule<E>>
    createEnumRule(E defaultValue)
    Creates an enum rule type.
    static <E extends Enum<E>>
    net.minecraft.world.GameRules.Type<EnumRule<E>>
    createEnumRule(E defaultValue, E[] supportedValues)
    Creates an enum rule type.
    static <E extends Enum<E>>
    net.minecraft.world.GameRules.Type<EnumRule<E>>
    createEnumRule(E defaultValue, E[] supportedValues, BiConsumer<net.minecraft.server.MinecraftServer,EnumRule<E>> changedCallback)
    Creates an enum rule type.
    static <E extends Enum<E>>
    net.minecraft.world.GameRules.Type<EnumRule<E>>
    createEnumRule(E defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,EnumRule<E>> changedCallback)
    Creates an enum rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue)
    Creates an integer rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue, int minimumValue)
    Creates an integer rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue, int minimumValue, int maximumValue)
    Creates an integer rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue, int minimumValue, int maximumValue, @Nullable BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.GameRules.IntRule> changedCallback)
    Creates an integer rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue, int minimumValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.GameRules.IntRule> changedCallback)
    Creates an integer rule type.
    static net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule>
    createIntRule(int defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.GameRules.IntRule> changedCallback)
    Creates an integer rule type.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createBooleanRule

      public static net.minecraft.world.GameRules.Type<net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.BooleanRule> createBooleanRule(boolean defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule> createIntRule(int defaultValue, int minimumValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule> createIntRule(int defaultValue, BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.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 net.minecraft.world.GameRules.Type<net.minecraft.world.GameRules.IntRule> createIntRule(int defaultValue, int minimumValue, int maximumValue, @Nullable @Nullable BiConsumer<net.minecraft.server.MinecraftServer,net.minecraft.world.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 net.minecraft.world.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 net.minecraft.world.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 net.minecraft.world.GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue, BiConsumer<net.minecraft.server.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 net.minecraft.world.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 net.minecraft.world.GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, BiConsumer<net.minecraft.server.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 net.minecraft.world.GameRules.Type<DoubleRule> createDoubleRule(double defaultValue, double minimumValue, double maximumValue, BiConsumer<net.minecraft.server.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>> net.minecraft.world.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>> net.minecraft.world.GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue, BiConsumer<net.minecraft.server.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>> net.minecraft.world.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>> net.minecraft.world.GameRules.Type<EnumRule<E>> createEnumRule(E defaultValue, E[] supportedValues, BiConsumer<net.minecraft.server.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