Class GameRuleRegistry

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

public final class GameRuleRegistry extends Object
A utility class which allows for registration of game rules. Note game rules with duplicate keys are not allowed. Checking if a game rule key is already taken can be done using hasRegistration(String).

Creation of rule types is done using GameRuleFactory.

See Also:
  • Method Details

    • register

      public static <T extends GameRules.Rule<T>> GameRules.Key<T> register(String name, GameRules.Category category, GameRules.Type<T> type)
      Registers a GameRules.Rule.
      Type Parameters:
      T - the type of rule
      Parameters:
      name - the name of the rule
      category - the category of this rule
      type - the rule type
      Returns:
      a rule key which can be used to query the value of the rule
      Throws:
      IllegalStateException - if a rule of the same name already exists
    • register

      public static <T extends GameRules.Rule<T>> GameRules.Key<T> register(String name, CustomGameRuleCategory category, GameRules.Type<T> type)
      Registers a GameRules.Rule with a custom category.
      Type Parameters:
      T - the type of rule
      Parameters:
      name - the name of the rule
      category - the category of this rule
      type - the rule type
      Returns:
      a rule key which can be used to query the value of the rule
      Throws:
      IllegalStateException - if a rule of the same name already exists
    • hasRegistration

      public static boolean hasRegistration(String ruleName)
      Checks if a name for a game rule is already registered.
      Parameters:
      ruleName - the rule name to test
      Returns:
      true if the name is taken.