[Changes] Adapted BCLBiomeBuilder for DataGen pass

This commit is contained in:
Frank 2022-11-30 19:43:09 +01:00
parent 271c974929
commit 2aa445d9e0
8 changed files with 173 additions and 209 deletions

View file

@ -145,7 +145,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
} }
final BCLBiome bclBiome; final BCLBiome bclBiome;
if (!BiomeAPI.hasBiome(biomeID)) { if (!BiomeAPI.hasBiome(biomeID)) {
bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.END_LAND); bclBiome = new BCLBiome(biomeID, BiomeAPI.BiomeType.END_LAND);
InternalBiomeAPI.registerBCLBiomeData(bclBiome); InternalBiomeAPI.registerBCLBiomeData(bclBiome);
} else { } else {
bclBiome = BiomeAPI.getBiome(biomeID); bclBiome = BiomeAPI.getBiome(biomeID);

View file

@ -108,7 +108,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc
return; return;
} }
if (!BiomeAPI.hasBiome(biomeID)) { if (!BiomeAPI.hasBiome(biomeID)) {
BCLBiome bclBiome = new BCLBiome(biomeID, biome.value(), BiomeAPI.BiomeType.NETHER); BCLBiome bclBiome = new BCLBiome(biomeID, BiomeAPI.BiomeType.NETHER);
InternalBiomeAPI.registerBCLBiomeData(bclBiome); InternalBiomeAPI.registerBCLBiomeData(bclBiome);
biomePicker.addBiome(bclBiome); biomePicker.addBiome(bclBiome);
} else { } else {

View file

@ -153,7 +153,6 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
private final Map<String, Object> customData = Maps.newHashMap(); private final Map<String, Object> customData = Maps.newHashMap();
private final ResourceLocation biomeID; private final ResourceLocation biomeID;
private final ResourceKey<Biome> biomeKey; private final ResourceKey<Biome> biomeKey;
final Biome biomeToRegister;
protected final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList(); protected final List<Climate.ParameterPoint> parameterPoints = Lists.newArrayList();
@ -174,7 +173,6 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
Optional<String> intendedType Optional<String> intendedType
) { ) {
super(terrainHeight, fogDensity, genChance, edgeSize, vertical, edge.map(BiomeAPI::getBiome).orElse(null)); super(terrainHeight, fogDensity, genChance, edgeSize, vertical, edge.map(BiomeAPI::getBiome).orElse(null));
biomeToRegister = null;
this.biomeID = biomeID; this.biomeID = biomeID;
this.biomeKey = ResourceKey.create(Registries.BIOME, biomeID); this.biomeKey = ResourceKey.create(Registries.BIOME, biomeID);
this.biomeParent = biomeParent.orElse(null); this.biomeParent = biomeParent.orElse(null);
@ -200,42 +198,17 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
this(ResourceKey.create(Registries.BIOME, biomeID), null); this(ResourceKey.create(Registries.BIOME, biomeID), null);
} }
/** /**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}. * Create wrapper for existing biome.
* *
* @param biomeToRegister {@link Biome} to wrap. * @param biomeID Teh ResoureLocation for this Biome
* @param settings The Settings for this Biome or {@code null} if you want to apply default settings
*/ */
@ApiStatus.Internal @ApiStatus.Internal
BCLBiome(Biome biomeToRegister, VanillaBiomeSettings settings) { public BCLBiome(ResourceLocation biomeID, BiomeAPI.BiomeType type) {
this(BiomeAPI.getBiomeID(biomeToRegister), biomeToRegister, settings); this(ResourceKey.create(Registries.BIOME, biomeID), (BCLBiomeSettings) null);
}
/**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
*
* @param biomeToRegister {@link Biome} to wrap.
* @param biomeID Teh ResoureLocation for this Biome
*/
@ApiStatus.Internal
public BCLBiome(ResourceLocation biomeID, Biome biomeToRegister, BiomeAPI.BiomeType type) {
this(biomeID, biomeToRegister, (BCLBiomeSettings) null);
setIntendedType(type); setIntendedType(type);
} }
/**
* Create a new Biome
*
* @param biomeID {@link ResourceLocation} biome ID.
* @param biomeToRegister {@link Biome} to wrap.
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceLocation biomeID, Biome biomeToRegister, BCLBiomeSettings defaults) {
this(ResourceKey.create(Registries.BIOME, biomeID), biomeToRegister, defaults);
}
/** /**
* Create a new Biome * Create a new Biome
* *
@ -243,18 +216,6 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
* @param defaults The Settings for this Biome or null if you want to apply the defaults * @param defaults The Settings for this Biome or null if you want to apply the defaults
*/ */
protected BCLBiome(ResourceKey<Biome> biomeKey, BCLBiomeSettings defaults) { protected BCLBiome(ResourceKey<Biome> biomeKey, BCLBiomeSettings defaults) {
this(biomeKey, null, defaults);
}
/**
* Create a new Biome
*
* @param biomeKey {@link ResourceKey<Biome>} of the wrapped Biome
* @param biomeToRegister The biome you want to use when this instance gets registered through the {@link BiomeAPI}
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
protected BCLBiome(ResourceKey<Biome> biomeKey, Biome biomeToRegister, BCLBiomeSettings defaults) {
this.biomeToRegister = biomeToRegister;
this.biomeID = biomeKey.location(); this.biomeID = biomeKey.location();
this.biomeKey = biomeKey; this.biomeKey = biomeKey;
@ -354,15 +315,6 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
return subbiomes; return subbiomes;
} }
/**
* Getter for a random sub-biome from all existing sub-biomes. Will return biome itself if there are no sub-biomes.
*
* @param random {@link Random}.
* @return {@link BCLBiome}.
*/
// public BCLBiome getSubBiome(WorldgenRandom random) {
// return getSubBiomes().get(random);
// }
public void forEachSubBiome(BiConsumer<BCLBiome, Float> consumer) { public void forEachSubBiome(BiConsumer<BCLBiome, Float> consumer) {
final WeightedList<BCLBiome> subbiomes = getSubBiomes(); final WeightedList<BCLBiome> subbiomes = getSubBiomes();
for (int i = 0; i < subbiomes.size(); i++) for (int i = 0; i < subbiomes.size(); i++)
@ -477,4 +429,22 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData {
boolean allowFabricRegistration() { boolean allowFabricRegistration() {
return !isEdgeBiome(); return !isEdgeBiome();
} }
@ApiStatus.Internal
private Biome biomeToRegister;
@ApiStatus.Internal
void _setBiomeToRegister(Biome b) {
this.biomeToRegister = b;
}
@ApiStatus.Internal
Biome _getBiomeToRegister() {
return this.biomeToRegister;
}
@ApiStatus.Internal
boolean _hasBiomeToRegister() {
return this.biomeToRegister != null;
}
} }

View file

@ -7,7 +7,6 @@ import org.betterx.bclib.entity.BCLEntityWrapper;
import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor; import org.betterx.bclib.mixin.common.BiomeGenerationSettingsAccessor;
import org.betterx.bclib.util.CollectionsUtil; import org.betterx.bclib.util.CollectionsUtil;
import org.betterx.bclib.util.Pair; import org.betterx.bclib.util.Pair;
import org.betterx.bclib.util.TriFunction;
import org.betterx.ui.ColorUtil; import org.betterx.ui.ColorUtil;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry; import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import org.betterx.worlds.together.tag.v3.TagManager; import org.betterx.worlds.together.tag.v3.TagManager;
@ -45,97 +44,89 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import java.util.*; import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function;
public class BCLBiomeBuilder { public class BCLBiomeBuilder {
public record Context(BootstapContext<Biome> bootstrapContext) {
public BCLBiomeBuilder start(ResourceLocation biomeID) {
return BCLBiomeBuilder.start(this, biomeID);
}
}
public static final class PreparedBiome<T extends BCLBiome> { public static class UnregisteredBCLBiome<T extends BCLBiome> extends BCLBiomeContainer<T> {
private final T biome; private final BCLBiome parentBiome;
private final Context context; private final BuildCompletion supplier;
private PreparedBiome(T biome, Context context) { private UnregisteredBCLBiome(T biome, BCLBiome parentBiome, BuildCompletion supplier) {
this.biome = biome; super(biome);
this.context = context; this.parentBiome = parentBiome;
this.supplier = supplier;
} }
public T registerEndLandBiome() {
BiomeAPI.registerEndLandBiome(context.bootstrapContext, biome); @Override
return this.biome; public BCLBiomeContainer<T> register(BootstapContext<Biome> bootstrapContext, BiomeAPI.BiomeType dim) {
if (dim == null) dim = BiomeAPI.BiomeType.NONE;
biome._setBiomeToRegister(this.supplier.apply(bootstrapContext));
if (dim.is(BiomeAPI.BiomeType.END_LAND)) {
BiomeAPI.registerEndLandBiome(bootstrapContext, biome);
} else if (dim.is(BiomeAPI.BiomeType.END_VOID)) {
BiomeAPI.registerEndVoidBiome(bootstrapContext, biome);
} else if (dim.is(BiomeAPI.BiomeType.END_BARRENS)) {
BiomeAPI.registerEndBarrensBiome(bootstrapContext, parentBiome, biome);
} else if (dim.is(BiomeAPI.BiomeType.END_CENTER)) {
BiomeAPI.registerEndCenterBiome(bootstrapContext, biome);
} else if (dim.is(BiomeAPI.BiomeType.NETHER)) {
BiomeAPI.registerNetherBiome(bootstrapContext, biome);
} else if (hasParent()) {
BiomeAPI.registerSubBiome(bootstrapContext, parentBiome, biome, dim);
} else {
BiomeAPI.registerBuiltinBiomeAndOverrideIntendedDimension(bootstrapContext, biome, dim);
}
return new BCLBiomeContainer<>(this.biome);
} }
public T registerEndVoidBiome() { public T biome() {
BiomeAPI.registerEndVoidBiome(context.bootstrapContext, biome);
return this.biome;
}
public T registerEndBarrensBiome(BCLBiome highlandBiome) {
BiomeAPI.registerEndBarrensBiome(context.bootstrapContext, highlandBiome, biome);
return this.biome;
}
public T registerEndCenterBiome() {
BiomeAPI.registerEndCenterBiome(context.bootstrapContext, biome);
return this.biome;
}
public T registerNetherBiome() {
BiomeAPI.registerNetherBiome(context.bootstrapContext, biome);
return this.biome;
}
public T registerSubBiome(BCLBiome parent) {
BiomeAPI.registerSubBiome(context.bootstrapContext, parent, biome);
return this.biome;
}
public T registerSubBiome(BCLBiome parent, BiomeAPI.BiomeType dim) {
BiomeAPI.registerSubBiome(context.bootstrapContext, parent, biome, dim);
return this.biome;
}
public T register(BiomeAPI.BiomeType dim) {
BiomeAPI.registerBuiltinBiomeAndOverrideIntendedDimension(context.bootstrapContext, biome, dim);
return this.biome;
}
public BCLBiome biome() {
return biome; return biome;
} }
public Context context() { public boolean hasParent() {
return context; return parentBiome != null;
}
public BCLBiome parentBiome() {
return parentBiome;
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) return true; if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false; if (obj == null || obj.getClass() != this.getClass()) return false;
PreparedBiome that = (PreparedBiome) obj; UnregisteredBCLBiome<?> that = (UnregisteredBCLBiome<?>) obj;
return Objects.equals(this.biome, that.biome) && return Objects.equals(this.biome, that.biome);
Objects.equals(this.context, that.context);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(biome, context); return Objects.hash(biome);
} }
@Override @Override
public String toString() { public String toString() {
return "Registry[" + return "UnregisteredBiome[" + "biome=" + biome + ']';
"biome=" + biome + ", " +
"context=" + context + ']';
} }
} }
@FunctionalInterface @FunctionalInterface
public interface BiomeSupplier<T> extends TriFunction<ResourceLocation, Biome, BCLBiomeSettings, T> { public interface BiomeSupplier<T> extends BiFunction<ResourceKey<Biome>, BCLBiomeSettings, T> {
}
@FunctionalInterface
private interface FeatureSupplier extends Consumer<BiomeGenerationSettings.Builder> {
}
@FunctionalInterface
private interface BuildCompletion extends Function<BootstapContext<Biome>, Biome> {
} }
@ -145,6 +136,7 @@ public class BCLBiomeBuilder {
-0.012 -0.012
); );
private final List<FeatureSupplier> featureSupliers = new LinkedList<>();
private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>( private final List<Pair<GenerationStep.Carving, Holder<? extends ConfiguredWorldCarver<?>>>> carvers = new ArrayList<>(
1); 1);
private BiomeGenerationSettings.Builder generationSettings; private BiomeGenerationSettings.Builder generationSettings;
@ -153,7 +145,7 @@ public class BCLBiomeBuilder {
private SurfaceRules.RuleSource surfaceRule; private SurfaceRules.RuleSource surfaceRule;
private Precipitation precipitation; private Precipitation precipitation;
private ResourceLocation biomeID; private ResourceLocation biomeID;
private Context builderContext;
private final Set<TagKey<Biome>> tags = Sets.newHashSet(); private final Set<TagKey<Biome>> tags = Sets.newHashSet();
@ -166,6 +158,7 @@ public class BCLBiomeBuilder {
private float height; private float height;
private int edgeSize; private int edgeSize;
private BCLBiome edge; private BCLBiome edge;
private BCLBiome parent;
private boolean vertical; private boolean vertical;
private BiomeAPI.BiomeType biomeType; private BiomeAPI.BiomeType biomeType;
@ -177,8 +170,7 @@ public class BCLBiomeBuilder {
* @param biomeID {@link ResourceLocation} biome identifier. * @param biomeID {@link ResourceLocation} biome identifier.
* @return prepared {@link BCLBiomeBuilder} instance. * @return prepared {@link BCLBiomeBuilder} instance.
*/ */
private static BCLBiomeBuilder start( public static BCLBiomeBuilder start(
Context ctx,
ResourceLocation biomeID ResourceLocation biomeID
) { ) {
INSTANCE.biomeID = biomeID; INSTANCE.biomeID = biomeID;
@ -194,11 +186,12 @@ public class BCLBiomeBuilder {
INSTANCE.height = 0.1F; INSTANCE.height = 0.1F;
INSTANCE.vertical = false; INSTANCE.vertical = false;
INSTANCE.edge = null; INSTANCE.edge = null;
INSTANCE.parent = null;
INSTANCE.carvers.clear(); INSTANCE.carvers.clear();
INSTANCE.parameters.clear(); INSTANCE.parameters.clear();
INSTANCE.tags.clear(); INSTANCE.tags.clear();
INSTANCE.biomeType = null; INSTANCE.biomeType = null;
INSTANCE.builderContext = ctx; INSTANCE.featureSupliers.clear();
return INSTANCE; return INSTANCE;
} }
@ -207,6 +200,11 @@ public class BCLBiomeBuilder {
return this; return this;
} }
public BCLBiomeBuilder setParent(BCLBiome parent) {
this.parent = parent;
return this;
}
/** /**
* Set the type for this Biome. If the type was set, the Biome can be registered. * Set the type for this Biome. If the type was set, the Biome can be registered.
* *
@ -612,7 +610,12 @@ public class BCLBiomeBuilder {
* @param soundPositionOffset offset in sound. * @param soundPositionOffset offset in sound.
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder mood(Holder<SoundEvent> mood, int tickDelay, int blockSearchExtent, float soundPositionOffset) { public BCLBiomeBuilder mood(
Holder<SoundEvent> mood,
int tickDelay,
int blockSearchExtent,
float soundPositionOffset
) {
getEffects().ambientMoodSound(new AmbientMoodSettings(mood, tickDelay, blockSearchExtent, soundPositionOffset)); getEffects().ambientMoodSound(new AmbientMoodSettings(mood, tickDelay, blockSearchExtent, soundPositionOffset));
return this; return this;
} }
@ -657,7 +660,7 @@ public class BCLBiomeBuilder {
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder feature(Decoration decoration, Holder<PlacedFeature> feature) { public BCLBiomeBuilder feature(Decoration decoration, Holder<PlacedFeature> feature) {
getGeneration().addFeature(decoration, feature); featureSupliers.add(gen -> gen.addFeature(decoration, feature));
return this; return this;
} }
@ -686,7 +689,7 @@ public class BCLBiomeBuilder {
* @return same {@link BCLBiomeBuilder} instance. * @return same {@link BCLBiomeBuilder} instance.
*/ */
public BCLBiomeBuilder feature(Consumer<BiomeGenerationSettings.Builder> featureAdd) { public BCLBiomeBuilder feature(Consumer<BiomeGenerationSettings.Builder> featureAdd) {
featureAdd.accept(getGeneration()); featureSupliers.add(gen -> featureAdd.accept(gen));
return this; return this;
} }
@ -927,12 +930,12 @@ public class BCLBiomeBuilder {
* *
* @return new or same {@link BiomeGenerationSettings.Builder} instance. * @return new or same {@link BiomeGenerationSettings.Builder} instance.
*/ */
private BiomeGenerationSettings.Builder getGeneration() { private BiomeGenerationSettings.Builder getGeneration(BootstapContext<Biome> bootstrapContext) {
if (generationSettings == null) { if (generationSettings == null) {
generationSettings = new BiomeGenerationSettings.Builder( generationSettings = new BiomeGenerationSettings.Builder(
builderContext.bootstrapContext.lookup(Registries.PLACED_FEATURE), bootstrapContext.lookup(Registries.PLACED_FEATURE),
builderContext.bootstrapContext.lookup(Registries.CONFIGURED_CARVER) bootstrapContext.lookup(Registries.CONFIGURED_CARVER)
); );
} }
return generationSettings; return generationSettings;
@ -943,7 +946,7 @@ public class BCLBiomeBuilder {
* *
* @return created {@link BCLBiome} instance. * @return created {@link BCLBiome} instance.
*/ */
public PreparedBiome<BCLBiome> build() { public UnregisteredBCLBiome<BCLBiome> build() {
return build(BCLBiome::new); return build(BCLBiome::new);
} }
@ -954,17 +957,7 @@ public class BCLBiomeBuilder {
* @param biomeConstructor {@link BiomeSupplier} biome constructor. * @param biomeConstructor {@link BiomeSupplier} biome constructor.
* @return created {@link BCLBiome} instance. * @return created {@link BCLBiome} instance.
*/ */
public <T extends BCLBiome> PreparedBiome<T> build(BiomeSupplier<T> biomeConstructor) { public <T extends BCLBiome> UnregisteredBCLBiome<T> build(BiomeSupplier<T> biomeConstructor) {
BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation)
.temperature(temperature)
.downfall(downfall);
builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());
builder.generationSettings(fixGenerationSettings(getGeneration().build()));
BCLBiomeSettings settings = BCLBiomeSettings.createBCL() BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
.setTerrainHeight(height) .setTerrainHeight(height)
.setFogDensity(fogDensity) .setFogDensity(fogDensity)
@ -973,20 +966,30 @@ public class BCLBiomeBuilder {
.setEdge(edge) .setEdge(edge)
.setVertical(vertical) .setVertical(vertical)
.build(); .build();
final T res = biomeConstructor.apply(ResourceKey.create(Registries.BIOME, biomeID), settings);
final Biome biome = builder.build();
final T res = biomeConstructor.apply(biomeID, biome, settings);
tags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, res.getBiomeKey())); tags.forEach(tagKey -> TagManager.BIOMES.add(tagKey, res.getBiomeKey()));
//res.addBiomeTags(tags);
//res.setSurface(surfaceRule);
SurfaceRuleRegistry.registerRule(biomeID, surfaceRule, biomeID); SurfaceRuleRegistry.registerRule(biomeID, surfaceRule, biomeID);
res.addClimateParameters(parameters); res.addClimateParameters(parameters);
if (biomeType != null) if (biomeType != null)
res._setIntendedType(biomeType); res._setIntendedType(biomeType);
BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation)
.temperature(temperature)
.downfall(downfall);
builder.mobSpawnSettings(getSpawns().build());
builder.specialEffects(getEffects().build());
//res.addBiomeTags(tags);
//res.setSurface(surfaceRule);
//carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first)); //carvers.forEach(cfg -> BiomeAPI.addBiomeCarver(biome, cfg.second, cfg.first));
return new PreparedBiome<>(res, builderContext); return new UnregisteredBCLBiome<>(
res,
parent,
ctx -> builder.generationSettings(fixGenerationSettings(getGeneration(ctx).build())).build()
);
} }
} }

View file

@ -0,0 +1,24 @@
package org.betterx.bclib.api.v2.levelgen.biomes;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.world.level.biome.Biome;
public class BCLBiomeContainer<T extends BCLBiome> {
protected final T biome;
BCLBiomeContainer(T biome) {
this.biome = biome;
}
public T biome() {
return biome;
}
public BCLBiomeContainer<T> register(BootstapContext<Biome> bootstrapContext) {
return register(bootstrapContext, biome.getIntendedType());
}
public BCLBiomeContainer<T> register(BootstapContext<Biome> bootstrapContext, BiomeAPI.BiomeType dim) {
return this;
}
}

View file

@ -291,10 +291,10 @@ public class BiomeAPI {
static BCLBiome registerBiome(BootstapContext<Biome> bootstrapContext, BCLBiome bclbiome) { static BCLBiome registerBiome(BootstapContext<Biome> bootstrapContext, BCLBiome bclbiome) {
HolderGetter<Biome> registryOrNull = bootstrapContext.lookup(Registries.BIOME); HolderGetter<Biome> registryOrNull = bootstrapContext.lookup(Registries.BIOME);
if (registryOrNull != null if (registryOrNull != null
&& bclbiome.biomeToRegister != null && bclbiome._hasBiomeToRegister()
//TODO: 1.19.3 this was a ResourceLocation lookup, is this a valid test? //TODO: 1.19.3 this was a ResourceLocation lookup, is this a valid test?
&& registryOrNull.get(bclbiome.getBiomeKey()).map(v -> v.isBound()).orElse(false) == false) { && registryOrNull.get(bclbiome.getBiomeKey()).map(v -> v.isBound()).orElse(false) == false) {
bootstrapContext.register(bclbiome.getBiomeKey(), bclbiome.biomeToRegister); bootstrapContext.register(bclbiome.getBiomeKey(), bclbiome._getBiomeToRegister());
BCLBiomeRegistry.register(null, bclbiome); BCLBiomeRegistry.register(null, bclbiome);
} }
@ -330,21 +330,6 @@ public class BiomeAPI {
); );
} }
static BCLBiome registerSubBiome(
BootstapContext<Biome> bootstrapContext,
BCLBiome parent,
Biome subBiome,
float genChance
) {
return registerSubBiome(
bootstrapContext,
parent,
subBiome,
genChance,
parent.getIntendedType()
);
}
static BCLBiome registerSubBiome( static BCLBiome registerSubBiome(
BootstapContext<Biome> bootstrapContext, BootstapContext<Biome> bootstrapContext,
BCLBiome parent, BCLBiome parent,
@ -357,17 +342,6 @@ public class BiomeAPI {
return subBiome; return subBiome;
} }
static BCLBiome registerSubBiome(
BootstapContext<Biome> bootstrapContext,
BCLBiome parent,
Biome biome,
float genChance,
BiomeType dim
) {
BCLBiome subBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
return registerSubBiome(bootstrapContext, parent, subBiome, dim);
}
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands). * After that biome will be added to BCLib End Biome Generator and into Fabric Biome API as a land biome (will generate only on islands).

View file

@ -27,7 +27,7 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
BCLib.LOGGER.info("Datagen buildRegistry"); BCLib.LOGGER.info("Datagen buildRegistry");
registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap); registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap);
registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap); registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap);
//registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap); registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap); registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap);
} }
} }

