For mod developers

What other mods can do with Sorted, and how to call it without making it a requirement.

Sorted's public API is the package com.sorted.api, on the client. Everything else in Sorted can change in any release. The examples use the Mojang names of Minecraft 26.x.

APIWhat it is forSince
SortedStorageLet Sorted treat your containers as storage: its buttons, sorting, Quick Stack and search.0.1.22
SortedLookupAsk what Sorted has seen in the player's containers: counts, positions, highlights, and where the storage is for a map.0.1.13
SortedActionsRun Sorted's actions by id, for a shortcut wheel or a menu of your own.0.1.31
SortedProtectionKeep the slots your mod protects, such as favorites or locked slots, out of Sorted's sorts and transfers, and ask which slots Sorted keeps.0.1.42
SortedInputAsk Sorted to leave Alt on items to your mod.0.1.42
SortedRequestsHave Sorted take exact amounts from the containers around the player, or put them away, such as a build's materials.0.1.46

Keep Sorted optional #

Sorted is client-side, and most players of your mod will not have it. Two ways to call it without making it a requirement:

  • Check FabricLoader.getInstance().isModLoaded("sorted"), or on NeoForge ModList.get().isLoaded("sorted"), and keep the calls in a class of their own, so Sorted's classes only load when it is there.
  • Or call it by reflection. The storage, actions, protection, input and requests calls and the plain-typed lookup calls take only Java types (String, long, java.util.function), so there is nothing to compile against. See the example. A missing class or method means an older Sorted: skip it.
Client initializer Java
public final class MyModClient implements ClientModInitializer {
    @Override
    public void onInitializeClient() {
        if (FabricLoader.getInstance().isModLoaded("sorted")) {
            SortedCompat.init();
        }
    }
}

// A class of its own: Sorted's classes only load when Sorted is there.
final class SortedCompat {
    static void init() {
        SortedStorage.register("mymod:iron_chest");
    }
}

Compiling against it #

Sorted is on Modrinth, so the Modrinth Maven works. Several files share a version number, one per Minecraft version and loader. Use the version id of the file for yours. It is on the file's page on Modrinth.

build.gradle Gradle
repositories {
    maven { url = "https://api.modrinth.com/maven" }
}

dependencies {
    // The version id of the Sorted file for your Minecraft version, from its Modrinth page.
    // 26.x: compileOnly. 1.21.x: modCompileOnly.
    modCompileOnly "maven.modrinth:sorted:<version id>"
}

Sorted runs on Fabric on 1.21.1 to 26.3, and on NeoForge on 1.21.1, 1.21.3, 1.21.4, 1.21.5, 1.21.8, 1.21.10 and 1.21.11 and 26.1.2 to 26.3, with the same API everywhere. It is client-side only, so call it from client code.

Questions #

Every class has isAvailable(). While it is false (Sorted is off on this server, or no world is loaded) calls do nothing and return empty, false or null. None of them throws.

Something the API should do, or something that does not work: ask on Discord.

Something missing or wrong on this page? Say so on Discord.