Refactored Biome Config handling (#63)

This commit is contained in:
Frank 2022-01-17 14:06:22 +01:00
parent 11985395ae
commit b0f6dd6bff
9 changed files with 389 additions and 172 deletions

View file

@ -34,7 +34,10 @@ import ru.bclib.api.surface.SurfaceRuleBuilder;
import ru.bclib.entity.BCLEntityWrapper; import ru.bclib.entity.BCLEntityWrapper;
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor; import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
import ru.bclib.util.ColorUtil; import ru.bclib.util.ColorUtil;
import ru.bclib.util.TriFunction;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.BCLBiomeSettings;
import ru.bclib.world.biomes.BCLBiomeSettings.Builder;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.structures.BCLStructureFeature; import ru.bclib.world.structures.BCLStructureFeature;
@ -48,6 +51,10 @@ import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class BCLBiomeBuilder { public class BCLBiomeBuilder {
@FunctionalInterface
public interface BiomeSupplier<T> extends TriFunction<ResourceLocation, Biome, BCLBiomeSettings, T>{
}
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder(); private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012); private static final SurfaceRules.ConditionSource SURFACE_NOISE = SurfaceRules.noiseCondition(Noises.SOUL_SAND_LAYER, -0.012);
@ -64,6 +71,10 @@ public class BCLBiomeBuilder {
private float genChance; private float genChance;
private float downfall; private float downfall;
private float height; private float height;
private int edgeSize;
private BCLBiome edge;
private boolean vertical;
/** /**
* Starts new biome building process. * Starts new biome building process.
@ -80,9 +91,12 @@ public class BCLBiomeBuilder {
INSTANCE.structures.clear(); INSTANCE.structures.clear();
INSTANCE.temperature = 1.0F; INSTANCE.temperature = 1.0F;
INSTANCE.fogDensity = 1.0F; INSTANCE.fogDensity = 1.0F;
INSTANCE.edgeSize = 0;
INSTANCE.downfall = 1.0F; INSTANCE.downfall = 1.0F;
INSTANCE.genChance = 1.0F; INSTANCE.genChance = 1.0F;
INSTANCE.height = 0.1F; INSTANCE.height = 0.1F;
INSTANCE.vertical = false;
INSTANCE.edge = null;
return INSTANCE; return INSTANCE;
} }
@ -234,6 +248,40 @@ public class BCLBiomeBuilder {
return this; return this;
} }
/**
* Sets edge size for this biome.
* @param edgeSize size of the Edge (in Blocks)
* @return same {@link BCLBiomeBuilder}.
*/
public BCLBiomeBuilder edgeSize(int edgeSize) {
this.edgeSize = edgeSize;
return this;
}
/**
* Sets edge-Biome for this biome.
* @param edge The Edge Biome
* @return same {@link BCLBiomeBuilder}.
*/
public BCLBiomeBuilder edge(BCLBiome edge) {
this.edge = edge;
return this;
}
/**
* Sets edge-Biome for this biome.
* @param edge The Edge Biome
* @param edgeSize size of the Edge (in Blocks)
* @return same {@link BCLBiomeBuilder}.
*/
public BCLBiomeBuilder edge(BCLBiome edge, int edgeSize) {
this.edge(edge);
this.edgeSize(edgeSize);
return this;
}
/** /**
* Sets water color for the biome. Color is in ARGB int format. * Sets water color for the biome. Color is in ARGB int format.
* @param color ARGB color as integer. * @param color ARGB color as integer.
@ -579,12 +627,24 @@ public class BCLBiomeBuilder {
return this; return this;
} }
/**
* Make this a vertical Biome
*
* @return same {@link BCLBiomeBuilder} instance.
*/
public BCLBiomeBuilder vertical() {
this.vertical = vertical;
return this;
}
/** /**
* Finalize biome creation. * Finalize biome creation.
* @return created {@link BCLBiome} instance. * @return created {@link BCLBiome} instance.
*/ */
public BCLBiome build() { public BCLBiome build() {
return build(BCLBiome::new); return build((BiomeSupplier<BCLBiome>)BCLBiome::new);
} }
/** /**
@ -592,7 +652,17 @@ public class BCLBiomeBuilder {
* @param biomeConstructor {@link BiFunction} biome constructor. * @param biomeConstructor {@link BiFunction} biome constructor.
* @return created {@link BCLBiome} instance. * @return created {@link BCLBiome} instance.
*/ */
@Deprecated(forRemoval = true)
public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) { public <T extends BCLBiome> T build(BiFunction<ResourceLocation, Biome, T> biomeConstructor) {
return build((id, biome, settings)->biomeConstructor.apply(id, biome));
}
/**
* Finalize biome creation.
* @param biomeConstructor {@link BiomeSupplier} biome constructor.
* @return created {@link BCLBiome} instance.
*/
public <T extends BCLBiome> T build(BiomeSupplier<T> biomeConstructor) {
BiomeBuilder builder = new BiomeBuilder() BiomeBuilder builder = new BiomeBuilder()
.precipitation(precipitation) .precipitation(precipitation)
.biomeCategory(category) .biomeCategory(category)
@ -622,12 +692,18 @@ public class BCLBiomeBuilder {
builder.generationSettings(getGeneration().build()); builder.generationSettings(getGeneration().build());
} }
final T res = biomeConstructor.apply(biomeID, builder.build()); BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
res.setTerrainHeight(height); .setTerrainHeight(height)
.setFogDensity(fogDensity)
.setGenChance(genChance)
.setEdgeSize(edgeSize)
.setEdge(edge)
.setVertical(vertical)
.build();
final T res = biomeConstructor.apply(biomeID, builder.build(), settings);
res.attachStructures(structures); res.attachStructures(structures);
res.setSurface(surfaceRule); res.setSurface(surfaceRule);
res.setFogDensity(fogDensity);
res.setGenChance(genChance);
res.setFeatures(defferedFeatures); res.setFeatures(defferedFeatures);
return res; return res;
} }

View file

@ -69,7 +69,9 @@ import ru.bclib.mixin.common.StructureSettingsAccessor;
import ru.bclib.util.CollectionsUtil; import ru.bclib.util.CollectionsUtil;
import ru.bclib.util.MHelper; import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.BCLBiomeSettings;
import ru.bclib.world.biomes.FabricBiomesData; import ru.bclib.world.biomes.FabricBiomesData;
import ru.bclib.world.biomes.VanillaBiomeSettings;
import ru.bclib.world.features.BCLFeature; import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.generator.BiomePicker; import ru.bclib.world.generator.BiomePicker;
import ru.bclib.world.structures.BCLStructureFeature; import ru.bclib.world.structures.BCLStructureFeature;
@ -216,7 +218,7 @@ public class BiomeAPI {
} }
public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) { public static BCLBiome registerSubBiome(BCLBiome parent, Biome biome, float genChance) {
BCLBiome subBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome subBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
return registerSubBiome(parent, subBiome); return registerSubBiome(parent, subBiome);
} }
@ -253,8 +255,8 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerNetherBiome(Biome biome) { public static BCLBiome registerNetherBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome, null);
configureBiome(bclBiome);
NETHER_BIOME_PICKER.addBiome(bclBiome); NETHER_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
@ -268,7 +270,7 @@ public class BiomeAPI {
*/ */
public static BCLBiome registerEndLandBiome(BCLBiome biome) { public static BCLBiome registerEndLandBiome(BCLBiome biome) {
registerBiome(biome); registerBiome(biome);
configureBiome(biome);
END_LAND_BIOME_PICKER.addBiome(biome); END_LAND_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
@ -284,8 +286,8 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(Biome biome) { public static BCLBiome registerEndLandBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome, null);
configureBiome(bclBiome);
END_LAND_BIOME_PICKER.addBiome(bclBiome); END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
@ -299,8 +301,8 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) { public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
configureBiome(bclBiome);
END_LAND_BIOME_PICKER.addBiome(bclBiome); END_LAND_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
@ -314,7 +316,7 @@ public class BiomeAPI {
*/ */
public static BCLBiome registerEndVoidBiome(BCLBiome biome) { public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
registerBiome(biome); registerBiome(biome);
configureBiome(biome);
END_VOID_BIOME_PICKER.addBiome(biome); END_VOID_BIOME_PICKER.addBiome(biome);
float weight = biome.getGenChance(); float weight = biome.getGenChance();
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow(); ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
@ -329,8 +331,8 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome) { public static BCLBiome registerEndVoidBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome); BCLBiome bclBiome = new BCLBiome(biome, null);
configureBiome(bclBiome);
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
@ -344,8 +346,8 @@ public class BiomeAPI {
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance); BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
configureBiome(bclBiome);
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
return bclBiome; return bclBiome;
@ -993,13 +995,6 @@ public class BiomeAPI {
}); });
} }
private static void configureBiome(BCLBiome biome) {
String group = biome.getID().getNamespace() + "." + biome.getID().getPath();
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", biome.getGenChance());
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", biome.getFogDensity());
biome.setGenChance(chance).setFogDensity(fog);
}
/** /**
* Getter for correct feature list from all biome feature list of lists. * Getter for correct feature list from all biome feature list of lists.
* @param step feature {@link Decoration} step. * @param step feature {@link Decoration} step.

View file

@ -0,0 +1,6 @@
package ru.bclib.util;
@FunctionalInterface
public interface TriFunction<A, B, C, R> {
R apply(A a, B b, C c);
}

View file

@ -25,7 +25,7 @@ import java.util.Random;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
public class BCLBiome { public class BCLBiome extends BCLBiomeSettings {
private final List<ConfiguredStructureFeature> structures = Lists.newArrayList(); private final List<ConfiguredStructureFeature> structures = Lists.newArrayList();
private final WeightedList<BCLBiome> subbiomes = new WeightedList<>(); private final WeightedList<BCLBiome> subbiomes = new WeightedList<>();
private final Map<String, Object> customData = Maps.newHashMap(); private final Map<String, Object> customData = Maps.newHashMap();
@ -35,13 +35,6 @@ public class BCLBiome {
private Consumer<Biome> surfaceInit; private Consumer<Biome> surfaceInit;
private BCLBiome biomeParent; private BCLBiome biomeParent;
private Biome actualBiome; private Biome actualBiome;
private BCLBiome edge;
private float terrainHeight = 0.1F;
private float fogDensity = 1.0F;
private float genChance = 1.0F;
private int edgeSize = 0;
private boolean vertical;
/** /**
* Create wrapper for existing biome using its {@link ResourceLocation} identifier. * Create wrapper for existing biome using its {@link ResourceLocation} identifier.
@ -56,7 +49,7 @@ public class BCLBiome {
* @param biomeID {@link ResourceLocation} biome ID. * @param biomeID {@link ResourceLocation} biome ID.
*/ */
public BCLBiome(ResourceLocation biomeID) { public BCLBiome(ResourceLocation biomeID) {
this(biomeID, BuiltinRegistries.BIOME.get(biomeID)); this(biomeID, BuiltinRegistries.BIOME.get(biomeID), null);
} }
/** /**
@ -64,13 +57,36 @@ public class BCLBiome {
* @param biome {@link Biome} to wrap. * @param biome {@link Biome} to wrap.
*/ */
public BCLBiome(Biome biome) { public BCLBiome(Biome biome) {
this(BuiltinRegistries.BIOME.getKey(biome), biome); this(biome, null);
}
/**
* Create wrapper for existing biome using biome instance from {@link BuiltinRegistries}.
* @param biome {@link Biome} to wrap.
* @param settings The Settings for this Biome or {@code null} if you want to apply default settings
*/
public BCLBiome(Biome biome, VanillaBiomeSettings settings) {
this(BuiltinRegistries.BIOME.getKey(biome), biome, settings);
} }
public BCLBiome(ResourceLocation biomeID, Biome biome) { public BCLBiome(ResourceLocation biomeID, Biome biome) {
this(biomeID, biome, null);
}
/**
* Create a new Biome
* @param biomeID {@link ResourceLocation} biome ID.
* @param biome {@link Biome} to wrap.
* @param defaults The Settings for this Biome or null if you want to apply the defaults
*/
public BCLBiome(ResourceLocation biomeID, Biome biome, BCLBiomeSettings defaults) {
this.subbiomes.add(this, 1.0F); this.subbiomes.add(this, 1.0F);
this.biomeID = biomeID; this.biomeID = biomeID;
this.biome = biome; this.biome = biome;
if (defaults !=null){
defaults.applyWithDefaults(this);
}
} }
/** /**
@ -87,30 +103,12 @@ public class BCLBiome {
* @param edge {@link BCLBiome} as the edge biome. * @param edge {@link BCLBiome} as the edge biome.
* @return same {@link BCLBiome}. * @return same {@link BCLBiome}.
*/ */
public BCLBiome setEdge(BCLBiome edge) { BCLBiome setEdge(BCLBiome edge) {
this.edge = edge; this.edge = edge;
edge.biomeParent = this; edge.biomeParent = this;
return this; return this;
} }
/**
* Getter for biome edge size.
* @return edge size in blocks.
*/
public int getEdgeSize() {
return edgeSize;
}
/**
* Set edges size for this biome. Size is in blocks.
* @param size as a float value.
* @return same {@link BCLBiome}.
*/
public BCLBiome setEdgeSize(int size) {
edgeSize = size;
return this;
}
/** /**
* Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance. * Adds sub-biome into this biome instance. Biome chance will be interpreted as a sub-biome generation chance.
* Biome itself has chance 1.0 compared to all its sub-biomes. * Biome itself has chance 1.0 compared to all its sub-biomes.
@ -167,23 +165,6 @@ public class BCLBiome {
return biomeID; return biomeID;
} }
/**
* Getter for fog density, used in custom for renderer.
* @return fog density as a float.
*/
public float getFogDensity() {
return fogDensity;
}
/**
* Sets fog density for this biome.
* @param fogDensity
* @return same {@link BCLBiome}.
*/
public BCLBiome setFogDensity(float fogDensity) {
this.fogDensity = fogDensity;
return this;
}
/** /**
* Getter for biome from buil-in registry. For datapack biomes will be same as actual biome. * Getter for biome from buil-in registry. For datapack biomes will be same as actual biome.
@ -201,23 +182,7 @@ public class BCLBiome {
return this.actualBiome; return this.actualBiome;
} }
/**
* Getter for biome generation chance, used in {@link ru.bclib.world.generator.BiomePicker} and in custom generators.
* @return biome generation chance as float.
*/
public float getGenChance() {
return this.genChance;
}
/**
* Set gen chance for this biome, default value is 1.0.
* @param genChance chance of this biome to be generated.
* @return same {@link BCLBiome}.
*/
public BCLBiome setGenChance(float genChance) {
this.genChance = genChance;
return this;
}
/** /**
* Recursively update biomes to correct world biome registry instances, for internal usage only. * Recursively update biomes to correct world biome registry instances, for internal usage only.
@ -289,50 +254,6 @@ public class BCLBiome {
return this; return this;
} }
/**
* Setter for terrain height, can be used in custom terrain generator.
* @param terrainHeight a relative float terrain height value.
* @return same {@link BCLBiome}.
*/
public BCLBiome setTerrainHeight(float terrainHeight) {
this.terrainHeight = terrainHeight;
return this;
}
/**
* Getter for terrain height, can be used in custom terrain generator.
* @return terrain height.
*/
public float getTerrainHeight() {
return terrainHeight;
}
/**
* Set biome vertical distribution (for tall Nether only).
* @return same {@link BCLBiome}.
*/
public BCLBiome setVertical() {
return setVertical(true);
}
/**
* Set biome vertical distribution (for tall Nether only).
* @param vertical {@code boolean} value.
* @return same {@link BCLBiome}.
*/
public BCLBiome setVertical(boolean vertical) {
this.vertical = vertical;
return this;
}
/**
* Checks if biome is vertical, for tall Nether only (or for custom generators).
* @return is biome vertical or not.
*/
public boolean isVertical() {
return vertical;
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj == this) { if (obj == this) {
@ -406,29 +327,62 @@ public class BCLBiome {
} }
private boolean didLoadConfig = false; private boolean didLoadConfig = false;
/**
* For internal use. // /**
* Set Biome configuartion from Config. This method is called for all Biomes that get registered // * Set gen chance for this biome, default value is 1.0.
* to a {@link ru.bclib.world.generator.BCLBiomeSource}. // * @param genChance chance of this biome to be generated.
* // * @return same {@link BCLBiome}.
* @return This instance // */
*/ // public BCLBiome setGenChance(float genChance) {
public BCLBiome setupFromConfig() { // super.setGenChance(genChance);
if (didLoadConfig) return this; // return this;
didLoadConfig = true; // }
//
String group = this.configGroup(); // /**
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", this.getGenChance()); // * Setter for terrain height, can be used in custom terrain generator.
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", this.getFogDensity()); // * @param terrainHeight a relative float terrain height value.
this.setGenChance(chance).setFogDensity(fog); // * @return same {@link BCLBiome}.
// */
if (this.getEdge()!=null){ // public BCLBiome setTerrainHeight(float terrainHeight) {
int edgeSize = Configs.BIOMES_CONFIG.getInt(group, "edge_size", this.getEdgeSize()); // super.setTerrainHeight(genChance);
this.setEdgeSize(edgeSize); // return this;
} // }
//
Configs.BIOMES_CONFIG.saveChanges(); // /**
// * Set biome vertical distribution (for tall Nether only).
return this; // * @return same {@link BCLBiome}.
} // */
// public BCLBiome setVertical() {
// return setVertical(true);
// }
//
// /**
// * Set biome vertical distribution (for tall Nether only).
// * @param vertical {@code boolean} value.
// * @return same {@link BCLBiome}.
// */
// public BCLBiome setVertical(boolean vertical) {
// super.setVertical(vertical);
// return this;
// }
//
// /**
// * Sets fog density for this biome.
// * @param fogDensity
// * @return same {@link BCLBiome}.
// */
// public BCLBiome setFogDensity(float fogDensity) {
// super.setFogDensity(fogDensity);
// return this;
// }
//
// /**
// * Set edges size for this biome. Size is in blocks.
// * @param size as a float value.
// * @return same {@link BCLBiome}.
// */
// public BCLBiome setEdgeSize(int size) {
// edgeSize = size;
// return this;
// }
} }

