Jump to content

[1.19] Check when the crafting matrix has a valid craft


WhatIsABlock

Recommended Posts

Hello,

I am looking to create an event handler for whenever the crafting matrix of the vanilla Inventory or Crafting Table menu has a valid craft.  The way that I had thought about doing that would be by checking if the menu's resultSlot is occupied by something.

My idea was to do so through events: call getScreen() from a MouseClickedEvent and check if the screen was InventoryScreen or CraftingScreen.  From there I would try to access the menu, but the menu attribute in AbstractContainerScreen is protected, so that is a no-go for me. 

In short, my questions are:

  1. Is there a way of accessing the Menu from an event?
  2. Is there a way of telling whether or not there is a valid craft in the crafting matrix?
Link to comment
Share on other sites

Your proposed solution won't work - for interest you would implement it like this:

    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
    public class DONT_TRY_TO_USE_THIS
    {
        @SubscribeEvent
        public static void DOES_NOT_WORK(ScreenEvent.MouseButtonPressed.Post event)
        {
            if (event.getScreen() instanceof CraftingScreen craftingScreen) {
                CraftingMenu menu = craftingScreen.getMenu();
                LOGGER.info("result: " + menu.getSlot(0).getItem()); // Prints the wrong thing!
            }
        }
    }

I posted this, so you can see how to get the menu.

 

The problem is the result has not been determined when you handle the mouse click.

The game has to send a network packet to the server to ask if there is a valid recipe.

The result of that query does not get updated on the client until *after* the mouse event.

 

There is an ItemCraftedEvent, but that handles items removed from the result slot, which doesn't sound like what you want?

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Quote

There is an ItemCraftedEvent, but that handles items removed from the result slot, which doesn't sound like what you want?

Thank you for the example, I really should have seen the obvious getMenu() function.  Yes, ItemCraftedEvent is not what I want.  Ideally this event would fire after the player either clicks one of the recipes in the recipe book (with all of the needed materials for that recipe), or after the player slots in an item into the crafting matrix that results in a valid craft.

Quote

What do you want to do as a result of this?

My intention is to detect when the crafting matrix has been filled with a valid craft, and submit to the Minecraft instance a TutorialToast.  This is part of a student project of mine where I augment the vanilla Tutorial with more instructions on how to play the game.  

Link to comment
Share on other sites

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.