Refactored Biome Config handling (#63)
This commit is contained in:
parent
3584432a96
commit
05ed11978d
9 changed files with 389 additions and 172 deletions
|
@ -34,7 +34,10 @@ import ru.bclib.api.surface.SurfaceRuleBuilder;
|
|||
import ru.bclib.entity.BCLEntityWrapper;
|
||||
import ru.bclib.mixin.common.BiomeGenerationSettingsAccessor;
|
||||
import ru.bclib.util.ColorUtil;
|
||||
import ru.bclib.util.TriFunction;
|
||||
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.structures.BCLStructureFeature;
|
||||
|
||||
|
@ -48,6 +51,10 @@ import java.util.function.Supplier;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class BCLBiomeBuilder {
|
||||
@FunctionalInterface
|
||||
public interface BiomeSupplier<T> extends TriFunction<ResourceLocation, Biome, BCLBiomeSettings, T>{
|
||||
}
|
||||
|
||||
private static final BCLBiomeBuilder INSTANCE = new BCLBiomeBuilder();
|
||||
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 downfall;
|
||||
private float height;
|
||||
private int edgeSize;
|
||||
private BCLBiome edge;
|
||||
private boolean vertical;
|
||||
|
||||
|
||||
/**
|
||||
* Starts new biome building process.
|
||||
|
@ -80,9 +91,12 @@ public class BCLBiomeBuilder {
|
|||
INSTANCE.structures.clear();
|
||||
INSTANCE.temperature = 1.0F;
|
||||
INSTANCE.fogDensity = 1.0F;
|
||||
INSTANCE.edgeSize = 0;
|
||||
INSTANCE.downfall = 1.0F;
|
||||
INSTANCE.genChance = 1.0F;
|
||||
INSTANCE.height = 0.1F;
|
||||
INSTANCE.vertical = false;
|
||||
INSTANCE.edge = null;
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
|
@ -234,6 +248,40 @@ public class BCLBiomeBuilder {
|
|||
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.
|
||||
* @param color ARGB color as integer.
|
||||
|
@ -579,12 +627,24 @@ public class BCLBiomeBuilder {
|
|||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Make this a vertical Biome
|
||||
*
|
||||
* @return same {@link BCLBiomeBuilder} instance.
|
||||
*/
|
||||
public BCLBiomeBuilder vertical() {
|
||||
this.vertical = vertical;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize biome creation.
|
||||
* @return created {@link BCLBiome} instance.
|
||||
*/
|
||||
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.
|
||||
* @return created {@link BCLBiome} instance.
|
||||
*/
|
||||
@Deprecated(forRemoval = true)
|
||||
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()
|
||||
.precipitation(precipitation)
|
||||
.biomeCategory(category)
|
||||
|
@ -622,12 +692,18 @@ public class BCLBiomeBuilder {
|
|||
builder.generationSettings(getGeneration().build());
|
||||
}
|
||||
|
||||
final T res = biomeConstructor.apply(biomeID, builder.build());
|
||||
res.setTerrainHeight(height);
|
||||
BCLBiomeSettings settings = BCLBiomeSettings.createBCL()
|
||||
.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.setSurface(surfaceRule);
|
||||
res.setFogDensity(fogDensity);
|
||||
res.setGenChance(genChance);
|
||||
res.setFeatures(defferedFeatures);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -69,7 +69,9 @@ import ru.bclib.mixin.common.StructureSettingsAccessor;
|
|||
import ru.bclib.util.CollectionsUtil;
|
||||
import ru.bclib.util.MHelper;
|
||||
import ru.bclib.world.biomes.BCLBiome;
|
||||
import ru.bclib.world.biomes.BCLBiomeSettings;
|
||||
import ru.bclib.world.biomes.FabricBiomesData;
|
||||
import ru.bclib.world.biomes.VanillaBiomeSettings;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
import ru.bclib.world.generator.BiomePicker;
|
||||
import ru.bclib.world.structures.BCLStructureFeature;
|
||||
|
@ -216,7 +218,7 @@ public class BiomeAPI {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -253,8 +255,8 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerNetherBiome(Biome biome) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome);
|
||||
configureBiome(bclBiome);
|
||||
BCLBiome bclBiome = new BCLBiome(biome, null);
|
||||
|
||||
NETHER_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
return bclBiome;
|
||||
|
@ -268,7 +270,7 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static BCLBiome registerEndLandBiome(BCLBiome biome) {
|
||||
registerBiome(biome);
|
||||
configureBiome(biome);
|
||||
|
||||
END_LAND_BIOME_PICKER.addBiome(biome);
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
|
||||
|
@ -284,8 +286,8 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerEndLandBiome(Biome biome) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome);
|
||||
configureBiome(bclBiome);
|
||||
BCLBiome bclBiome = new BCLBiome(biome, null);
|
||||
|
||||
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
return bclBiome;
|
||||
|
@ -299,8 +301,8 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerEndLandBiome(Biome biome, float genChance) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
|
||||
configureBiome(bclBiome);
|
||||
BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
|
||||
|
||||
END_LAND_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
return bclBiome;
|
||||
|
@ -314,7 +316,7 @@ public class BiomeAPI {
|
|||
*/
|
||||
public static BCLBiome registerEndVoidBiome(BCLBiome biome) {
|
||||
registerBiome(biome);
|
||||
configureBiome(biome);
|
||||
|
||||
END_VOID_BIOME_PICKER.addBiome(biome);
|
||||
float weight = biome.getGenChance();
|
||||
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).orElseThrow();
|
||||
|
@ -329,8 +331,8 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerEndVoidBiome(Biome biome) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome);
|
||||
configureBiome(bclBiome);
|
||||
BCLBiome bclBiome = new BCLBiome(biome, null);
|
||||
|
||||
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(bclBiome);
|
||||
return bclBiome;
|
||||
|
@ -344,8 +346,8 @@ public class BiomeAPI {
|
|||
* @return {@link BCLBiome}
|
||||
*/
|
||||
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
|
||||
BCLBiome bclBiome = new BCLBiome(biome).setGenChance(genChance);
|
||||
configureBiome(bclBiome);
|
||||
BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
|
||||
|
||||
END_VOID_BIOME_PICKER.addBiome(bclBiome);
|
||||
registerBiome(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.
|
||||
* @param step feature {@link Decoration} step.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue