For mod developers

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

Sorted has two public APIs, both in the package com.sorted.api and both on the client. 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.0.1.13

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"), 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 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.
Client initializerJava
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 range of Minecraft versions, so use the version id of the file for yours. It is on the file's page on Modrinth.

build.gradleGradle
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 is a Fabric mod. It is client-side only, so call it from client code.

Questions #

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.