Curios API (Forge/NeoForge)

Curios API (Forge/NeoForge)

140M Downloads

Question: how to filter item insertion to item handlers retrieved via API?

desht opened this issue · 3 comments

commented

Hi, I'm looking to write some mod integration between my mods (PneumaticCraft and Modular Routers), and I'm using the Curios API to retrieve the player's Curios item handlers for automated insertion/extraction. However, I notice that these item handlers don't do any kind item filtering on what may be inserted, unlike when you attempt to insert items via GUI slots.

Am I missing something here, or this is an oversight in the mod?

For reference, my current approach is to build an item handler like this, using the Forge CombinedInvWrapper on all Curios item handlers for the given player:

public static IItemHandler makeCombinedInvWrapper(@Nonnull Player player) {
        return CuriosApi.getCuriosHelper().getCuriosHandler(player)
                .map(handler -> new CombinedInvWrapper(handler.getCurios().values().stream()
                        .map(ICurioStacksHandler::getStacks)
                        .toArray(IItemHandlerModifiable[]::new))
                ).orElse(new CombinedInvWrapper());
}

This item handler seems happy to allow insertion of any item into the player's Curios slots, regardless of whether they can be inserted via inventory GUI.

commented

Hmm, at a quick glance, probably an oversight in the mod. I don't think anyone has tried to use Curios in this way before, at least none that has been brought up to me before. The problem is likely because Curios does validity checks outside of the item handlers themselves because it only expects to be interacted with directly through the container or the capability. I'll look into the best way to accommodate for your use-case.

commented

Encountering the same issue here while trying to add Curios functionality to Advanced Peripheral's Inventory Manager

commented

Sorry for the long delay on this.

I've just released Curios 5.3.0 for 1.20.1, which addresses this issue by consolidating all of the validation checks into the item handlers. Interacting with the item handlers directly, such as the example in the OP, should work correctly without any other changes or checks needed. Please let me know if there any other further issues or if the issue persists, and if there are any other questions or concerns about how to interact with the API.