Jump to content

[Solved] [1.13.2] Smelting recipe with NBT manipulation


xerca

Recommended Posts

I have a smelting recipe that needs to copy its input's NBT data to its output. I tried to use a custom IRecipe for that like I did for similar crafting recipes, but the smelting code in TileEntityFurnace does not respect getCraftingResult() at all. It only uses getRecipeOutput() as such (which is normally for display purposes)

ItemStack itemstack = this.furnaceItemStacks.get(0);
ItemStack itemstack1 = recipe.getRecipeOutput();
ItemStack itemstack2 = this.furnaceItemStacks.get(2);
if (itemstack2.isEmpty()) {
   this.furnaceItemStacks.set(2, itemstack1.copy());
} else if (itemstack2.getItem() == itemstack1.getItem()) {
   itemstack2.grow(itemstack1.getCount());
}

So I cannot set the NBT data of the output ItemStack.

 

I also tried using a PlayerEvent.ItemSmeltedEvent, however that event does not give me any handle to the input, it only has the output. So I cannot read the input's NBT in this way.

 

Is there another way to do what I am trying to achieve other than creating infinite JSONs or editing the vanilla furnace code?

Edited by xerca
Link to comment
Share on other sites

2 hours ago, diesieben07 said:

One very hacky way would be to "remember" the furnace inside the IRecipe#matches version and use that to return the proper item in getRecipeOutput.

You would have to reset this at some point though. Some experimenting is probably needed.

Unfortunately I don't have any way of knowing which furnace is calling getRecipeOutput, so this would probably only work if there is just one active furnace in the whole world at a time :(.

Link to comment
Share on other sites

Thank you, you're right, it calls matches continously a few lines before getting the output. Assuming the main game code runs in a single thread, hopefully there will be no race conditions. I got away with just remembering the required NBT value of the itemstack. It seems to work for now, although it is one of the more bizarre workarounds I did. I hope forge adds a way to do this normally in the future.

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.