From 8861c0645f309590d0509749df3b84d8422359b4 Mon Sep 17 00:00:00 2001 From: Frank Date: Fri, 8 Jul 2022 00:12:39 +0200 Subject: [PATCH] [Feature] More flexible/extensible End-Biome Placement --- .../api/v2/generator/BCLibEndBiomeSource.java | 144 +++++++--- .../v2/generator/BCLibNetherBiomeSource.java | 6 +- .../bclib/api/v2/generator/BiomeDecider.java | 264 ++++++++++++++++++ .../api/v2/generator/GeneratorOptions.java | 10 +- .../config/BCLEndBiomeSourceConfig.java | 7 +- .../config/BCLNetherBiomeSourceConfig.java | 7 +- .../generator/config/MapBuilderFunction.java | 9 + .../bclib/api/v2/generator/map/MapStack.java | 6 +- .../api/v2/levelgen/biomes/BCLBiome.java | 2 +- 9 files changed, 394 insertions(+), 61 deletions(-) create mode 100644 src/main/java/org/betterx/bclib/api/v2/generator/BiomeDecider.java create mode 100644 src/main/java/org/betterx/bclib/api/v2/generator/config/MapBuilderFunction.java diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java index bd4ef2e1..927c3709 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibEndBiomeSource.java @@ -67,6 +67,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi private BiomePicker endVoidBiomePicker; private BiomePicker endCenterBiomePicker; private BiomePicker endBarrensBiomePicker; + private List deciders; private BCLEndBiomeSourceConfig config; @@ -111,6 +112,11 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi var includeMap = Configs.BIOMES_CONFIG.getBiomeIncludeMap(); var excludeList = Configs.BIOMES_CONFIG.getExcludeMatching(BiomeAPI.BiomeType.END); + this.deciders = BiomeDecider.DECIDERS.stream() + .filter(d -> d.canProvideFor(this)) + .map(d -> d.createInstance(this)) + .toList(); + this.endLandBiomePicker = new BiomePicker(biomeRegistry); this.endVoidBiomePicker = new BiomePicker(biomeRegistry); this.endCenterBiomePicker = new BiomePicker(biomeRegistry); @@ -160,24 +166,36 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi } if (!didForceAdd) { - if (BiomeAPI.wasRegisteredAs(biomeID, BiomeAPI.BiomeType.END_IGNORE)) { + if (biomeID.equals(BCLBiomeRegistry.EMPTY_BIOME.getID()) + || bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_IGNORE)) { //we should not add this biome anywhere, so just ignore it - } else if (BiomeAPI.wasRegisteredAs(biomeID, BiomeAPI.BiomeType.END_CENTER) - || TheEndBiomesHelper.canGenerateAsMainIslandBiome(key)) { - endCenterBiomePicker.addBiome(bclBiome); - } else if (BiomeAPI.wasRegisteredAs(biomeID, BiomeAPI.BiomeType.END_LAND) - || TheEndBiomesHelper.canGenerateAsHighlandsBiome(key)) { - if (!config.withVoidBiomes) endVoidBiomePicker.addBiome(bclBiome); - endLandBiomePicker.addBiome(bclBiome); - } else if (BiomeAPI.wasRegisteredAs(biomeID, BiomeAPI.BiomeType.END_BARRENS) - || TheEndBiomesHelper.canGenerateAsEndBarrens(key)) { - endBarrensBiomePicker.addBiome(bclBiome); - } else if (BiomeAPI.wasRegisteredAs(biomeID, BiomeAPI.BiomeType.END_VOID) - || TheEndBiomesHelper.canGenerateAsSmallIslandsBiome(key)) { - endVoidBiomePicker.addBiome(bclBiome); } else { - BCLib.LOGGER.info("Found End Biome " + biomeStr + " that was not registers with fabric or bclib. Assuming end-land Biome..."); - endLandBiomePicker.addBiome(bclBiome); + didForceAdd = false; + for (BiomeDecider decider : deciders) { + if (decider.addToPicker(bclBiome)) { + didForceAdd = true; + break; + } + } + if (!didForceAdd) { + if (bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_CENTER) + || TheEndBiomesHelper.canGenerateAsMainIslandBiome(key)) { + endCenterBiomePicker.addBiome(bclBiome); + } else if (bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_LAND) + || TheEndBiomesHelper.canGenerateAsHighlandsBiome(key)) { + if (!config.withVoidBiomes) endVoidBiomePicker.addBiome(bclBiome); + endLandBiomePicker.addBiome(bclBiome); + } else if (bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_BARRENS) + || TheEndBiomesHelper.canGenerateAsEndBarrens(key)) { + endBarrensBiomePicker.addBiome(bclBiome); + } else if (bclBiome.getIntendedType().is(BiomeAPI.BiomeType.END_VOID) + || TheEndBiomesHelper.canGenerateAsSmallIslandsBiome(key)) { + endVoidBiomePicker.addBiome(bclBiome); + } else { + BCLib.LOGGER.info("Found End Biome " + biomeStr + " that was not registers with fabric or bclib. Assuming end-land Biome..."); + endLandBiomePicker.addBiome(bclBiome); + } + } } } } @@ -189,6 +207,10 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi endBarrensBiomePicker.rebuild(); endCenterBiomePicker.rebuild(); + for (BiomeDecider decider : deciders) { + decider.rebuild(); + } + if (endVoidBiomePicker.isEmpty()) { BCLib.LOGGER.info("No Void Biomes found. Disabling by using barrens"); endVoidBiomePicker = endBarrensBiomePicker; @@ -266,25 +288,32 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi @Override protected void onInitMap(long seed) { - this.mapLand = config.mapVersion.mapBuilder.apply( + for (BiomeDecider decider : deciders) { + decider.createMap((picker, size) -> config.mapVersion.mapBuilder.create( + seed, + size <= 0 ? config.landBiomesSize : size, + picker + )); + } + this.mapLand = config.mapVersion.mapBuilder.create( seed, config.landBiomesSize, endLandBiomePicker ); - this.mapVoid = config.mapVersion.mapBuilder.apply( + this.mapVoid = config.mapVersion.mapBuilder.create( seed, config.voidBiomesSize, endVoidBiomePicker ); - this.mapCenter = config.mapVersion.mapBuilder.apply( + this.mapCenter = config.mapVersion.mapBuilder.create( seed, config.centerBiomesSize, endCenterBiomePicker ); - this.mapBarrens = config.mapVersion.mapBuilder.apply( + this.mapBarrens = config.mapVersion.mapBuilder.create( seed, config.barrensBiomesSize, endBarrensBiomePicker @@ -315,39 +344,74 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi mapVoid.clearCache(); mapCenter.clearCache(); mapVoid.clearCache(); + for (BiomeDecider decider : deciders) { + decider.clearMapCache(); + } } - if (config.generatorVersion == BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA || endLandFunction == null) { - if (dist <= (long) config.innerVoidRadiusSquared) { - return mapCenter.getBiome(posX, biomeY << 2, posZ).biome; - } + BiomeAPI.BiomeType suggestedType; + + if (config.generatorVersion == BCLEndBiomeSourceConfig.EndBiomeGeneratorType.VANILLA) { int x = (SectionPos.blockToSectionCoord(posX) * 2 + 1) * 8; int z = (SectionPos.blockToSectionCoord(posZ) * 2 + 1) * 8; double d = sampler.erosion().compute(new DensityFunction.SinglePointContext(x, posY, z)); - if (d > 0.25) { - return mapLand.getBiome(posX, biomeY << 2, posZ).biome; //highlands - } else if (d >= -0.0625) { - return mapLand.getBiome(posX, biomeY << 2, posZ).biome; //midlands + if (dist <= (long) config.innerVoidRadiusSquared) { + suggestedType = BiomeAPI.BiomeType.END_CENTER; } else { - return d < -0.21875 - ? mapVoid.getBiome(posX, biomeY << 2, posZ).biome //small islands - : (config.withVoidBiomes ? mapBarrens : mapLand).getBiome( + if (d > 0.25) { + suggestedType = BiomeAPI.BiomeType.END_LAND; //highlands + } else if (d >= -0.0625) { + suggestedType = BiomeAPI.BiomeType.END_LAND; //midlands + } else { + suggestedType = d < -0.21875 + ? BiomeAPI.BiomeType.END_VOID //small islands + : (config.withVoidBiomes + ? BiomeAPI.BiomeType.END_BARRENS + : BiomeAPI.BiomeType.END_LAND); //barrens + } + } + + final BiomeAPI.BiomeType originalType = suggestedType; + for (BiomeDecider decider : deciders) { + suggestedType = decider + .suggestType( + originalType, + suggestedType, + d, + maxHeight, posX, - biomeY << 2, - posZ - ).biome; //barrens + posY, + posZ, + biomeX, + biomeY, + biomeZ + ); } } else { pos.setLocation(biomeX, biomeZ); - if (endLandFunction.apply(pos, maxHeight)) { - return (dist <= (long) config.innerVoidRadiusSquared ? mapCenter : mapLand) - .getBiome(posX, biomeY << 2, posZ).biome; - } else { - return (dist <= (long) config.innerVoidRadiusSquared ? mapBarrens : mapVoid) - .getBiome(posX, biomeY << 2, posZ).biome; + final BiomeAPI.BiomeType originalType = (dist <= (long) config.innerVoidRadiusSquared + ? BiomeAPI.BiomeType.END_CENTER + : BiomeAPI.BiomeType.END_LAND); + suggestedType = originalType; + + for (BiomeDecider decider : deciders) { + suggestedType = decider + .suggestType(originalType, suggestedType, maxHeight, posX, posY, posZ, biomeX, biomeY, biomeZ); } } + BiomePicker.ActualBiome result; + for (BiomeDecider decider : deciders) { + if (decider.canProvideBiome(suggestedType)) { + result = decider.provideBiome(suggestedType, posX, posY, posZ); + if (result != null) return result.biome; + } + } + + if (suggestedType.is(BiomeAPI.BiomeType.END_CENTER)) return mapCenter.getBiome(posX, posY, posZ).biome; + if (suggestedType.is(BiomeAPI.BiomeType.END_VOID)) return mapVoid.getBiome(posX, posY, posZ).biome; + if (suggestedType.is(BiomeAPI.BiomeType.END_BARRENS)) return mapBarrens.getBiome(posX, posY, posZ).biome; + return mapLand.getBiome(posX, posY, posZ).biome; } diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java index dc614b86..60e87d0a 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/BCLibNetherBiomeSource.java @@ -2,13 +2,13 @@ package org.betterx.bclib.api.v2.generator; import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.generator.config.BCLNetherBiomeSourceConfig; +import org.betterx.bclib.api.v2.generator.config.MapBuilderFunction; import org.betterx.bclib.api.v2.generator.map.MapStack; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome; import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; import org.betterx.bclib.config.Configs; import org.betterx.bclib.interfaces.BiomeMap; -import org.betterx.bclib.util.TriFunction; import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig; import org.betterx.worlds.together.biomesource.ReloadableBiomeSource; @@ -181,7 +181,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc @Override protected void onInitMap(long seed) { - TriFunction mapConstructor = config.mapVersion.mapBuilder; + MapBuilderFunction mapConstructor = config.mapVersion.mapBuilder; if (maxHeight > config.biomeSizeVertical * 1.5 && config.useVerticalBiomes) { this.biomeMap = new MapStack( seed, @@ -192,7 +192,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource implements BiomeSourc mapConstructor ); } else { - this.biomeMap = mapConstructor.apply( + this.biomeMap = mapConstructor.create( seed, config.biomeSize, biomePicker diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/BiomeDecider.java b/src/main/java/org/betterx/bclib/api/v2/generator/BiomeDecider.java new file mode 100644 index 00000000..4b4c3394 --- /dev/null +++ b/src/main/java/org/betterx/bclib/api/v2/generator/BiomeDecider.java @@ -0,0 +1,264 @@ +package org.betterx.bclib.api.v2.generator; + +import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome; +import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; +import org.betterx.bclib.interfaces.BiomeMap; + +import net.minecraft.core.Registry; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.biome.Biome; +import net.minecraft.world.level.biome.BiomeSource; + +import java.util.LinkedList; +import java.util.List; + + +/** + * Used to extend the BiomePlacement in the {@link BCLBiomeSource} + */ +public abstract class BiomeDecider { + + /** + * used to create new {@link BiomeMap} instances + */ + @FunctionalInterface + public interface BiomeMapBuilderFunction { + /** + * Constructs a new {@link BiomeMap} + * + * @param picker The picker the BiomeMap should use + * @param biomeSize The biomeSize the map will use or -1 for the default size + * @return a new {@link BiomeMap} instance + */ + BiomeMap create(BiomePicker picker, int biomeSize); + } + + /** + * used to determine wether or not a decider can provide this biome + */ + @FunctionalInterface + public interface BiomePredicate { + boolean test(BCLBiome biome); + } + + protected BiomePicker picker; + protected BiomeMap map; + private final BiomePredicate predicate; + + static List DECIDERS = new LinkedList<>(); + + /** + * Register a high priority Decider for the {@link BCLibEndBiomeSource}. + * Normally you should not need to register a high priority decider and instead use + * {@link BiomeDecider#registerDecider(ResourceLocation, BiomeDecider)}. + * BetterEnd (for example) will add + * + * @param location The {@link ResourceLocation} for the decider + * @param decider The initial decider Instance. Each Instance of the {@link BCLibEndBiomeSource} + * will call {@link BiomeDecider#createInstance(BCLBiomeSource)} to build a + * new instance of this decider + */ + public static void registerHighPriorityDecider(ResourceLocation location, BiomeDecider decider) { + if (DECIDERS.size() == 0) DECIDERS.add(decider); + else DECIDERS.add(0, decider); + } + + /** + * Register a new Decider for the {@link BCLibEndBiomeSource} + * + * @param location The {@link ResourceLocation} for the decider + * @param decider The initial decider Instance. Each Instance of the {@link BCLibEndBiomeSource} + * will call {@link BiomeDecider#createInstance(BCLBiomeSource)} to build a + * new instance of this decider + */ + public static void registerDecider(ResourceLocation location, BiomeDecider decider) { + DECIDERS.add(decider); + } + + protected BiomeDecider(BiomePredicate predicate) { + this(null, predicate); + } + + /** + * @param biomeRegistry The biome registry assigned to the creating BiomeSource + * @param predicate A predicate that decides if a given Biome can be provided by this decider + */ + protected BiomeDecider( + Registry biomeRegistry, BiomePredicate predicate + ) { + this.predicate = predicate; + this.map = null; + if (biomeRegistry == null) { + this.picker = null; + } else { + this.picker = new BiomePicker(biomeRegistry); + } + } + + /** + * Called to test, if a decider is suitable for the given BiomeSource. + * + * @param source The BiomeSource that wants to use the decider + * @return true, if this decider is usable by that source + */ + public abstract boolean canProvideFor(BiomeSource source); + + /** + * Called from the BiomeSource whenever it needs to create a new instance of this decider. + *

+ * Inheriting classes should overwrite this method and return Instances of the class. For + * the base {@link BiomeDecider} you would return new BiomeDecider(biomeSource.biomeRegistry, this.predicate); + * + * @param biomeSource The biome source this decider is used from + * @return A new instance + */ + public abstract BiomeDecider createInstance(BCLBiomeSource biomeSource); + + /** + * Called when the BiomeSources needs to construct a new {@link BiomeMap} for the picker. + *

+ * The default implementation creates a new map with the instances picker and a default biome size + * + * @param mapBuilder A function you can use to create a new {@link BiomeMap} that conforms to the settings + * of the current BiomeSource. + */ + public void createMap(BiomeMapBuilderFunction mapBuilder) { + this.map = mapBuilder.create(picker, -1); + } + + /** + * called whenever the BiomeSource needs to clear caches + */ + public void clearMapCache() { + map.clearCache(); + } + + /** + * This method get's called whenever the BiomeSource populates the Biome Pickers. You need to + * determine if the passed Biome is valid for your picker. + *

+ * If this method returns false, the Biome wil not get added to any other Deciders/Pickers. + *

+ * The default implementation will use the instances {@link BiomeDecider#predicate} to determine if + * a biome should get added and return true if it was added. + * + * @param biome The biome that should get added if it matches the criteria of the picker + * @return false, if other pickers/deciders are allowed to use the biome as well + */ + public boolean addToPicker(BCLBiome biome) { + if (predicate.test(biome)) { + picker.addBiome(biome); + return true; + } + + return false; + } + + /** + * Called whenever the picker needs to rebuild it's contents + */ + public void rebuild() { + picker.rebuild(); + } + + /** + * Called from the BiomeSource to determine the type of Biome it needs to place. + * + * @param originalType The original biome type the source did select + * @param suggestedType The currently suggested type. This will differ from originalType if other + * {@link BiomeDecider} instances already had a new suggestion. You implementation should return the + * suggestedType if it does not want to provide the Biome for this location + * @param maxHeight The maximum terrain height for this world + * @param blockX The block coordinate where we are at + * @param blockY The block coordinate where we are at + * @param blockZ The block coordinate where we are at + * @param quarterX The quarter Block Coordinate (which is blockX/4) + * @param quarterY The quarter Block Coordinate (which is blockY/4) + * @param quarterZ The quarter Block Coordinate (which is blockZ/4) + * @return The suggestedType if this decider does not plan to provide a Biome, or a unique BiomeType. + * The Biome Source will call {@link BiomeDecider#selectBiome(BiomeAPI.BiomeType)} with the finally chosen type + * for all available Deciders. + */ + public BiomeAPI.BiomeType suggestType( + BiomeAPI.BiomeType originalType, + BiomeAPI.BiomeType suggestedType, + int maxHeight, + int blockX, + int blockY, + int blockZ, + int quarterX, + int quarterY, + int quarterZ + ) { + return suggestType( + originalType, + suggestedType, + 0, + maxHeight, + blockX, + blockY, + blockZ, + quarterX, + quarterY, + quarterZ + ); + } + + /** + * Called from the BiomeSource to determine the type of Biome it needs to place. + * + * @param originalType The original biome type the source did select + * @param suggestedType The currently suggested type. This will differ from originalType if other + * {@link BiomeDecider} instances already had a new suggestion. You implementation should return the + * suggestedType if it does not want to provide the Biome for this location + * @param density The terrain density at this location. Currently only valid if for {@link BCLibEndBiomeSource} + * that use the {@link org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig.EndBiomeGeneratorType#VANILLA} + * @param maxHeight The maximum terrain height for this world + * @param blockX The block coordinate where we are at + * @param blockY The block coordinate where we are at + * @param blockZ The block coordinate where we are at + * @param quarterX The quarter Block Coordinate (which is blockX/4) + * @param quarterY The quarter Block Coordinate (which is blockY/4) + * @param quarterZ The quarter Block Coordinate (which is blockZ/4) + * @param maxHeight + * @return The suggestedType if this decider does not plan to provide a Biome, or a unique BiomeType. + * The Biome Source will call {@link BiomeDecider#selectBiome(BiomeAPI.BiomeType)} with the finally chosen type + * for all available Deciders. + */ + public abstract BiomeAPI.BiomeType suggestType( + BiomeAPI.BiomeType originalType, + BiomeAPI.BiomeType suggestedType, + double density, + int maxHeight, + int blockX, + int blockY, + int blockZ, + int quarterX, + int quarterY, + int quarterZ + ); + + + /** + * Called to check if this decider can place a biome for the specified type + * + * @param suggestedType The type of biome we need to place + * @return true, if this type of biome can be provided by the current picker. If true + * is returned, the BiomeSource will call {@link BiomeDecider#provideBiome(BiomeAPI.BiomeType, int, int, int)} + * next + */ + public abstract boolean canProvideBiome(BiomeAPI.BiomeType suggestedType); + + /** + * Called to check if this decider can place a biome for the specified type + *

+ * The default implementation will return map.getBiome(posX, posY, posZ) + * + * @param suggestedType The type of biome we need to place + * @return The methode should return a Biome from its {@link BiomeMap}. If null is returned, the next + * decider (or the default map) will provide the biome + */ + public BiomePicker.ActualBiome provideBiome(BiomeAPI.BiomeType suggestedType, int posX, int posY, int posZ) { + return map.getBiome(posX, posY, posZ); + } +} diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/GeneratorOptions.java b/src/main/java/org/betterx/bclib/api/v2/generator/GeneratorOptions.java index a15eef3e..79679d8b 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/GeneratorOptions.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/GeneratorOptions.java @@ -7,7 +7,7 @@ import java.util.function.BiFunction; import java.util.function.Function; public class GeneratorOptions { - private static BiFunction endLandFunction; + //private static BiFunction endLandFunction; private static boolean fixEndBiomeSource = true; private static boolean fixNetherBiomeSource = true; @@ -42,15 +42,17 @@ public class GeneratorOptions { */ @Deprecated(forRemoval = true) public static void setEndLandFunction(Function endLandFunction) { - GeneratorOptions.endLandFunction = (p, h) -> endLandFunction.apply(p); + //GeneratorOptions.endLandFunction = (p, h) -> endLandFunction.apply(p); } + @Deprecated(forRemoval = true) public static void setEndLandFunction(BiFunction endLandFunction) { - GeneratorOptions.endLandFunction = endLandFunction; + ///GeneratorOptions.endLandFunction = endLandFunction; } + @Deprecated(forRemoval = true) public static BiFunction getEndLandFunction() { - return endLandFunction; + return (a, b) -> true;//endLandFunction; } @Deprecated(forRemoval = true) diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLEndBiomeSourceConfig.java b/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLEndBiomeSourceConfig.java index b52bb069..558773e6 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLEndBiomeSourceConfig.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLEndBiomeSourceConfig.java @@ -2,11 +2,8 @@ package org.betterx.bclib.api.v2.generator.config; import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.generator.BCLibEndBiomeSource; -import org.betterx.bclib.api.v2.generator.BiomePicker; import org.betterx.bclib.api.v2.generator.map.hex.HexBiomeMap; import org.betterx.bclib.api.v2.generator.map.square.SquareBiomeMap; -import org.betterx.bclib.interfaces.BiomeMap; -import org.betterx.bclib.util.TriFunction; import org.betterx.worlds.together.biomesource.config.BiomeSourceConfig; import com.mojang.serialization.Codec; @@ -114,9 +111,9 @@ public class BCLEndBiomeSourceConfig implements BiomeSourceConfig CODEC = StringRepresentable.fromEnum(EndBiomeMapType::values); public final String name; - public final @NotNull TriFunction mapBuilder; + public final @NotNull MapBuilderFunction mapBuilder; - EndBiomeMapType(String name, @NotNull TriFunction mapBuilder) { + EndBiomeMapType(String name, @NotNull MapBuilderFunction mapBuilder) { this.name = name; this.mapBuilder = mapBuilder; } diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLNetherBiomeSourceConfig.java b/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLNetherBiomeSourceConfig.java index d50e7313..4d8c5249 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLNetherBiomeSourceConfig.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/config/BCLNetherBiomeSourceConfig.java @@ -1,11 +1,8 @@ package org.betterx.bclib.api.v2.generator.config; import org.betterx.bclib.api.v2.generator.BCLibNetherBiomeSource; -import org.betterx.bclib.api.v2.generator.BiomePicker; import org.betterx.bclib.api.v2.generator.map.hex.HexBiomeMap; import org.betterx.bclib.api.v2.generator.map.square.SquareBiomeMap; -import org.betterx.bclib.interfaces.BiomeMap; -import org.betterx.bclib.util.TriFunction; import org.betterx.worlds.together.biomesource.config.BiomeSourceConfig; import com.mojang.serialization.Codec; @@ -110,9 +107,9 @@ public class BCLNetherBiomeSourceConfig implements BiomeSourceConfig CODEC = StringRepresentable.fromEnum(NetherBiomeMapType::values); public final String name; - public final TriFunction mapBuilder; + public final MapBuilderFunction mapBuilder; - NetherBiomeMapType(String name, TriFunction mapBuilder) { + NetherBiomeMapType(String name, MapBuilderFunction mapBuilder) { this.name = name; this.mapBuilder = mapBuilder; } diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/config/MapBuilderFunction.java b/src/main/java/org/betterx/bclib/api/v2/generator/config/MapBuilderFunction.java new file mode 100644 index 00000000..cfb9e206 --- /dev/null +++ b/src/main/java/org/betterx/bclib/api/v2/generator/config/MapBuilderFunction.java @@ -0,0 +1,9 @@ +package org.betterx.bclib.api.v2.generator.config; + +import org.betterx.bclib.api.v2.generator.BiomePicker; +import org.betterx.bclib.interfaces.BiomeMap; + +@FunctionalInterface +public interface MapBuilderFunction { + BiomeMap create(long seed, int biomeSize, BiomePicker picker); +} diff --git a/src/main/java/org/betterx/bclib/api/v2/generator/map/MapStack.java b/src/main/java/org/betterx/bclib/api/v2/generator/map/MapStack.java index 0340d06c..74dbb00f 100644 --- a/src/main/java/org/betterx/bclib/api/v2/generator/map/MapStack.java +++ b/src/main/java/org/betterx/bclib/api/v2/generator/map/MapStack.java @@ -1,11 +1,11 @@ package org.betterx.bclib.api.v2.generator.map; import org.betterx.bclib.api.v2.generator.BiomePicker; +import org.betterx.bclib.api.v2.generator.config.MapBuilderFunction; import org.betterx.bclib.interfaces.BiomeChunk; import org.betterx.bclib.interfaces.BiomeMap; import org.betterx.bclib.interfaces.TriConsumer; import org.betterx.bclib.noise.OpenSimplexNoise; -import org.betterx.bclib.util.TriFunction; import net.minecraft.util.Mth; @@ -26,7 +26,7 @@ public class MapStack implements BiomeMap { BiomePicker picker, int mapHeight, int worldHeight, - TriFunction mapConstructor + MapBuilderFunction mapConstructor ) { final int mapCount = Mth.ceil((float) worldHeight / mapHeight); this.maxIndex = mapCount - 1; @@ -37,7 +37,7 @@ public class MapStack implements BiomeMap { maps = new BiomeMap[mapCount]; Random random = new Random(seed); for (int i = 0; i < mapCount; i++) { - maps[i] = mapConstructor.apply(random.nextLong(), size, picker); + maps[i] = mapConstructor.create(random.nextLong(), size, picker); maps[i].setChunkProcessor(this::onChunkCreation); } noise = new OpenSimplexNoise(random.nextInt()); diff --git a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiome.java b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiome.java index f5694e8f..fe7a699f 100644 --- a/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiome.java +++ b/src/main/java/org/betterx/bclib/api/v2/levelgen/biomes/BCLBiome.java @@ -290,7 +290,7 @@ public class BCLBiome extends BCLBiomeSettings implements BiomeData { return this; } - BiomeAPI.BiomeType getIntendedType() { + public BiomeAPI.BiomeType getIntendedType() { return this.intendedType; }