HT's TreeChop

HT's TreeChop

3M Downloads

[1.16.5-0.14.2] TreeChop classloads TagCollectionManager too early and can break other mod's tags

TelepathicGrunt opened this issue ยท 3 comments

commented

Hello! I received a report in my discord channel about how my mod was crashing due to seemingly impossible missing structure pieces. I asked the person to put on the mod called Blame and give me the latest.log file after it crashes. Turns out the issue was due to TagCollectionManager being classloaded too early. To make sure, I ran the mod with Blame and a few other mods and here's the latest.log file of that and the mods on:
latest.log
image

It's hard to explain but the reason why classloading TagCollectionManager at mod startup is dangerous is because if it is classloaded before another mod can register their tags in code, the tag will blow up where-ever it is used as it now will not exist in TagCollectionManager. In this case, TagCollectionManager was classloaded too early, broke The Undergarden's tag that they use in their worldgen features, and the parse error cascaded out of that json file into all worldgen json files including my own which caused a massive ton of our mods to no longer spawn and crash in some cases.

The best solution would be to never try to get a tag before a world exist as tags really aren't a thing at mod startup and reading tags before the world is entered defeats the purpose of letting users configure tags with datapacks that aren't loaded yet. But if you need to use TagCollectionManager early, could you try delaying it to after FMLCommonSetupEvent is finished for all mods? At that point, all mod's tags should be finished being registered in code. Though if you are just needing a reference to a tag to store somewhere to grab after the world is made, try using Lazy.of(() -> <the tag>) to create a lazy that will only run its code when you call .get() on it later and thus, prevents TagCollectionManager from being classloaded too early.

I hope this helps!

commented

Hey Grunt, thanks for reporting this, and for the very detailed explanation! I definitely don't need to be messing with tags before the world loads, it was only being done for convenience when reloading the mod's config. I also didn't realize that datapacks don't load until entering a world -- that is very useful to know!

I'll have this fixed right away.

commented

I was able to reproduce the crash. It should be fixed as of TreeChop 0.14.3. Thanks again! Probably saved a lot of folks a lot of headache.

commented

Nice! Looks like the update works. I'll close this now and let the other user know to update. Thank you!