Spectrum

Spectrum

2M Downloads

[BUG] Attempting to initialize a FabricBlockLootTableProvider object results in a crash

Librv opened this issue ยท 5 comments

commented

Describe the bug
Trying to initialize a FabricBlockLootTableProvider object (e.g. MyBlockLootTableProvider) while Spectrum (and its dependencies) is included in the same instance results in a crash at startup.

To Reproduce
Include this example mod in a 1.19.2 instance together with Spectrum (1.6.10) and its dependencies. This is a simple mod that creates a BlockLootTableProvider object at initialization and nothing else, see here.

Below is the mod list used and the versions for each dependency, which are also detailed in the logs.
image

Expected behavior
Game loading without issues. Note: provider isn't used, meaning that no data is being generated at any point.

Mod version
1.6.10

Screenshots

Crash Report
crash-2023-05-04_21.01.40-client.txt
latest.log

commented

Your example mod is adding loot tables at a point where mods have not finished initialisation yet.
Instead, you should load loot tables at the same time vanilla does - when loading a world.
Does the mod still crash, then?
(Can check in 3 days)

commented

Moving the initialization for BlockLootTableProvider to client initialization fixes the crash, but why isn't initializing a standard LootTableProvider during mod initialization causing problems?

Also, what loot tables are being created? I'm simply creating an instance of a provider that can't be run because it isn't added to any DataGenerator, meaning that no .json files will be created.

I also want to add that attempting to pass a loot builder created from BlockLootTableGenerator through LootTableProvider (see here) creates the same exact crash, and it's worth noting that this generator class is extended by FabricBlockLootTableProvider. This generator class is all about methods for creating, as the name implies, block loot tables, but it also contains a static initializer block at the bottom that I think is worth looking at.

Thank you for your patience ๐Ÿ‘

commented

BlockLootTableProvider loads the class ItemPredicate
...which triggers Spectrum's Shears Mixin to load
...which then loads the SpectrumItems class
...which then acts up, because the config has not been loaded yet (Since Spectrum's mod initializer has not yet run).

You can probably also trigger that crash by using a ItemPredicate in your LootTableProvider.

That mixin sadly is a remnant from minecraft/fabric not having a dedicated shears item tag, with minecraft:shears being hardcoded in lots of vanilla loot tables and is used in different variations in other mods, like Botania. Once FabricMC/fabric#1287 is done that mixin can be ditched. ๐Ÿ˜Š

commented

Understood, I guess I'll be joining the wait for the shears tag! ๐Ÿ˜…
I'll look into having every provider done at client initialization from here on out.
Thanks for your help again, I'll be closing this.

commented

Happy to help!