Jump to content

[1.16.4] Custom recipe type doesn't work with custom machine.


Recommended Posts

Posted

I made a custom machine in my mod alongside a custom recipe but I can't seem to get the output to update based on the input. Help would be appreciated!

Here is how i am trying to implement it in my container.

    public void updateOutput() {
        List<SpiritRecipe> list = world.getRecipeManager().getRecipes(ModRecipeSerializers.SPIRIT_TYPE, inventory, world);
        if (list.isEmpty()) {
            craftResultInventory.setInventorySlotContents(0, ItemStack.EMPTY);
            System.out.println("List is empty");
        } else {
            SpiritRecipe spiritRecipe = list.get(0);
            ItemStack itemstack = spiritRecipe.getCraftingResult(inventory);
            craftResultInventory.setRecipeUsed(spiritRecipe);
            craftResultInventory.setInventorySlotContents(0, itemstack);
        }
    }

    @Override
    public void onCraftMatrixChanged(IInventory inventoryIn) {
        super.onCraftMatrixChanged(inventoryIn);
        if (inventoryIn == inventory) {
            updateOutput();
        }
    }

 

Posted
9 minutes ago, diesieben07 said:

Does it find the recipe? Does the recipe work properly? Have you tried using the debugger?

I didn’t thought of a debugger. Ill check now. The output doesnt change so no it doesnt work properly. Are the methods written properly?

Posted
8 minutes ago, diesieben07 said:

No, you have to call it manually from your slots. Look at the vanilla crafting containers for reference.

I will do that! Thank you very much for your time!

Posted
1 hour ago, diesieben07 said:

Look at e.g. LoomContainer.

Something like this?

    @Override
    public void onCraftMatrixChanged(IInventory inventoryIn) {
        ItemStack itemStack = base.getStack();
        ItemStack itemStack1 = addition.getStack();
        ItemStack itemStack2 = result.getStack();
        if (itemStack2.isEmpty() && itemStack.isEmpty() || itemStack1.isEmpty()) {
            this.result.putStack(ItemStack.EMPTY);
        }
        
        super.onCraftMatrixChanged(inventoryIn);
        updateOutput();
    }

 

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

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