Moved WorldPreset creating to DataGen step
This commit is contained in:
parent
ad0a82c2f0
commit
a592c05b4d
26 changed files with 452 additions and 431 deletions
|
@ -1,5 +0,0 @@
|
|||
package org.betterx.worlds.together.entrypoints;
|
||||
|
||||
public interface WorldPresetBootstrap extends WorldsTogetherEntrypoint {
|
||||
void bootstrapWorldPresets();
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package org.betterx.worlds.together.levelgen;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
|
||||
import org.betterx.worlds.together.biomesource.ReloadableBiomeSource;
|
||||
|
@ -100,15 +101,18 @@ public class WorldGenUtil {
|
|||
|
||||
public static class Context extends StemContext {
|
||||
public final HolderGetter<Biome> biomes;
|
||||
public final HolderGetter<BCLBiome> bclBiomes;
|
||||
|
||||
public Context(
|
||||
HolderGetter<Biome> biomes,
|
||||
HolderGetter<BCLBiome> bclBiomes,
|
||||
Holder<DimensionType> dimension,
|
||||
HolderGetter<StructureSet> structureSets,
|
||||
Holder<NoiseGeneratorSettings> generatorSettings
|
||||
) {
|
||||
super(dimension, structureSets, generatorSettings);
|
||||
this.biomes = biomes;
|
||||
this.bclBiomes = bclBiomes;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ import java.util.function.Function;
|
|||
|
||||
@Mixin(WorldPreset.class)
|
||||
public class WorldPresetMixin {
|
||||
|
||||
|
||||
@ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lcom/mojang/serialization/codecs/RecordCodecBuilder;create(Ljava/util/function/Function;)Lcom/mojang/serialization/Codec;"))
|
||||
private static Function<RecordCodecBuilder.Instance<WorldPreset>, ? extends App<RecordCodecBuilder.Mu<WorldPreset>, WorldPreset>> foo(
|
||||
Function<RecordCodecBuilder.Instance<WorldPreset>, ? extends App<RecordCodecBuilder.Mu<WorldPreset>, WorldPreset>> builder
|
||||
|
|
|
@ -1,97 +0,0 @@
|
|||
package org.betterx.worlds.together.mixin.common;
|
||||
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
import net.minecraft.data.worldgen.BootstapContext;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
@Mixin(net.minecraft.world.level.levelgen.presets.WorldPresets.Bootstrap.class)
|
||||
public abstract class WorldPresetsBootstrapMixin {
|
||||
@Shadow
|
||||
@Final
|
||||
private HolderGetter<Biome> biomes;
|
||||
@Shadow
|
||||
@Final
|
||||
private HolderGetter<StructureSet> structureSets;
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private BootstapContext<WorldPreset> context;
|
||||
@Shadow
|
||||
@Final
|
||||
private HolderGetter<PlacedFeature> placedFeatures;
|
||||
@Shadow
|
||||
@Final
|
||||
private LevelStem netherStem;
|
||||
@Shadow
|
||||
@Final
|
||||
private LevelStem endStem;
|
||||
//see WorldPresets.register
|
||||
|
||||
@Shadow
|
||||
protected abstract LevelStem makeNoiseBasedOverworld(
|
||||
BiomeSource biomeSource,
|
||||
Holder<NoiseGeneratorSettings> holder
|
||||
);
|
||||
|
||||
@Shadow
|
||||
@Final
|
||||
private HolderGetter<NoiseGeneratorSettings> noiseSettings;
|
||||
|
||||
@ModifyArg(method = "run", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/world/level/levelgen/presets/WorldPresets$Bootstrap;registerCustomOverworldPreset(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/world/level/dimension/LevelStem;)V"))
|
||||
private LevelStem bcl_getOverworldStem(LevelStem overworldStem) {
|
||||
Holder<NoiseGeneratorSettings> netherSettings, endSettings;
|
||||
if (this.netherStem.generator() instanceof NoiseBasedChunkGenerator nether) {
|
||||
netherSettings = nether.generatorSettings();
|
||||
} else {
|
||||
netherSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.NETHER);
|
||||
}
|
||||
|
||||
if (this.endStem.generator() instanceof NoiseBasedChunkGenerator nether) {
|
||||
endSettings = nether.generatorSettings();
|
||||
} else {
|
||||
endSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.END);
|
||||
}
|
||||
|
||||
WorldGenUtil.Context netherContext = new WorldGenUtil.Context(
|
||||
this.biomes,
|
||||
this.netherStem.type(),
|
||||
this.structureSets,
|
||||
netherSettings
|
||||
);
|
||||
WorldGenUtil.Context endContext = new WorldGenUtil.Context(
|
||||
this.biomes,
|
||||
this.endStem.type(),
|
||||
this.structureSets,
|
||||
endSettings
|
||||
);
|
||||
|
||||
WorldPresets.bootstrapPresets(
|
||||
context,
|
||||
overworldStem,
|
||||
netherContext,
|
||||
endContext,
|
||||
noiseSettings,
|
||||
this::makeNoiseBasedOverworld
|
||||
);
|
||||
|
||||
return overworldStem;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,12 +1,8 @@
|
|||
package org.betterx.worlds.together.worldPreset;
|
||||
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.entrypoints.EntrypointUtil;
|
||||
import org.betterx.worlds.together.entrypoints.WorldPresetBootstrap;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.worlds.together.levelgen.WorldGenUtil;
|
||||
import org.betterx.worlds.together.tag.v3.TagManager;
|
||||
import org.betterx.worlds.together.tag.v3.TagRegistry;
|
||||
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
|
||||
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.HolderGetter;
|
||||
|
@ -15,28 +11,23 @@ import net.minecraft.core.registries.Registries;
|
|||
import net.minecraft.data.worldgen.BootstapContext;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.WorldPresetTags;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.BiomeSource;
|
||||
import net.minecraft.world.level.biome.MultiNoiseBiomeSource;
|
||||
import net.minecraft.world.level.biome.TheEndBiomeSource;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.dimension.BuiltinDimensionTypes;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.NoiseBasedChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureSet;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.Map;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class WorldPresets {
|
||||
@FunctionalInterface
|
||||
public interface OverworldBuilder {
|
||||
LevelStem make(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> noiseGeneratorSettings);
|
||||
}
|
||||
|
||||
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
|
||||
|
||||
public static final TagRegistry.UnTyped<WorldPreset> WORLD_PRESETS =
|
||||
TagManager.registerType(Registries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
|
||||
private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
|
||||
|
||||
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
|
||||
|
@ -45,28 +36,6 @@ public class WorldPresets {
|
|||
.getHolderOrThrow(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a custom WorldPreset (with custom rules and behaviour)
|
||||
* <p>
|
||||
* See also {@link WorldPresetsClient} if you need to add a Customize Button/Screen
|
||||
* for your preset
|
||||
*
|
||||
* @param loc The ID of your Preset
|
||||
* @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(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;
|
||||
}
|
||||
WORLD_PRESETS.addUntyped(WorldPresetTags.NORMAL, key.location());
|
||||
}
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
public static void ensureStaticallyLoaded() {
|
||||
|
||||
}
|
||||
|
@ -75,68 +44,99 @@ public class WorldPresets {
|
|||
return ResourceKey.create(Registries.WORLD_PRESET, loc);
|
||||
}
|
||||
|
||||
public static ResourceKey<WorldPreset> register(
|
||||
ResourceKey<WorldPreset> loc,
|
||||
PresetBuilder builder,
|
||||
boolean visibleInUI
|
||||
) {
|
||||
ResourceKey<WorldPreset> key = register(loc, visibleInUI);
|
||||
|
||||
if (BUILDERS == null) {
|
||||
WorldsTogether.LOGGER.error("Unable to register WorldPreset '" + loc + "'.");
|
||||
|
||||
} else {
|
||||
BUILDERS.put(key, builder);
|
||||
}
|
||||
return key;
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void bootstrapPresets(
|
||||
BootstapContext<WorldPreset> bootstrapContext,
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext,
|
||||
HolderGetter<NoiseGeneratorSettings> noiseSettings,
|
||||
OverworldBuilder noiseBasedOverworld
|
||||
) {
|
||||
if (BUILDERS == null)
|
||||
return;
|
||||
EntrypointUtil.getCommon(WorldPresetBootstrap.class)
|
||||
.forEach(e -> e.bootstrapWorldPresets());
|
||||
|
||||
for (Map.Entry<ResourceKey<WorldPreset>, PresetBuilder> e : BUILDERS.entrySet()) {
|
||||
TogetherWorldPreset preset = e.getValue()
|
||||
.create(
|
||||
overworldStem, netherContext, endContext,
|
||||
noiseSettings, noiseBasedOverworld
|
||||
);
|
||||
bootstrapContext.register(e.getKey(), preset);
|
||||
}
|
||||
BUILDERS = null;
|
||||
}
|
||||
|
||||
public static ResourceKey<WorldPreset> getDEFAULT() {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
private static boolean didExplicitlySetDefault = false;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void setDEFAULT(ResourceKey<WorldPreset> DEFAULT) {
|
||||
didExplicitlySetDefault = true;
|
||||
WorldPresets.DEFAULT = DEFAULT;
|
||||
}
|
||||
|
||||
public static class BootstrapData {
|
||||
public final HolderGetter<NoiseGeneratorSettings> noiseSettings;
|
||||
public final HolderGetter<Biome> biomes;
|
||||
public final HolderGetter<PlacedFeature> placedFeatures;
|
||||
public final HolderGetter<StructureSet> structureSets;
|
||||
public final LevelStem netherStem;
|
||||
public final LevelStem endStem;
|
||||
public final LevelStem overworldStem;
|
||||
public final Holder<DimensionType> netherDimensionType;
|
||||
public final Holder<DimensionType> endDimensionType;
|
||||
public final Holder<DimensionType> overworldDimensionType;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface PresetBuilder {
|
||||
TogetherWorldPreset create(
|
||||
LevelStem overworldStem,
|
||||
WorldGenUtil.Context netherContext,
|
||||
WorldGenUtil.Context endContext,
|
||||
HolderGetter<NoiseGeneratorSettings> noiseSettings,
|
||||
OverworldBuilder noiseBasedOverworld
|
||||
);
|
||||
public final WorldGenUtil.Context netherContext;
|
||||
public final WorldGenUtil.Context endContext;
|
||||
|
||||
public BootstrapData(BootstapContext<WorldPreset> bootstapContext) {
|
||||
final HolderGetter<DimensionType> dimensionTypes = bootstapContext.lookup(Registries.DIMENSION_TYPE);
|
||||
|
||||
this.noiseSettings = bootstapContext.lookup(Registries.NOISE_SETTINGS);
|
||||
this.biomes = bootstapContext.lookup(Registries.BIOME);
|
||||
this.placedFeatures = bootstapContext.lookup(Registries.PLACED_FEATURE);
|
||||
this.structureSets = bootstapContext.lookup(Registries.STRUCTURE_SET);
|
||||
|
||||
this.overworldDimensionType = dimensionTypes.getOrThrow(BuiltinDimensionTypes.OVERWORLD);
|
||||
MultiNoiseBiomeSource overworldBiomeSource = MultiNoiseBiomeSource.Preset.OVERWORLD.biomeSource(this.biomes);
|
||||
Holder<NoiseGeneratorSettings> defaultOverworldNoise = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.OVERWORLD);
|
||||
this.overworldStem = makeNoiseBasedOverworld(overworldBiomeSource, defaultOverworldNoise);
|
||||
|
||||
this.netherDimensionType = dimensionTypes.getOrThrow(BuiltinDimensionTypes.NETHER);
|
||||
Holder<NoiseGeneratorSettings> defaultNetherNoise = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.NETHER);
|
||||
this.netherStem = new LevelStem(
|
||||
netherDimensionType,
|
||||
new NoiseBasedChunkGenerator(
|
||||
MultiNoiseBiomeSource.Preset.NETHER.biomeSource(this.biomes),
|
||||
defaultNetherNoise
|
||||
)
|
||||
);
|
||||
|
||||
this.endDimensionType = dimensionTypes.getOrThrow(BuiltinDimensionTypes.END);
|
||||
Holder<NoiseGeneratorSettings> defaultEndNoise = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.END);
|
||||
this.endStem = new LevelStem(
|
||||
endDimensionType,
|
||||
new NoiseBasedChunkGenerator(TheEndBiomeSource.create(this.biomes), defaultEndNoise)
|
||||
);
|
||||
|
||||
|
||||
Holder<NoiseGeneratorSettings> netherSettings, endSettings;
|
||||
if (this.netherStem.generator() instanceof NoiseBasedChunkGenerator nether) {
|
||||
netherSettings = nether.generatorSettings();
|
||||
} else {
|
||||
netherSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.NETHER);
|
||||
}
|
||||
|
||||
if (this.endStem.generator() instanceof NoiseBasedChunkGenerator nether) {
|
||||
endSettings = nether.generatorSettings();
|
||||
} else {
|
||||
endSettings = this.noiseSettings.getOrThrow(NoiseGeneratorSettings.END);
|
||||
}
|
||||
|
||||
HolderGetter<BCLBiome> bclBiomes = bootstapContext.lookup(BCLBiomeRegistry.BCL_BIOMES_REGISTRY);
|
||||
this.netherContext = new WorldGenUtil.Context(
|
||||
this.biomes,
|
||||
bclBiomes,
|
||||
this.netherStem.type(),
|
||||
this.structureSets,
|
||||
netherSettings
|
||||
);
|
||||
|
||||
this.endContext = new WorldGenUtil.Context(
|
||||
this.biomes,
|
||||
bclBiomes,
|
||||
this.endStem.type(),
|
||||
this.structureSets,
|
||||
endSettings
|
||||
);
|
||||
}
|
||||
|
||||
private LevelStem makeOverworld(ChunkGenerator chunkGenerator) {
|
||||
return new LevelStem(this.overworldDimensionType, chunkGenerator);
|
||||
}
|
||||
|
||||
public LevelStem makeNoiseBasedOverworld(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> holder) {
|
||||
return this.makeOverworld(new NoiseBasedChunkGenerator(biomeSource, holder));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.Optional;
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue