JayZX535 Posted June 7, 2020 Posted June 7, 2020 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. Quote
poopoodice Posted June 7, 2020 Posted June 7, 2020 (edited) 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 June 7, 2020 by poopoodice Quote
JayZX535 Posted June 7, 2020 Author Posted June 7, 2020 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? Quote
JayZX535 Posted June 8, 2020 Author Posted June 8, 2020 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! Quote
JayZX535 Posted June 9, 2020 Author Posted June 9, 2020 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! Quote
Recommended Posts
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.