View file

@ -3,46 +3,35 @@ package org.betterx.bclib.datagen;
import org.betterx.bclib.BCLib; import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeBuilder; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeBuilder;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeContainer;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderGetter;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext; import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
public class TestBiomes { public class TestBiomes {
static BCLBiomeContainer<BCLBiome> THE_YELLOW = BCLBiomeBuilder
.start(BCLib.makeID("the_yellow"))
.precipitation(Biome.Precipitation.NONE)
.temperature(1.0f)
.wetness(1.0f)
.fogColor(0xFFFF00)
.waterColor(0x777700)
.waterFogColor(0xFFFF00)
.skyColor(0xAAAA00)
.feature(TestPlacedFeatures.YELLOW_PLACED)
.addNetherClimateParamater(-1, 1)
.surface(Blocks.YELLOW_CONCRETE)
.endLandBiome()
.build();
public static void bootstrap(BootstapContext<Biome> bootstrapContext) { public static void bootstrap(BootstapContext<Biome> bootstrapContext) {
BCLib.LOGGER.info("Bootstrap Biomes"); BCLib.LOGGER.info("Bootstrap Biomes");
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) { if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
HolderGetter<PlacedFeature> holderGetter = bootstrapContext.lookup(Registries.PLACED_FEATURE); BCLBiomeContainer<BCLBiome> theYellow = THE_YELLOW
Holder.Reference<PlacedFeature> reference = holderGetter.getOrThrow(ResourceKey.create( .register(bootstrapContext);
Registries.PLACED_FEATURE,
BCLib.makeID("yellow_feature")
));
BCLib.LOGGER.info("REF Biome:" + reference);
BCLBiomeBuilder.Context biomeBuilder = new BCLBiomeBuilder.Context(bootstrapContext); BCLBiome theBlue = BCLBiomeBuilder
BCLBiome theYellow = biomeBuilder
.start(BCLib.makeID("the_yellow"))
.precipitation(Biome.Precipitation.NONE)
.temperature(1.0f)
.wetness(1.0f)
.fogColor(0xFFFF00)
.waterColor(0x777700)
.waterFogColor(0xFFFF00)
.skyColor(0xAAAA00)
.feature(GenerationStep.Decoration.VEGETAL_DECORATION, reference)
.addNetherClimateParamater(-1, 1)
.surface(Blocks.YELLOW_CONCRETE)
.build()
.registerEndLandBiome();
BCLBiome theBlue = biomeBuilder
.start(BCLib.makeID("the_blue")) .start(BCLib.makeID("the_blue"))
.precipitation(Biome.Precipitation.NONE) .precipitation(Biome.Precipitation.NONE)
.temperature(1.0f) .temperature(1.0f)
@ -53,10 +42,11 @@ public class TestBiomes {
.skyColor(0x0000AA) .skyColor(0x0000AA)
.addNetherClimateParamater(-1, 1) .addNetherClimateParamater(-1, 1)
.surface(Blocks.LIGHT_BLUE_CONCRETE) .surface(Blocks.LIGHT_BLUE_CONCRETE)
.endLandBiome()
.build() .build()
.registerEndLandBiome(); .register(bootstrapContext).biome();
BCLBiome theGray = biomeBuilder BCLBiome theGray = BCLBiomeBuilder
.start(BCLib.makeID("the_gray")) .start(BCLib.makeID("the_gray"))
.precipitation(Biome.Precipitation.NONE) .precipitation(Biome.Precipitation.NONE)
.temperature(1.0f) .temperature(1.0f)
@ -67,10 +57,11 @@ public class TestBiomes {
.skyColor(0xAAAAAA) .skyColor(0xAAAAAA)
.addNetherClimateParamater(-1, 1) .addNetherClimateParamater(-1, 1)
.surface(Blocks.GRAY_CONCRETE) .surface(Blocks.GRAY_CONCRETE)
.endVoidBiome()
.build() .build()
.registerEndVoidBiome(); .register(bootstrapContext).biome();
BCLBiome theOrange = biomeBuilder BCLBiome theOrange = BCLBiomeBuilder
.start(BCLib.makeID("the_orange")) .start(BCLib.makeID("the_orange"))
.precipitation(Biome.Precipitation.NONE) .precipitation(Biome.Precipitation.NONE)
.temperature(1.0f) .temperature(1.0f)
@ -81,10 +72,11 @@ public class TestBiomes {
.skyColor(0xAA7700) .skyColor(0xAA7700)
.addNetherClimateParamater(-1, 1.1f) .addNetherClimateParamater(-1, 1.1f)
.surface(Blocks.ORANGE_CONCRETE) .surface(Blocks.ORANGE_CONCRETE)
.netherBiome()
.build() .build()
.registerNetherBiome(); .register(bootstrapContext).biome();
BCLBiome thePurple = biomeBuilder BCLBiome thePurple = BCLBiomeBuilder
.start(BCLib.makeID("the_purple")) .start(BCLib.makeID("the_purple"))
.precipitation(Biome.Precipitation.NONE) .precipitation(Biome.Precipitation.NONE)
.temperature(1.0f) .temperature(1.0f)
@ -95,8 +87,9 @@ public class TestBiomes {
.skyColor(0xAA00AA) .skyColor(0xAA00AA)
.addNetherClimateParamater(-1.1f, 1) .addNetherClimateParamater(-1.1f, 1)
.surface(Blocks.PURPLE_CONCRETE) .surface(Blocks.PURPLE_CONCRETE)
.netherBiome()
.build() .build()
.registerNetherBiome(); .register(bootstrapContext).biome();
} }
} }
} }