--- title: "Protection API - Sorted wiki" description: "Keep the slots your mod protects, such as favorites or locked slots, out of Sorted's sorts and transfers." url: https://voxelsprout.com/sorted/wiki/protection-api --- [Sorted](https://voxelsprout.com/sorted) [Wiki](https://voxelsprout.com/sorted/wiki)Protection API # 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 | Level | A sort | Quick Stack, Quick Empty, Smart Empty | Pull All, Quick Fill | | ------- | ---------------------- | ------------------------------------- | ----------------------------------------------------- | | LOCKED | Leaves it where it is. | Never take from it. | Pull All puts nothing in. Fill does not fetch for it. | | TOP\_UP | Leaves 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**](https://voxelsprout.com/sorted/wiki/settings#setting-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) slot -> Favorites.isMarked(slot) ? "LOCKED" : null); } catch (ReflectiveOperationException e) { // Sorted is not installed, or older than 0.1.42. Nothing to do. } } ``` ## Reference | SortedProtection | What it does | | -------------------------------------------------------------------- | ---------------------------------------------------------------------------------------- | | register(String owner, IntFunction inventorySlot) | Your answer for the player's inventory. | | registerEnderChest(String owner, IntFunction 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\_UP | The two levels, as strings. | ## Next, you may want to * [Use Alt for your own gesturesInput API](https://voxelsprout.com/sorted/wiki/input-api) [Previous Actions API](https://voxelsprout.com/sorted/wiki/actions-api) [Next Input API](https://voxelsprout.com/sorted/wiki/input-api) Something missing or wrong on this page? Say so on [Discord](https://discord.gg/CvdkGbEW4y).