Jump to content

[1.14.4] Getting Items from Recipe / Drawing Items on GUI


JayZX535

Recommended Posts

Hello again,

 

I'm wondering what the best way to get an item/itemstack from a recipe is.  I'm trying to draw a recipe to the screen-- sort of like the crafting guide, but not quite.  I don't want to hardcode it because of the way recipes can now be altered with a datapack.  So basically I'm trying to load the current (shaped) recipe for an item (if it exists), loop through it and get the item/itemstack (if not empty) for each space in the grid, and draw it to the screen.  It's worth noting that, due to the way this particular GUI is set up, I'm not using an actual container for it.  I'd like to avoid using a container if at all possible just due to the way this particular GUI works-- so I need a way to draw the stacks on the screen without a container, either by drawing the item/stack directly or by getting its texture location.

 

Is there a good way I can go about doing this?

 

Thanks, and have a great day.

Link to comment
Share on other sites

you can use itemrenderer to draw items onto the screen (there are quite a lot of render item methods, check ItemRenderer or BeaconScreen), and I guess they are all pretty simple and straight forward, you should be able to get what they do.

Edited by poopoodice
Link to comment
Share on other sites

5 minutes ago, poopoodice said:

you can use itemrenderer to draw items onto the screen (there are quite a lot of render item methods, check ItemRenderer or BeaconScreen), and I guess they are all pretty simple and straight forward, you should be able to get what they do.

ItemRenderer looks exactly like what I need to draw the items.  Thank you so much!  I didn't realize the beacon used anything that wasn't slot based.

 

Only question now is, how do I get them from the recipe in the first place?

Link to comment
Share on other sites

7 hours ago, diesieben07 said:

IRecipe#getIngredients to get the recipe's ingredients. You can then use Ingredient#getMatchingStacks, but that can just be an approximation in certain cases.

As for the output, you can call IRecipe#getRecipeOutput, but that is again just an approximation, the only way to really determine the output is to call getCraftingResult with an inventory that has the actual inputs.

Ohhh I see that now!  I was confused by that getMatchingStacks at first, but given that item tags are a thing, I think I understand it now?  I assume that's why it's an array rather than a static ItemStack-- to account for recipes that take in multiple possible ingredients?

 

Happy to say I've got it all working now!  I know some modpacks like to change/remove recipes, so I wanted to make sure I got the recipe from its source rather than hardcoding it in.  ItemRenderer works like a charm too.  Thanks for the help!

Link to comment
Share on other sites

7 hours ago, diesieben07 said:

Yes, but like I said it is only an approximation. The only way to know if an ItemStack matches an ingredient is to ask that ingredient "does this match?".

Makes sense.  Looks like that's the function of the test boolean from Ingredient-- to check a specific stack and make sure it fits.

 

Right now for my GUI I've asked it to give me the first stack from Ingredient#getMatchingStacks() to display in the GUI.  This seems to work with the recipes I have so far, but I'll continue to monitor it (especially if I end up with any recipes with multiple possible inputs).  My biggest concern is if the recipe gets changed (I know some modpacks really like doing that, for example), but I think this should at least return a result if the recipe is craftable (and I'd imagine blank if it's not?).  And if people really want to know how to craft something, I expect they'll look first to the crafting guide.  The GUI I'm working with here is the lore book, so it has more info on how the stuff actually works-- the recipes are just there for easy reference.  So I'm hoping this will at least function acceptably for what I'm trying to get it to do.

 

Thanks!

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.