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.
| API | What it is for | Since |
|---|---|---|
| SortedStorage | Let Sorted treat your containers as storage: its buttons, sorting, Quick Stack and search. | 0.1.22 |
| SortedLookup | Ask 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"), or on NeoForgeModList.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 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.
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.gradleGradlerepositories {
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 #
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.