Fabric API

Fabric API

108M Downloads

[1.18.2][FAPI 48.0] Ingredient.fromJson fails to fill tags with items on first world load

Nosrick opened this issue ยท 8 comments

commented

Issue:
Hopefully this isn't a problem with the code, but I've stripped down the mod I was updating to 1.18.2 for my own practise purposes (Farmer's Delight), and I've found that calling Ingredient.fromJson() in a RecipeSerializer does not fill the contents of a tag when the world is loaded for the first time.

If the world is reloaded, or /reload is used, it will parse the tags correctly. Not sure if this is a Minecraft problem, or something FAPI is doing with mixins.

The tag exists in the correct namespace, folder, etc, and it is filled on the second attempt, and the recipe works.

Expected Behaviour:
Tags used by a deserialized recipe are filled with the correct item stacks.

Actual Behaviour:
Tags are empty of item stacks until /reload is used, or the world is loaded a second time in one session.

Minimum test harness:
https://github.com/Nosrick/ingredient-parsing-harness

Steps to reproduce:

  1. Place down a cutting board
  2. Get an axe and a dark oak log
  3. Place the log on the cutting board with a right click
  4. Select the axe and right click on the cutting board
  5. You will receive the message "This doesn't seem cuttable..."
  6. Type /reload, and wait a few seconds
  7. Right click the log on the cutting board with the axe again
  8. Receive a stripped dark oak log

Additional Info:
Specifically, the thing that seems to fail is the Ingredient.fromJson() call on line 45 of CuttingBoardRecipeSerializer.
It will not fill the Ingredient on the initial load, but when /reload is used, it will fill correctly.

If this is a problem with the code, I'd appreciate any advice!

EDIT: updated my FAPI to 48.0, but no change.

commented

Disclaimer: I haven't tried your example or the 1.18.2 tag stuff.

My guess is your problem is because fabric in 1.18.2 no longer registers those tags: #1989

The datapacks are loaded in 2 passes:

  • Parse
  • Apply (if all the parses work)

So when it parses your ingredient on first load it uses a dummy empty tag because it is not registered.
On reload the apply will have registered the tag loaded from the datapack so now it has data.

Try registering the tag in your mod initialiser until (if?) those tags get restored: #2063
The idea is your parse will get the registered tag which is initially empty but will get the data during the apply.

commented
commented

Yeah, tags seem to work with the vanilla recipes I've tested (shapeless, cooking, shaped), but I can't figure out why. It just calls Ingredient.fromJson and it works. There's some magic going on here that I don't quite understand. Yet.

commented

Maybe check that it works with vanilla shapeless recipes (which I assume), and why it does?

commented
commented

Ah, thank you so much! This explains a lot, and gives me a solution to try. I'll probably close this issue ina few days; not working until Monday, so I'll try it then.

commented

I'm assuming you had time to figure it out and that it works. ๐Ÿ˜„

commented

Oh my god I'm so sorry I completely forgot about this, because life got in the way.
I haven't had a chance to do anything with it, so far, but assume the link you've provided will fix it!