[1.18.2][FAPI 48.0] Ingredient.fromJson fails to fill tags with items on first world load
Nosrick opened this issue ยท 8 comments
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:
- Place down a cutting board
- Get an axe and a dark oak log
- Place the log on the cutting board with a right click
- Select the axe and right click on the cutting board
- You will receive the message "This doesn't seem cuttable..."
- Type /reload, and wait a few seconds
- Right click the log on the cutting board with the axe again
- 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.
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.
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.
Maybe check that it works with vanilla shapeless recipes (which I assume), and why it does?
Maybe have a look at MinecraftForge/MinecraftForge#8498.
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.