View file

@ -0,0 +1,185 @@
package ru.bclib.world.biomes;
import net.minecraft.world.level.biome.Biome;
import ru.bclib.config.Configs;
import ru.bclib.world.biomes.VanillaBiomeSettings.Builder;
public class BCLBiomeSettings {
public static Builder createBCL(){
return new Builder();
}
public static class Builder extends CommonBuilder<BCLBiomeSettings, Builder>{
public Builder(){
super(new BCLBiomeSettings());
}
}
public static class CommonBuilder<T extends BCLBiomeSettings, R extends CommonBuilder>{
private final T storage;
CommonBuilder(T storage){
this.storage = storage;
}
public T build(){
return storage;
}
/**
* Set gen chance for this biome, default value is 1.0.
* @param genChance chance of this biome to be generated.
* @return same {@link BCLBiomeSettings}.
*/
public R setGenChance(float genChance) {
storage.genChance = genChance;
return (R)this;
}
/**
* Setter for terrain height, can be used in custom terrain generator.
* @param terrainHeight a relative float terrain height value.
* @return same {@link Builder}.
*/
public R setTerrainHeight(float terrainHeight) {
storage.terrainHeight = terrainHeight;
return (R)this;
}
/**
* Set biome vertical distribution (for tall Nether only).
* @return same {@link Builder}.
*/
public R setVertical() {
return setVertical(true);
}
/**
* Set biome vertical distribution (for tall Nether only).
* @param vertical {@code boolean} value.
* @return same {@link Builder}.
*/
public R setVertical(boolean vertical) {
storage.vertical = vertical;
return (R)this;
}
/**
* Set edges size for this biome. Size is in blocks.
* @param size as a float value.
* @return same {@link Builder}.
*/
public R setEdgeSize(int size) {
storage.edgeSize = size;
return (R)this;
}
/**
* Set edges:biome for this biome.
* @param edge The {@link Biome}.
* @return same {@link Builder}.
*/
public R setEdge(BCLBiome edge) {
storage.edge = edge;
return (R)this;
}
/**
* Sets fog density for this biome.
* @param fogDensity
* @return same {@link Builder}.
*/
public R setFogDensity(float fogDensity) {
storage.fogDensity = fogDensity;
return (R)this;
}
}
protected BCLBiomeSettings(){
this.terrainHeight = 0.1F;
this.fogDensity = 1.0F;
this.genChance = 1.0F;
this.edgeSize = 0;
this.vertical = false;
this.edge = null;
}
float terrainHeight;
float fogDensity;
float genChance;
int edgeSize;
boolean vertical;
BCLBiome edge;
/**
* Getter for biome generation chance, used in {@link ru.bclib.world.generator.BiomePicker} and in custom generators.
* @return biome generation chance as float.
*/
public float getGenChance() {
return this.genChance;
}
/**
* Checks if biome is vertical, for tall Nether only (or for custom generators).
* @return is biome vertical or not.
*/
public boolean isVertical() {
return vertical;
}
/**
* Getter for terrain height, can be used in custom terrain generator.
* @return terrain height.
*/
public float getTerrainHeight() {
return terrainHeight;
}
/**
* Getter for fog density, used in custom for renderer.
* @return fog density as a float.
*/
public float getFogDensity() {
return fogDensity;
}
/**
* Getter for biome edge size.
* @return edge size in blocks.
*/
public int getEdgeSize() {
return edgeSize;
}
/**
* Getter for edge-biome.
* @return The assigned edge biome.
*/
public BCLBiome getEdge() {
return edge;
}
/**
* Load values from Config and apply to the passed Biome. The Default values for the loaded settings
* are derifed from the values store in this object
* @param biome {@link BCLBiome} to assign values to
*/
public void applyWithDefaults(BCLBiome biome){
final String group = biome.configGroup();
biome.genChance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", this.genChance);
if (edge!=null){
biome.edgeSize = Configs.BIOMES_CONFIG.getInt(group, "edge_size", this.edgeSize);
if (edgeSize>0) {
biome.setEdge(edge);
}
}
if (!(this instanceof VanillaBiomeSettings)){
biome.fogDensity = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", this.fogDensity);
biome.vertical = Configs.BIOMES_CONFIG.getBoolean(group, "vertical", this.vertical);
biome.terrainHeight = Configs.BIOMES_CONFIG.getFloat(group, "terrain_height", this.terrainHeight);
}
Configs.BIOMES_CONFIG.saveChanges();
}
}

