Jump to content

[1.15.2] Getting Recipes using RecipeManager


Blu_Nighttime

Recommended Posts

for (Item item : ForgeRegistries.ITEMS) {
  IRecipe<?> iRecipe = world.getRecipeManager().getRecipe(Objects.requireNonNull(item.getRegistryName())).orElse(null);
  if (iRecipe != null) {
    // get ingredients ...
  }

 

I'm using the above function to get the recipes of items that have been registered referencing ForgeRegistries. This is successful and I'm able to get the ingredients for a smelting recipe for example, for all vanilla items; however, getRecipes() returns null when item belongs to my mod. There are recipes for smelting/blasting those items and work with a normal furnace/blast furnace in-game yet don't return a IRecipe<?> like the vanilla items do.

 

Just trying to figure out what I'm missing that Minecraft/Forge implements that I don't to get a null return and not valid IRecipe<?>

 

Any help to this would be much appreciated and any pointers to where to further look would be appreciated as well.

Link to comment
Share on other sites

1 hour ago, diesieben07 said:

This doesn't make sense. This is getting a recipe with the same name as an item.

Not only that, but registry names CAN'T be null, so "require non-null" is useless.

 

Now...where are my recipe utils...

Hm, not updated since 1.12, but might give some insight.

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/util/RecipesUtils.java#L164

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Sorry, was trying to be a bit more general for all applications. It's for a custom smelter so currently how it works as just a quickly thrown together system is that when the tile entity is loaded into the world it executed the function, as shown above, and adds the ingredient and result to a map that I then iterate over if the contents for the 0th slot (input slot) are changed and gets corresponding result from the ingredient if it's in that map.

 

I was trying to find a way if I could get a recipe output from the ingredient that's placed inside first, which is how a crafting table works (I believe), but hadn't had any success with trying to implement that so went with the function I showed above and have it only execute once which is upon the tile being placed into the world once it has loaded from the mod starting up.

 

It's apparent that this isn't the greatest way to implement the system but was struggling to find resources on how it should be implemented.

 

 

1 hour ago, diesieben07 said:

RecipeManager#getRecipe(IRecipeType, C, World)

If I placed cobblestone into the input slot, would this then return stone if I fetch its smelting/blasting recipe? If so that'd be what I'm looking for, and assuming by what you said this is the case. This would also remove the need to load all recipes on the tile entity being loaded which is just a bodge solution to the scenario.

 

Do I need world or just call RecipeManager?

 

 

26 minutes ago, Draco18s said:

Not only that, but registry names CAN'T be null, so "require non-null" is useless.

It's IntelliJ's Lint for doing that. It's pretty clear that this is indeed the case so I don't understand why it needs to be flagged but I guess IntelliJ isn't that intelligent.

 

 

28 minutes ago, Draco18s said:

Thanks for the reference, just took brief look at it. It's a bit annoying trying to get what the replacement methods and functions are from 1.12 to 1.14/1.15 as CraftingManager doesn't exist but I'll try to implement something similar along with what Diesie suggested.

 

 

Thanks in advance as well with what has been suggested.

Link to comment
Share on other sites

1 hour ago, Blu_Nighttime said:

Thanks for the reference, just took brief look at it. It's a bit annoying trying to get what the replacement methods and functions are from 1.12 to 1.14/1.15 as CraftingManager doesn't exist but I'll try to implement something similar along with what Diesie suggested.

Yeah, its changed, but the info is still there somewhere.

I just haven't updated it because the portion of my mod that relied on it I haven't re-written yet. So its been low priority.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

So I've implemented the following statement to be as similar to what's in AbstractFurnaceTileEntity#tick 

IRecipe<?> irecipe = world.getRecipeManager().getRecipe(IRecipeType.SMELTING, this, world).orElse(null);

My tile entity class now implements ISidedInventory like AbstractTileEntity does but now I only ever receive null. Should the param this actually reference my container class for the block or am I missing something else?

 

If I should be referencing the container class, how would I go about doing that to satisfy the inventoryIn param?

Link to comment
Share on other sites

1 hour ago, Blu_Nighttime said:

My tile entity class now implements ISidedInventory like AbstractTileEntity does but now I only ever receive null. Should the param this actually reference my container class for the block or am I missing something else?

Don't. Get rid of ISidedInventory and use ItemStackHandler fields instead.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L39

https://github.com/Draco18s/ReasonableRealism/blob/1.14.4/src/main/java/com/draco18s/harderores/entity/SifterTileEntity.java#L147

 

I don't deal with recipes in the same way the furnace does, but that's how you use ItemStackHandlers. The output wrapper is a custom ItemStackWrapper class that accepts another in its constructor and prevents insertion, so that it can be exposed via getCapability to allow extraction, but the original stack handler can still modified by the machine itself.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Thanks for the examples, shows me some options on how I might be able to restructure my class if needs be in the future.

 

However, I'm failing to understand what I'm passing into getRecipe() that satisfies C as the inventoryIn as the second parameter. the input slot for the custom smelter is an ItemStackHandler but passing this isn't allowed and I'm not sure if it's something that needs casting/converting to something else or what that would mean that C is satisfied.

Any knowledge on this is greatly appreciated.

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.