Language

Unruled API

Unruled API

Modrinth

Expands on the vanilla gamerules, adding new gamerules types for other mods to use and enabling players to set per-dimension overrides for gamerules

34.9k downloads 21 followers updated 1h ago
latest v2.3.3+26.2 Modrinth
Fabric Forge Neoforge Quilt 1.18 – 26.2 Game-mechanicsLibraryUtility

Unruled API

mod icon

Allows to create new form of gamerules, beyond the restrictive vanilla integers and booleans.

This mod enables developers to easily create new floating, long, double, string, text, enum-driven,
entity selector and even registry-entry gamerules, using their respective builders,
all available from the com.nerjal.unruled_api.UnruledApi class's static methods.

It also provides means to add value validators alongside registering new gamerules, which in turn
allows to restrict the range of valid values for gamerules. For instance, it can be used to only allow
odd values in an integer gamerule.

Additionally, this mod also adds per-dimension gamerule overrides! These are applied in their
strict dimension (provided they are queried correctly).
See gamerules overrides for more details about it.

Gamerules registration

Example:

import com.nerjal.unruled_api.UnruledApi;

public class MyClass {
    private static final int STRING_RULE_MAX_LENGTH = 24;

    public void gamerulesRegistration() {
        var myFloatingRule = UnruledApi.floatRuleBuilder(category, 1.5) // takes the category and the initial value as arguments
                // the category determines where in the world creation screen will it be placed
                .register("mymod:my_gamerule"); // gamerule registration always takes the gamerule's ID
                // the ID also determines the translated name of the gamerule
        var myStringRule = new StringRule.Builder(category, "initial value", STRING_RULE_MAX_LENGTH)
                // using the UnruledApi methods or directly creating the builder has the same result, and arguments are the same.
                // however, mind that in some cases, it is strongly recommended to use the specified builders such as for string
                // rules, enum, and dynamic registry entry rules, as they have a more specific processing of their values and
                // command handling.
                .register("mymod:my_other_gamerule");
    }

}

Additionally, quick creation and registration methods have been added for your convenience

import com.nerjal.unruled_api.UnruledApi;

    public static void quickGamerulesRegistration() {
        var myLongRule = UnruledApi.registerLong(Identifier.of("mymod:my_long_rule"), category, 25L);
        // Quick registration methods always follow the same parameter order: name, category, initial value, gamerule-type specific arguments
        // Except for enum rules, for which the enum class goes before the initial value
        var myEnumRule = UnruledApi.registerEnumRule(Identifier.of("mymod:my_enum_rule"), category, MyEnum.FIRST, MyEnum.class);
    }
    
    enum MyEnum {
        FIRST,
        SECOND,
        THIRD
    }

For consistency, methods have also been created to allow quickly register vanilla-type gamerules.

import com.nerjal.unruled_api.UnruledApi;

    public static void registerBasicRules() {
        UnruledApi.registerInteger("my_int_rule", category, 5);
        UnruledApi.registerBoolean("my_bool_rule", category, false);
    }

You can also retrieve their values using the same class's methods

This has become outdated since release 2.0 (for Minecraft 1.21.11 and later).
Please use the gamerule methods directly as now meant by the game code.

    public long getMyLongGamerules(ServerWorld dimension) { // ServerWorld is a Yarn mapping class. Might be Level or ServerLevel with Mojmap
        return UnruledApi.getLong(dimension.getGameRules(), myLongGamerule);
    }
    
    public Block getMyBlockRule(ServerWorld dimension) {
        // querying a registry entry rule returns the registry entry's very value, as it can only be set if it exists in the registry
        return UnruledApi.getRegistryEntry(dimension.getGameRules(), myBlockRegistryEntryRule);
    }

Command Tweaks

The average experience of using gamerules in vanilla minecraft is pretty poor.
Navigating a long list of names, trying to remember the one of the rule you need,
or even worse, searching for a hypothetic one, can be pretty annoying.

Thus, Unruled API aims to alleviate that burden ever so slightly, by allowing you
to navigate the same list by category!

Hence, you can now add the category name or full ID (both in full caps) in the command and the following
list will only contain rules in the appropriate category.

E.g. /gamerule CHAT will then have your game suggest you only the rules inside the
chat category, according to the world creation menu listing.

This also applies to all modded gamerules and categories, as well as modded gamerule types
from any and all mod.

/gamerule [<category NAME or FULL ID>] <gamerule name or ID> [<value>]

Gamerules Overrides

Gamerules overrides are set per dimension. They allow players to set specific rules to specific values
in the wanted dimension, all via the gamerule-override command.

This command has many uses:

  • gamerule-override alone and with no arguments allows you to get a list of existing overrides in the current dimension.
  • gamerule-override <dimension id> allows you to get a list of existing overrides in the specified dimension.
  • gamerule-override get <gamerule id> allows you to query a potential override for the specified gamerule in the current dimension.
  • gamerule-override set <gamerule id> <value> allows you to set an override for the specified gamerule to the given value in the current dimension.
  • gamerule-override unset <gamerule id> allows you to remove a set override for the specified gamerule in the current dimension.
  • gamerule-override in <dimension id> get <gamerule id> allows you to query a potential override for the specific gamerule in the given dimension.
  • gamerule-override in <dimension id> set <gamerule id> <value> allows you to set an override for the specified gamerule to the given value in the provided dimension.
  • gamerule-override in <dimension id> unset <gamerule id> allows you to remove a set override for the specified gamerule in the provided dimension.

Gamerule overrides are stored in the dimension's data folder, as the gamerules.dat file.
Removing it while the server is offline/world is not being played will simply remove all overrides for the dimension.

Additionally, for your convenience, the get, set and unset in all cases also
support the per-category filtering, for easier usage.
You can thus use the command as follows:

/gamerule-override in <dimension id> set [<category NAME or FULL ID>] <gamerule name or id> <value>

Configurable Default Values

Especially relevant for modpack creators, this feature allows to set custom values to be used as default gamerule
values upon world creation.

In order to set them, you only need to create a config/default_gamerules.json file, and for each gamerule you want
to add a default value for, set a key-value pair with the wanted new value, set as a string. (due to limitations in
the mojang code for easy JSON-parsing, only string values are accepted, anything else will simply be ignored)

Example:

{
  "doDaylightCycle": "false",
  "mobGriefing": "false"
}

Obviously, this works just as well with modded gamerules and gamerule types!

Custom Gamerule Categories

As of 1.21.11, gamerule categories are now a registry. The following is only relevant to game versions prior to this

Developers can easily register new custom gamerule categories, that will be added straight to the category enum!
However, you do need it to be done early in the game load process, i.e. before the gamerules class gets loaded.

This can be done on Fabric with a preLaunch entrypoint, on (Neo)Forge upon initializing your @Mod class,
or on any launcher from your mixin config plugin.

You only need to add a CategoryProvider implementation to the UnruledEarlyUtils.CATEGORY_PROVIDERS set.

The CategoryProvider interface is a String supplier-like class, that allows for an optional implementation of a
category consumer upon creation of the matching category. The provided String will be set as the category name, but
will not allow for duplicate entries (i.e. if two mods want to add a same category, only one will be created, but both
providers will receive it as well)

How to use in your project

You can implement this mod in your project using the Modrinth maven. Don't hesitate to read the official documentation.

Add the Modrinth maven repository

repositories {
    maven {
            name = "Modrinth"
            url = "https://api.modrinth.com/maven"
    }
}

Import the mod

loom example:

dependencies {
    // using modApi allows your project's dependents to also import dependencies by default
    modApi "maven.modrinth:unruled-api:${project.unruled_version}"
}

(neo)forgeGradle example:

dependencies {
    implementation "maven.modrinth:unruled-api:${project.unruled_version}"
}

For copyright reasons, we require you to not include (JiJ, jar-in-a-jar, shadow, etc) this mod inside of your own. Thank you for your comprehension.

Versions

Release
2.3.3+26.2
fabric, neoforge · 26.2 · 1h ago
Minecraft 26.2 patch
2
Release
2.3.3+26.1
fabric, neoforge · 26.1, 26.1.1, 26.1.2 · 1mo ago
Fix mixin config plugin breaking on non-fabric loaders
704
Release
2.3.2+26.1
fabric · 26.1, 26.1.1, 26.1.2 · 1mo ago
Removed a broken old and now useless injection
348
Release
2.3.1+26.1
fabric · 26.1, 26.1.1, 26.1.2 · 2mo ago
Fix a null-case breaking data reloads
44
Release
2.3+26.1
fabric · 26.1, 26.1.1, 26.1.2 · 2mo ago
Fix debug injections being applied outside of dev environment
36
Release
2.2+26.1
fabric · 26.1, 26.1.1, 26.1.2 · 2mo ago
Updated to 26.x
51
Release
2.1-1.21.11+neoforge
neoforge · 1.21.11 · 5mo ago
## Release 2.1 Makes the vanilla keep_inventory use potential overrides from the death world rather than respawn
123
Release
2.1-fabric+1.21.11
fabric · 1.21.11 · 5mo ago
## Release 2.1 Makes the vanilla keep_inventory use potential overrides from the death world rather than respawn
5.7k
Release
2.0.3-1.21.11+neoforge
neoforge · 1.21.11 · 5mo ago
### 2.0.3 hotfix for NeoForge 1.21.11+ * Fixes enum rules making the mod not work only server-side * Fixes static registry rules breaking command tree…
25
Release
2.0.3-1.21.11+fabric
fabric · 1.21.11 · 5mo ago
### 2.0.3 hotfix for Fabric 1.21.11+ * Fixes enum rules making the mod not work only server-side * Fixes static registry rules breaking command tree sending *…
80
Release
2.0.2-1.21.11+neoforge
neoforge · 1.21.11 · 5mo ago
Fixes an issue with MixinExtras local name resolution due to refmap getting lost in the archloom build process
33
Release
2.0.2-1.21.11+fabric
fabric · 1.21.11 · 5mo ago
Fixes an issue with MixinExtras local name resolution due to refmap getting lost in the archloom build process
105

Comments 0

No comments yet. Be the first to share your thoughts.

Download Unruled API

R 2.3.3+26.2 26.2 fabric, neoforge 270 KB R 2.3.3+26.1 26.1, 26.1.1, 26.1.2 fabric, neoforge 269 KB R 2.3.2+26.1 26.1, 26.1.1, 26.1.2 fabric 270 KB R 2.3.1+26.1 26.1, 26.1.1, 26.1.2 fabric 271 KB R 2.3+26.1 26.1, 26.1.1, 26.1.2 fabric 271 KB R 2.2+26.1 26.1, 26.1.1, 26.1.2 fabric 271 KB R 2.1-1.21.11+neoforge 1.21.11 neoforge 248 KB R 2.1-fabric+1.21.11 1.21.11 fabric 245 KB R 2.0.3-1.21.11+neoforge 1.21.11 neoforge 247 KB R 2.0.3-1.21.11+fabric 1.21.11 fabric 244 KB R 2.0.2-1.21.11+neoforge 1.21.11 neoforge 248 KB R 2.0.2-1.21.11+fabric 1.21.11 fabric 245 KB R 2.0.1-1.21.11+neoforge 1.21.11 neoforge 248 KB R 2.0.1-1.21.11+fabric 1.21.11 fabric 245 KB R 2.0-1.21.11+neoforge 1.21.11 neoforge 247 KB R 2.0-1.21.11+fabric 1.21.11 fabric 245 KB R 1.4.1-1.21.9+neoforge 1.21.9, 1.21.10 neoforge 232 KB R 1.4.1-1.21.9+fabric 1.21.9, 1.21.10 fabric 230 KB R 1.4.1-1.21.5+neoforge 1.21.5, 1.21.6, 1.21.7 neoforge 234 KB R 1.4.1-fabric+1.21.5 1.21.5, 1.21.6, 1.21.7 fabric 232 KB R 1.4.1-1.21.3+neoforge 1.21.3, 1.21.4 neoforge 234 KB R 1.4.1-1.21.3+fabric 1.21.3, 1.21.4 fabric 232 KB R 1.4-1.21.9+neoforge 1.21.9, 1.21.10 neoforge 231 KB R 1.4-1.21.9+fabric 1.21.9, 1.21.10 fabric 229 KB R 1.4-1.21.5+neoforge 1.21.5, 1.21.6, 1.21.7 neoforge 233 KB R 1.4-1.21.5+fabric 1.21.5, 1.21.6, 1.21.7 fabric 231 KB R 1.4-1.21.3+neoforge 1.21.3, 1.21.4 neoforge 233 KB R 1.4-1.21.3+fabric 1.21.3, 1.21.4 fabric 231 KB R 1.4-1.21+neoforge 1.21, 1.21.1, 1.21.2 neoforge 233 KB R 1.4-1.21+fabric 1.21, 1.21.1, 1.21.2 fabric 231 KB R 1.3-1.21.5 1.21.5, 1.21.6, 1.21.7 fabric, neoforge, quilt 243 KB R 1.3-1.21.3 1.21.3, 1.21.4 fabric, neoforge, quilt 243 KB R 1.3-1.21 1.21, 1.21.1, 1.21.2 fabric, neoforge, quilt 242 KB R 1.3-1.20.2 1.20.2, 1.20.3, 1.20.4 fabric, neoforge, quilt 240 KB R 1.3-1.20 1.20, 1.20.1 fabric, forge, neoforge 419 KB R 1.2.1-1.21.5 1.21.5 fabric, neoforge, quilt 235 KB R 1.2.1-1.21.3 1.21.3, 1.21.4 fabric, neoforge, quilt 235 KB R 1.2.1-1.21 1.21, 1.21.1, 1.21.2 fabric, neoforge, quilt 234 KB R 1.2-1.21.5 1.21.5 fabric, neoforge, quilt 235 KB R 1.2-1.21.3 1.21.3, 1.21.4 fabric, neoforge, quilt 234 KB R 1.2-1.21 1.21, 1.21.1, 1.21.2 fabric, neoforge, quilt 234 KB R 1.2-1.20.2 1.20.2, 1.20.3, 1.20.4 fabric, neoforge, quilt 231 KB R 1.2-1.20 1.20, 1.20.1 fabric, forge, neoforge 411 KB R 1.1.3-1.21.5 1.21.5 fabric, neoforge, quilt 229 KB R 1.1.3-1.21.3 1.21.3, 1.21.4 fabric, neoforge, quilt 229 KB R 1.1.3-1.21 1.21, 1.21.1, 1.21.2 fabric, neoforge, quilt 228 KB R 1.1.3-1.20.2 1.20.2, 1.20.3, 1.20.4 fabric, neoforge, quilt 226 KB R 1.1.3-1.20 1.20, 1.20.1 fabric, forge, neoforge 405 KB R 1.1.2-1.21.5 1.21.5 fabric, neoforge, quilt 228 KB R 1.1.2-1.21.3 1.21.3, 1.21.4 fabric, neoforge, quilt 228 KB

Files are served directly from the original source. Modgrid does not host or modify them.