View file

@ -0,0 +1,14 @@
package ru.bclib.world.biomes;
public class VanillaBiomeSettings extends BCLBiomeSettings{
public static class Builder extends BCLBiomeSettings.CommonBuilder<VanillaBiomeSettings, VanillaBiomeSettings.Builder>{
public Builder(){
super(new VanillaBiomeSettings());
}
}
public static Builder createVanilla(){
return new Builder();
}
}

View file

@ -5,6 +5,7 @@ import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource;
import ru.bclib.api.biomes.BiomeAPI; import ru.bclib.api.biomes.BiomeAPI;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.BCLBiomeSettings;
import java.util.List; import java.util.List;
@ -25,14 +26,4 @@ public abstract class BCLBiomeSource extends BiomeSource {
BiomeAPI.initRegistry(biomeRegistry); BiomeAPI.initRegistry(biomeRegistry);
} }
/**
* Set Biome configuartion from Config
* @param bclBiome The biome you want to configure
* @return The input biome
*/
public static BCLBiome setupFromConfig(BCLBiome bclBiome) {
bclBiome.setupFromConfig();
return bclBiome;
}
} }

View file

@ -58,7 +58,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
String group = key.getNamespace() + "." + key.getPath(); String group = key.getNamespace() + "." + key.getPath();
if (!BiomeAPI.hasBiome(key)) { if (!BiomeAPI.hasBiome(key)) {
BCLBiome bclBiome = setupFromConfig(new BCLBiome(key, biome)); BCLBiome bclBiome = new BCLBiome(key, biome);
if (includeVoid.contains(key.toString())) { if (includeVoid.contains(key.toString())) {
BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome); BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome);
@ -70,8 +70,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
else { else {
BCLBiome bclBiome = BiomeAPI.getBiome(key); BCLBiome bclBiome = BiomeAPI.getBiome(key);
if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome != BiomeAPI.EMPTY_BIOME) {
setupFromConfig(bclBiome);
if (bclBiome.getParentBiome() == null) { if (bclBiome.getParentBiome() == null) {
if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) { if (!BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) && !BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key)) {
if (includeVoid.contains(key.toString())) { if (includeVoid.contains(key.toString())) {

View file

@ -64,14 +64,12 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
ResourceLocation key = biomeRegistry.getKey(biome); ResourceLocation key = biomeRegistry.getKey(biome);
if (!BiomeAPI.hasBiome(key)) { if (!BiomeAPI.hasBiome(key)) {
BCLBiome bclBiome = setupFromConfig(new BCLBiome(key, biome)); BCLBiome bclBiome = new BCLBiome(key, biome);
BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome);
} }
else { else {
BCLBiome bclBiome = BiomeAPI.getBiome(key); BCLBiome bclBiome = BiomeAPI.getBiome(key);
if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome != BiomeAPI.EMPTY_BIOME) {
setupFromConfig(bclBiome);
if (bclBiome.getParentBiome() == null) { if (bclBiome.getParentBiome() == null) {
if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) { if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) {
BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome); BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome);