More locking Options
This commit is contained in:
parent
13e56d0a97
commit
4bb3512433
2 changed files with 42 additions and 7 deletions
|
@ -7,10 +7,13 @@ 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;
|
||||
|
@ -74,6 +77,38 @@ public abstract class RegistrySupplier {
|
|||
});
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
pack.addProvider(TestWorldgenProvider::new);
|
||||
pack.addProvider(TestBiomes::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, TestWorldgenProvider::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, TestBiomes::new);
|
||||
RecipeDataProvider.createTestRecipes();
|
||||
} else {
|
||||
pack.addProvider(NullscapeBiomes::new);
|
||||
BCLRegistrySupplier.INSTANCE.addProviderWithLock(pack, NullscapeBiomes::new);
|
||||
}
|
||||
|
||||
pack.addProvider(RecipeDataProvider::new);
|
||||
pack.addProvider(WorldPresetDataProvider::new);
|
||||
pack.addProvider(BCLibRegistriesDataProvider::new);
|
||||
pack.addProvider(BCLAdvancementDataProvider::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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue