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 Summary

    Modifier and Type
    Method
    Description
    static boolean
    Checks if a name for a game rule is already registered.
    static <T extends net.minecraft.world.GameRules.Rule<T>>
    net.minecraft.world.GameRules.Key<T>
    register(String name, CustomGameRuleCategory category, net.minecraft.world.GameRules.Type<T> type)
    Registers a GameRules.Rule with a custom category.
    static <T extends net.minecraft.world.GameRules.Rule<T>>
    net.minecraft.world.GameRules.Key<T>
    register(String name, net.minecraft.world.GameRules.Category category, net.minecraft.world.GameRules.Type<T> type)
    Registers a GameRules.Rule.

    Methods inherited from class java.lang.Object

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

    • register

      public static <T extends net.minecraft.world.GameRules.Rule<T>> net.minecraft.world.GameRules.Key<T> register(String name, net.minecraft.world.GameRules.Category category, net.minecraft.world.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 net.minecraft.world.GameRules.Rule<T>> net.minecraft.world.GameRules.Key<T> register(String name, CustomGameRuleCategory category, net.minecraft.world.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.