Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/VazkiiMods/Quark/llms.txt

Use this file to discover all available pages before exploring further.

Quark registers NeoForge capabilities that allow other mods to provide custom behavior through the standard NeoForge capability system. Currently, the primary exposed capability is QuarkCapabilities.CUSTOM_SORTING_CAPABILITY, which lets items provide custom inventory sorting logic.

QuarkCapabilities.CUSTOM_SORTING_CAPABILITY

package org.violetmoon.quark.api;

public class QuarkCapabilities {
    public static final ItemCapability<ICustomSorting, @Nullable Void> CUSTOM_SORTING_CAPABILITY =
        ItemCapability.createVoid(
            Quark.asResource("custom_sorting"),
            ICustomSorting.class
        );
}
This is an ItemCapability<ICustomSorting, Void> registered under the resource location quark:custom_sorting. Quark’s inventory sorting system queries this capability on every item in the inventory to determine custom sort order and grouping.

When to Use the Capability vs. the Interface

You have two options for providing ICustomSorting:
ApproachWhen to use
Implement ICustomSorting directly on your Item classYour item always has the same sorting behavior regardless of NBT/components
Provide it via CUSTOM_SORTING_CAPABILITYYou need per-stack sorting logic, or you can’t modify the Item class (e.g. patching a third-party item)
For most mods, implementing ICustomSorting directly on the Item is simpler. Use the capability approach when you need dynamic, per-stack behavior.

Providing the Capability from Your Item

Register a capability provider in your mod’s initialization using RegisterCapabilitiesEvent:
@Mod.EventBusSubscriber(modid = "mymod", bus = Mod.EventBusSubscriber.Bus.MOD)
public class MyCapabilityRegistration {

    @SubscribeEvent
    public static void registerCapabilities(RegisterCapabilitiesEvent event) {
        event.registerItem(
            QuarkCapabilities.CUSTOM_SORTING_CAPABILITY,
            (stack, unused) -> new MyItemSorting(stack),
            MyModItems.MY_ITEM.get()
        );
    }
}
The lambda (stack, unused) -> ... receives the ItemStack and a null context (since this is a Void-context capability), and must return an ICustomSorting instance.

Example ICustomSorting Implementation

public class MyItemSorting implements ICustomSorting {

    private final ItemStack stack;

    public MyItemSorting(ItemStack stack) {
        this.stack = stack;
    }

    @Override
    public Comparator<ItemStack> getItemComparator() {
        // Sort by damage value (durability remaining) ascending
        return Comparator.comparingInt(ItemStack::getDamageValue);
    }

    @Override
    public String getSortingCategory() {
        // All items in your mod's wand family sort together
        return "mymod:wands";
    }
}
Items with the same getSortingCategory() are grouped together during sorting and compared using getItemComparator(). Make your category unique by prefixing it with your mod ID.

Querying the Capability

Quark queries the capability automatically during inventory sorting — you do not need to call it yourself. However, if you want to read another mod’s sorting information, you can query it:
import org.violetmoon.quark.api.QuarkCapabilities;
import net.neoforged.neoforge.capabilities.Capabilities;

ICustomSorting sorting = stack.getCapability(QuarkCapabilities.CUSTOM_SORTING_CAPABILITY);
if (sorting != null) {
    String category = sorting.getSortingCategory();
    Comparator<ItemStack> comparator = sorting.getItemComparator();
    // use them...
}

ISortingLockedSlots

If you have a custom Menu and want to prevent Quark from sorting certain slot indices, implement ISortingLockedSlots on your Menu class (which also extends IQuarkButtonAllowed to show the Q buttons):
public class MyStorageMenu extends AbstractContainerMenu
        implements ISortingLockedSlots {

    @Override
    public @Nullable int[] getSortingLockedSlots(boolean sortingPlayerInventory) {
        if (!sortingPlayerInventory) {
            // Lock slots 0-8 (the top row of our custom grid)
            return new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8};
        }
        return null; // allow sorting the player inventory portion
    }
}

Build docs developers (and LLMs) love