More Race-Condition fixes
This commit is contained in:
parent
457673d721
commit
3b2d8529e2
3 changed files with 19 additions and 61 deletions
|
@ -60,7 +60,8 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
|||
cachedOutput,
|
||||
registriesProvider,
|
||||
dynamicOps,
|
||||
registryData
|
||||
registryData,
|
||||
registries
|
||||
))
|
||||
.toArray(CompletableFuture<?>[]::new);
|
||||
|
||||
|
@ -71,12 +72,19 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
private <T> CompletableFuture<?> serializeRegistry(
|
||||
CachedOutput cachedOutput,
|
||||
HolderLookup.Provider registryAccess,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
RegistrySupplier.RegistryInfo<T> registryData
|
||||
RegistrySupplier.RegistryInfo<T> registryData,
|
||||
RegistrySupplier registries
|
||||
) {
|
||||
try {
|
||||
registries.MAIN_LOCK.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final List<Holder<T>> elements = registryData.allElements(registryAccess);
|
||||
final HolderLookup.RegistryLookup<T> registry = registryAccess.lookupOrThrow(registryData.key());
|
||||
LOGGER.info("Serializing "
|
||||
|
@ -86,6 +94,7 @@ public abstract class RegistriesDataProvider implements DataProvider {
|
|||
+ " elements from "
|
||||
+ registryData.data.key()
|
||||
);
|
||||
registries.MAIN_LOCK.release();
|
||||
|
||||
if (!elements.isEmpty()) {
|
||||
PackOutput.PathProvider pathProvider = this.output.createPathProvider(
|
||||
|
|
|
@ -7,13 +7,10 @@ import net.minecraft.core.Holder;
|
|||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistrySetBuilder;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.worldgen.BootstapContext;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
@ -23,6 +20,7 @@ import org.jetbrains.annotations.Nullable;
|
|||
public abstract class RegistrySupplier {
|
||||
private static final int MAX_PERMITS = 2000;
|
||||
private final Semaphore BOOTSTRAP_LOCK = new Semaphore(MAX_PERMITS);
|
||||
public final Semaphore MAIN_LOCK = new Semaphore(1);
|
||||
|
||||
final List<RegistrySupplier.RegistryInfo<?>> allRegistries;
|
||||
@Nullable List<String> defaultModIDs;
|
||||
|
@ -60,55 +58,6 @@ public abstract class RegistrySupplier {
|
|||
BOOTSTRAP_LOCK.release(MAX_PERMITS);
|
||||
}
|
||||
|
||||
|
||||
public <T> void addWithLock(
|
||||
RegistrySetBuilder registryBuilder,
|
||||
ResourceKey<? extends Registry<T>> resourceKey,
|
||||
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
|
||||
) {
|
||||
try {
|
||||
BOOTSTRAP_LOCK.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
registryBuilder.add(resourceKey, (ctx) -> {
|
||||
registryBootstrap.run(ctx);
|
||||
BOOTSTRAP_LOCK.release();
|
||||
});
|
||||
}
|
||||
|
||||
public <T extends DataProvider> void addProviderWithLock(
|
||||
FabricDataGenerator.Pack pack,
|
||||
FabricDataGenerator.Pack.RegistryDependentFactory<T> factory
|
||||
) {
|
||||
try {
|
||||
BOOTSTRAP_LOCK.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
pack.addProvider((output, future) -> {
|
||||
final T res = factory.create(output, future);
|
||||
BOOTSTRAP_LOCK.release();
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
public <T extends DataProvider> void addProviderWithLock(
|
||||
FabricDataGenerator.Pack pack,
|
||||
FabricDataGenerator.Pack.Factory<T> factory
|
||||
) {
|
||||
try {
|
||||
BOOTSTRAP_LOCK.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
pack.addProvider((output, future) -> {
|
||||
final T res = factory.create(output);
|
||||
BOOTSTRAP_LOCK.release();
|
||||
return res;
|
||||
});
|
||||
}
|
||||
|
||||
public class InfoList extends LinkedList<RegistrySupplier.RegistryInfo<?>> {
|
||||
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
|
||||
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec));
|
||||
|
|
|
@ -25,17 +25,17 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
|
|||
if (BCLib.ADD_TEST_DATA) {
|
||||
TestBiomes.ensureStaticallyLoaded();
|
||||
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, TestWorldgenProvider::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, TestBiomes::new);
|
||||
pack.addProvider(TestWorldgenProvider::new);
|
||||
pack.addProvider(TestBiomes::new);
|
||||
RecipeDataProvider.createTestRecipes();
|
||||
} else {
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, NullscapeBiomes::new);
|
||||
pack.addProvider(NullscapeBiomes::new);
|
||||
}
|
||||
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, RecipeDataProvider::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, WorldPresetDataProvider::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, BCLibRegistriesDataProvider::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, BCLAdvancementDataProvider::new);
|
||||
pack.addProvider(RecipeDataProvider::new);
|
||||
pack.addProvider(WorldPresetDataProvider::new);
|
||||
pack.addProvider(BCLibRegistriesDataProvider::new);
|
||||
pack.addProvider(BCLAdvancementDataProvider::new);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue