Check the valididty of a crafting recipe

Sorry to ask yet another question, I just keep hitting roadblocks. I’m using Sponge 7.2.0.

I’m trying to check if some ordered collection of ItemStacks creates a valid crafting recipe, and, if so, what the result would be. I understand that a recipe can be checked using
CraftingRecipeRegistry.getResult(CraftingGridInventory grid, World world) CraftingRecipeRegistry (SpongeAPI 7.2.0 API).

My probelm is I have no idea how to actually get a CraftingGridInventory that I can use, nor have I found another way to check the validity of a recipe.

Once again, I appreciate the help.

Personally i would create a custom inventory of a crafting inventory. Then use the crafting grid inventory of that.

When you create a custom inventory, by default it wants a regular chest. So the best option is to use the Inventory archetype of the crafting inventory and then build it without any extra mods. If you apply any, the object that comes out is a custom inventory, not something you can cast to

https://jd.spongepowered.org/spongeapi/7.2.0/org/spongepowered/api/item/inventory/crafting/CraftingInventory.html

But anyone. Once you have done of and then cast it, you should be able to use that.

I’ve not had any luck with that method. This is the code I’m using:

CraftingInventory craftingInv = (CraftingInventory) Inventory.builder()
                .of(InventoryArchetypes.WORKBENCH)
                .build(this); // In my main plugin class

Which gives me a ClassCastException

Exception:
    java.lang.ClassCastException:
    org.spongepowered.common.item.invent
    ry.custom.CustomInventory cannot be
    cast to
    org.spongepowered.api.item.inventory
    crafting.CraftingInventory
    crashdive.RecipePlanFixPlugin.programRecipePlan(RecipePlanFixPlugin.java:183)
    crashdive.RecipePlanFixPlugin.callback(RecipePlanFixPlugin.java:318)
    ...

I’m not sure what to do at this point. :confused:

Oh shoot. Its been a while since i have done api 7 stuff so cant remember exactly. It maybe that its a child of the custom inventory.

I would suggest using intelij debug to get the internal values of the custom inventory