[FAPI 0.68.1] DataGeneratorEntrypoint has RaceCondition with Registry Bootstrap
quiqueck opened this issue ยท 7 comments
Sorry to bother you again about the DataGeneratorEntrypoint, and maybe I do have a strange setup or have an improper configuration. But I checked all resources so far and didn't find anything about this.
So I have a Library-Mod and depending Mod setup as Modules in IntelliJ. Both have a DataGeneratorEntrypoint that write similar data from (for example) the Biome-Registry.
I noticed, that when I run the DataGenerator for my Mod, fabric will also execute the generator for the Library-Mod. While this was unexpected, I think this is intentional. However I have two problems:
- Both Mods writhe the data to the same director. So, the generated Directory of my mod will contain the elements for both the library and the mod itself. So I have to manually remove the duplicate entries, which (in my opinion) is very error prone.
- There also appears to be a race condition. Sometimes (especially when I delete the generated directory first), only the files form the Library Mods are created, so I end up with a Mod that will only include the elements for the library, and not the Mod itself. As I said, this happens randomly.
This is intended behavior. You should be able to use vmArg "-Dfabric-api.datagen.modid=<modid>"
to restrict the mod ids that run.
I did some more testing, and as far as I can tell, there is a Race-Condition between the registry Bootstrap and the execution of the DataProviders (this is a test with just the lib mod, so only one DataGenerator is executed).
My code adds a custom DataProvider in onInitializeDataGenerator
:
pack.addProvider(NetherRegistriesDataProvider::new);
The Provider is similar to FabricDynamicRegistryProvider
and I observe the same behaviour using an instance of FabricDynamicRegistryProvider
. Basically the Provider will dump the content of several Registries.
For most of those registries, I did also define a registry bootstrap in buildRegistry
:
registryBuilder.add(Registries.BIOME, NetherBiomesDataProvider::bootstrap);
In all, there are 8 different Registries I am trying to write. Most of the time all elements from those 8 registries are written. But every other run some entries (or entire registries) are not written. From the Looks of it, the Registry-bootstrap was not yet finished, and some entries are missing.
Is there a code I can use for testing, that uses FAPI one (not custom one)? @quiqueck
I'm sure the current code works, and it is probably a bug on your side. But we need to see if that is the case first.
buildRegistry
is invoked asynchronously and will run at the sametime as onInitializeDataGenerator
(Matches vanilla datagen). You can use the CompletableFuture<RegistryWrapper.WrapperLookup>
to access registry entries created in buildRegistry
.
All code invoked from buildRegistry
should be thread safe, if its not you can add a constructor to your entrypoint to go before these two methods.