Added more Registries to DataGen pass
This commit is contained in:
parent
2aa445d9e0
commit
b322453889
9 changed files with 102 additions and 202 deletions
|
@ -68,7 +68,7 @@ public class BCLChunkGenerator extends NoiseBasedChunkGenerator implements Resto
|
|||
) {
|
||||
super(biomeSource, holder);
|
||||
initialBiomeSource = biomeSource;
|
||||
if (biomeSource instanceof BiomeSourceWithNoiseRelatedSettings bcl) {
|
||||
if (biomeSource instanceof BiomeSourceWithNoiseRelatedSettings bcl && holder.isBound()) {
|
||||
bcl.onLoadGeneratorSettings(holder.value());
|
||||
}
|
||||
|
||||
|
|
|
@ -16,18 +16,23 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
|
|||
BCLib.LOGGER.info("Bootstrap onInitializeDataGenerator");
|
||||
final FabricDataGenerator.Pack pack = dataGenerator.createPack();
|
||||
|
||||
if (ADD_TESTS) {
|
||||
pack.addProvider(TestWorldgenProvider::new);
|
||||
}
|
||||
pack.addProvider(WorldgenProvider::new);
|
||||
//pack.addProvider(BiomeProvider::new);
|
||||
//pack.addProvider(new BiomeProvider());
|
||||
// pack.addProvider(CustomRegistriesDataProvider::new);
|
||||
//pack.addProvider(CustomRegistriesDataProvider::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildRegistry(RegistrySetBuilder registryBuilder) {
|
||||
BCLib.LOGGER.info("Datagen buildRegistry");
|
||||
if (ADD_TESTS) {
|
||||
registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap);
|
||||
registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap);
|
||||
registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
|
||||
}
|
||||
registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,137 +0,0 @@
|
|||
package org.betterx.bclib.datagen;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
|
||||
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.Encoder;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.registries.VanillaRegistries;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.Structure;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CustomRegistriesDataProvider implements DataProvider {
|
||||
public static final List<RegistryDataLoader.RegistryData<?>> REGISTRIES = List.of(
|
||||
new RegistryDataLoader.RegistryData<>(BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC),
|
||||
new RegistryDataLoader.RegistryData<>(
|
||||
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
|
||||
AssignedSurfaceRule.CODEC
|
||||
),
|
||||
new RegistryDataLoader.RegistryData<>(Registries.BIOME, Biome.DIRECT_CODEC),
|
||||
new RegistryDataLoader.RegistryData<>(Registries.CONFIGURED_FEATURE, ConfiguredFeature.DIRECT_CODEC),
|
||||
new RegistryDataLoader.RegistryData<>(Registries.PLACED_FEATURE, PlacedFeature.DIRECT_CODEC),
|
||||
new RegistryDataLoader.RegistryData<>(Registries.STRUCTURE, Structure.DIRECT_CODEC)
|
||||
);
|
||||
|
||||
|
||||
private final PackOutput output;
|
||||
|
||||
public CustomRegistriesDataProvider(FabricDataOutput generator) {
|
||||
this.output = generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cachedOutput) {
|
||||
HolderLookup.Provider registryAccess = VanillaRegistries.createLookup();
|
||||
RegistryOps<JsonElement> dynamicOps = RegistryOps.create(JsonOps.INSTANCE, registryAccess);
|
||||
final List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
|
||||
for (RegistryDataLoader.RegistryData<?> registryData : REGISTRIES) {
|
||||
futures.add(this.dumpRegistryCapFuture(
|
||||
cachedOutput,
|
||||
registryAccess,
|
||||
dynamicOps,
|
||||
(RegistryDataLoader.RegistryData) registryData
|
||||
));
|
||||
}
|
||||
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
private <T> CompletableFuture dumpRegistryCapFuture(
|
||||
CachedOutput cachedOutput,
|
||||
HolderLookup.Provider registryAccess,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
RegistryDataLoader.RegistryData<T> registryData
|
||||
) {
|
||||
return CompletableFuture.runAsync(() -> dumpRegistryCap(
|
||||
cachedOutput,
|
||||
registryAccess,
|
||||
dynamicOps,
|
||||
registryData
|
||||
));
|
||||
}
|
||||
|
||||
private <T> void dumpRegistryCap(
|
||||
CachedOutput cachedOutput,
|
||||
HolderLookup.Provider registryAccess,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
RegistryDataLoader.RegistryData<T> registryData
|
||||
) {
|
||||
ResourceKey<? extends Registry<T>> resourceKey = registryData.key();
|
||||
|
||||
HolderLookup.RegistryLookup<T> registry = registryAccess.lookupOrThrow(resourceKey);
|
||||
PackOutput.PathProvider pathProvider = this.output.createPathProvider(
|
||||
PackOutput.Target.DATA_PACK,
|
||||
resourceKey.location().getPath()
|
||||
);
|
||||
registry.listElementIds().forEach(entry ->
|
||||
dumpValue(
|
||||
pathProvider.json(entry.location()),
|
||||
cachedOutput,
|
||||
dynamicOps,
|
||||
registryData.elementCodec(),
|
||||
registry.get(entry).orElseThrow().value()
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static <E> void dumpValue(
|
||||
Path path,
|
||||
CachedOutput cachedOutput,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
Encoder<E> encoder,
|
||||
E object
|
||||
) {
|
||||
|
||||
Optional<JsonElement> optional = encoder.encodeStart(dynamicOps, object)
|
||||
.resultOrPartial(string -> WorldsTogether.LOGGER.error(
|
||||
"Couldn't serialize element {}: {}",
|
||||
path,
|
||||
string
|
||||
));
|
||||
if (optional.isPresent()) {
|
||||
DataProvider.saveStable(cachedOutput, optional.get(), path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BCL Registries";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package org.betterx.bclib.datagen;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TestWorldgenProvider extends FabricDynamicRegistryProvider {
|
||||
public TestWorldgenProvider(
|
||||
FabricDataOutput output,
|
||||
CompletableFuture<HolderLookup.Provider> registriesFuture
|
||||
) {
|
||||
super(output, registriesFuture);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HolderLookup.Provider registries, Entries entries) {
|
||||
if (BCLibDatagen.ADD_TESTS) {
|
||||
entries.addAll(registries.lookupOrThrow(Registries.CONFIGURED_FEATURE));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.PLACED_FEATURE));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.BIOME));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Test WorldGen Provider";
|
||||
}
|
||||
}
|
|
@ -1,5 +1,8 @@
|
|||
package org.betterx.bclib.datagen;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
|
||||
|
@ -18,14 +21,14 @@ public class WorldgenProvider extends FabricDynamicRegistryProvider {
|
|||
|
||||
@Override
|
||||
protected void configure(HolderLookup.Provider registries, Entries entries) {
|
||||
entries.addAll(registries.lookupOrThrow(Registries.CONFIGURED_FEATURE));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.PLACED_FEATURE));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.BIOME));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.NOISE_SETTINGS));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.WORLD_PRESET));
|
||||
entries.addAll(registries.lookupOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY));
|
||||
entries.addAll(registries.lookupOrThrow(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "007 - BCLib Feature Provider";
|
||||
return "WorldGen Provider";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,15 +21,14 @@ import java.util.Map;
|
|||
|
||||
public class PresetsRegistry implements WorldPresetBootstrap {
|
||||
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD;
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_LARGE;
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_AMPLIFIED;
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_17;
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD = WorldPresets.createKey(BCLib.makeID("normal"));
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_LARGE = WorldPresets.createKey(BCLib.makeID("large"));
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_AMPLIFIED = WorldPresets.createKey(BCLib.makeID("amplified"));
|
||||
public static ResourceKey<WorldPreset> BCL_WORLD_17 = WorldPresets.createKey(BCLib.makeID("legacy_17"));
|
||||
|
||||
public void bootstrapWorldPresets() {
|
||||
BCL_WORLD =
|
||||
WorldPresets.register(
|
||||
BCLib.makeID("normal"),
|
||||
BCL_WORLD,
|
||||
(overworldStem, netherContext, endContext, noiseSettings, noiseBasedOverworld) ->
|
||||
buildPreset(
|
||||
overworldStem,
|
||||
|
@ -39,9 +38,8 @@ public class PresetsRegistry implements WorldPresetBootstrap {
|
|||
true
|
||||
);
|
||||
|
||||
BCL_WORLD_LARGE =
|
||||
WorldPresets.register(
|
||||
BCLib.makeID("large"),
|
||||
BCL_WORLD_LARGE,
|
||||
(overworldStem, netherContext, endContext, noiseSettings, noiseBasedOverworld) -> {
|
||||
Holder<NoiseGeneratorSettings> largeBiomeGenerator = noiseSettings
|
||||
.getOrThrow(NoiseGeneratorSettings.LARGE_BIOMES);
|
||||
|
@ -57,8 +55,8 @@ public class PresetsRegistry implements WorldPresetBootstrap {
|
|||
true
|
||||
);
|
||||
|
||||
BCL_WORLD_AMPLIFIED = WorldPresets.register(
|
||||
BCLib.makeID("amplified"),
|
||||
WorldPresets.register(
|
||||
BCL_WORLD_AMPLIFIED,
|
||||
(overworldStem, netherContext, endContext, noiseSettings, noiseBasedOverworld) -> {
|
||||
Holder<NoiseGeneratorSettings> amplifiedBiomeGenerator = noiseSettings
|
||||
.getOrThrow(NoiseGeneratorSettings.AMPLIFIED);
|
||||
|
@ -82,8 +80,8 @@ public class PresetsRegistry implements WorldPresetBootstrap {
|
|||
true
|
||||
);
|
||||
|
||||
BCL_WORLD_17 = WorldPresets.register(
|
||||
BCLib.makeID("legacy_17"),
|
||||
WorldPresets.register(
|
||||
BCL_WORLD_17,
|
||||
(overworldStem, netherContext, endContext, noiseSettings, noiseBasedOverworld) ->
|
||||
buildPreset(
|
||||
overworldStem,
|
||||
|
|
|
@ -9,22 +9,16 @@ import net.fabricmc.api.Environment;
|
|||
@Environment(EnvType.CLIENT)
|
||||
public class PresetsRegistryClient {
|
||||
public static void onLoad() {
|
||||
WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, (createWorldScreen, worldCreationContext) -> {
|
||||
return new WorldSetupScreen(createWorldScreen, worldCreationContext);
|
||||
});
|
||||
WorldPresetsClient.registerCustomizeUI(PresetsRegistry.BCL_WORLD, WorldSetupScreen::new);
|
||||
|
||||
WorldPresetsClient.registerCustomizeUI(
|
||||
PresetsRegistry.BCL_WORLD_LARGE,
|
||||
(createWorldScreen, worldCreationContext) -> {
|
||||
return new WorldSetupScreen(createWorldScreen, worldCreationContext);
|
||||
}
|
||||
WorldSetupScreen::new
|
||||
);
|
||||
|
||||
WorldPresetsClient.registerCustomizeUI(
|
||||
PresetsRegistry.BCL_WORLD_AMPLIFIED,
|
||||
(createWorldScreen, worldCreationContext) -> {
|
||||
return new WorldSetupScreen(createWorldScreen, worldCreationContext);
|
||||
}
|
||||
WorldSetupScreen::new
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,8 +53,8 @@ public class WorldPresets {
|
|||
* @param visibleInUI if true, the preset will show up in the UI on world creataion
|
||||
* @return The key you may use to reference your new Preset
|
||||
*/
|
||||
private static ResourceKey<WorldPreset> register(ResourceLocation loc, boolean visibleInUI) {
|
||||
ResourceKey<WorldPreset> key = ResourceKey.create(Registries.WORLD_PRESET, loc);
|
||||
private static ResourceKey<WorldPreset> register(ResourceKey<WorldPreset> key, boolean visibleInUI) {
|
||||
//ResourceKey<WorldPreset> key = ResourceKey.create(Registries.WORLD_PRESET, loc);
|
||||
if (visibleInUI) {
|
||||
if (!didExplicitlySetDefault && DEFAULT == net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL) {
|
||||
DEFAULT = key;
|
||||
|
@ -69,8 +69,12 @@ public class WorldPresets {
|
|||
|
||||
}
|
||||
|
||||
public static ResourceKey<WorldPreset> createKey(ResourceLocation loc) {
|
||||
return ResourceKey.create(Registries.WORLD_PRESET, loc);
|
||||
}
|
||||
|
||||
public static ResourceKey<WorldPreset> register(
|
||||
ResourceLocation loc,
|
||||
ResourceKey<WorldPreset> loc,
|
||||
PresetBuilder builder,
|
||||
boolean visibleInUI
|
||||
) {
|
||||
|
@ -98,13 +102,12 @@ public class WorldPresets {
|
|||
.forEach(e -> e.bootstrapWorldPresets());
|
||||
|
||||
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
|
||||
//TODO:1.19.3 called out of sync
|
||||
// TogetherWorldPreset preset = e.getValue()
|
||||
// .create(
|
||||
// overworldStem, netherContext, endContext,
|
||||
// noiseSettings, noiseBasedOverworld
|
||||
// );
|
||||
// bootstrapContext.register(e.getKey(), preset);
|
||||
TogetherWorldPreset preset = e.getValue()
|
||||
.create(
|
||||
overworldStem, netherContext, endContext,
|
||||
noiseSettings, noiseBasedOverworld
|
||||
);
|
||||
bootstrapContext.register(e.getKey(), preset);
|
||||
}
|
||||
BUILDERS = null;
|
||||
}
|
||||
|
|
|
@ -7,12 +7,14 @@ import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
|||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class WorldPresetsClient {
|
||||
public static void registerCustomizeUI(ResourceKey<WorldPreset> key, PresetEditor setupScreen) {
|
||||
if (setupScreen != null) {
|
||||
//TODO: 1.19.3 this is called out of order
|
||||
//PresetEditor.EDITORS.put(Optional.of(key), setupScreen);
|
||||
PresetEditor.EDITORS.put(Optional.of(key), setupScreen);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue