Protection API

Keep the slots your mod protects, such as favorites or locked slots, out of Sorted's sorts and transfers.

For a favorites or lock mod. Tell Sorted which of the player's slots your mod protects, and its sorts, Quick Stack, Quick Empty and the nearby transfers leave them alone. You answer per slot, not per item, so two stacks of one item can be treated differently. From Sorted 0.1.42.

Register #

Java
// Once, on the client. Your answer: "LOCKED", "TOP_UP" or null for a slot Sorted may use.
SortedProtection.register("mymod", slot -> Favorites.isMarked(slot) ? SortedProtection.LOCKED : null);

// The ender chest too, while it is open.
SortedProtection.registerEnderChest("mymod", slot -> Favorites.isMarkedInEnderChest(slot) ? SortedProtection.LOCKED : null);

Slots are Inventory indices: 0 to 8 the hotbar, 9 to 35 the main inventory, 36 to 39 armor, 40 the offhand. In the ender chest, 0 to 26. One answer per owner, your mod id: registering again replaces it, null removes it, and release takes both away.

The two levels #

LevelA sortQuick Stack, Quick Empty, Smart EmptyPull All, Quick Fill
LOCKEDLeaves it where it is.Never take from it.Pull All puts nothing in. Fill does not fetch for it.
TOP_UPLeaves it where it is.Never take from it.May add to it.

The nearby versions of Quick Stack, Quick Empty and Fill follow the same rules. When two mods answer for one slot, LOCKED wins.

Good to know #

  • Quick Fill moves items with the game's own shift-click, which tops up any matching stack. So a LOCKED stack can still grow when Fill fetches its item for another stack.
  • A stack the player Quick Stacks by hand, on the cursor, goes where they put it.
  • Your answer is called often: keep it to a lookup. In singleplayer, nearby Quick Stack and Fill call it from the game's built-in server thread, so read your data in a thread-safe way.
  • If your answer throws, Sorted logs it once and leaves your mod out until you register again.
  • The player sees which mods protect slots under Item blacklist in Sorted's settings, so a stack that never moves is not a mystery.

Without a compile dependency #

Java
static void protectWithSorted() {
    try {
        Class.forName("com.sorted.api.SortedProtection")
                .getMethod("register", String.class, IntFunction.class)
                .invoke(null, "mymod", (IntFunction<String>) slot -> Favorites.isMarked(slot) ? "LOCKED" : null);
    } catch (ReflectiveOperationException e) {
        // Sorted is not installed, or older than 0.1.42. Nothing to do.
    }
}

Reference #

SortedProtectionWhat it does
register(String owner, IntFunction<String> inventorySlot)Your answer for the player's inventory.
registerEnderChest(String owner, IntFunction<String> enderChestSlot)The same for the ender chest, while it is open.
release(String owner)Takes away both.
level(int inventorySlot) / enderChestLevel(int slot)What Sorted uses now, from every mod's answers. Null while Sorted is off on this server.
owners()The mods that registered.
isAvailable()Sorted is running, in a world, and not off on this server. Registering works either way.
LOCKED, TOP_UPThe two levels, as strings.

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