Jump to content

[1.14.4] [SOLVED] How to get Recipes with IItemHandler


Recommended Posts

I've been using an IItemHandler (which, according to the Forge docs, we're supposed to use instead of IInventory) to handle the inventory of one of the processing blocks in my mod. However, I'm not sure how to get recipes with it. The Minecraft RecipeManager requires an IInventory as the second parameter of #getRecipe(), and I couldn't find a Forge RecipeManager nor a different method that would take an IItemHandler and return a recipe.


Does anyone know how I can get recipes using my IItemHandler?


Just for reference, here's what I'm trying to do:

public class GrinderTileEntity extends TileEntity implements ITickableTileEntity, INamedContainerProvider {
    private LazyOptional<IItemHandler> itemHandler = LazyOptional.of(this::createItemHandler);
    private LazyOptional<IEnergyStorage> energyHandler = LazyOptional.of(this::createEnergyHandler);
    private int counter = 0;

    public GrinderTileEntity() {

    public void tick() {
        if (world.isRemote)

        //Nothing to do if we have no energy
        AtomicBoolean hasEnergy = new AtomicBoolean();
        energyHandler.ifPresent( e -> hasEnergy.set(e.getEnergyStored() > 0) );
        if (!hasEnergy.get())

        //Nothing to do if there isn't an item.
        AtomicReference<ItemStack> stack = new AtomicReference<>();
        itemHandler.ifPresent( h -> stack.set(h.getStackInSlot(0).copy()) );

        AtomicReference<IItemHandler> inventory = new AtomicReference<>();

        //#getRecipe() is where it breaks, specifically inventory.get()
        IRecipe<?> recipe = world.getRecipeManager()
                .getRecipe(RecipeTypes.GRINDING, inventory.get(), world)
   /* ************************************************
    * Used to create the IItemHandler for itemHandler
	private IItemHandler createItemHandler() {
        return new ItemStackHandler(2) {
            public boolean isItemValid(int slot, @Nonnull ItemStack stack) {
                return ItemTags.getCollection()
                        && slot == 0;

            public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
                if (slot != 0
                        || !ItemTags.getCollection()
                ) {
                    return stack;
                return super.insertItem(slot, stack, simulate);

            protected void onContentsChanged(int slot) {

  //other functions...



Link to comment
Share on other sites

9 minutes ago, TheMikeste1 said:

Does anyone know how I can get recipes using my IItemHandler?

Create a RecipeWrapper it takes in a IItemHandlerModifiable and it's an IInventory.

  • Thanks 1


I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

  • TheMikeste1 changed the title to [1.14.4] [SOLVED] How to get Recipes with IItemHandler

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.