Biome API (WIP), javadocs, biome map
This commit is contained in:
parent
c89235ec92
commit
67c9c2302d
9 changed files with 424 additions and 38 deletions
|
@ -11,16 +11,16 @@ import com.google.gson.JsonObject;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import ru.bclib.config.IdConfig;
|
||||
import ru.bclib.util.JsonFactory;
|
||||
import ru.bclib.util.StructureHelper;
|
||||
import ru.bclib.util.WeightedList;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
import ru.bclib.world.features.ListFeature;
|
||||
import ru.bclib.world.features.ListFeature.StructureInfo;
|
||||
import ru.bclib.world.features.NBTStructureFeature.TerrainMerge;
|
||||
|
||||
public class BCLBiome {
|
||||
protected List<BCLBiome> subbiomes = Lists.newArrayList();
|
||||
protected WeightedList<BCLBiome> subbiomes = new WeightedList<BCLBiome>();
|
||||
|
||||
protected final Biome biome;
|
||||
protected final ResourceLocation mcID;
|
||||
|
@ -29,32 +29,29 @@ public class BCLBiome {
|
|||
|
||||
protected BCLBiome biomeParent;
|
||||
protected float maxSubBiomeChance = 1;
|
||||
protected final float genChanceUnmutable;
|
||||
protected float genChance = 1;
|
||||
protected final float genChance;
|
||||
|
||||
private final float fogDensity;
|
||||
private BCLFeature structuresFeature;
|
||||
private Biome actualBiome;
|
||||
|
||||
public BCLBiome(BiomeDefinition definition, IdConfig config) {
|
||||
public BCLBiome(BiomeDefinition definition) {
|
||||
this.mcID = definition.getID();
|
||||
this.readStructureList();
|
||||
if (structuresFeature != null) {
|
||||
definition.addFeature(structuresFeature);
|
||||
}
|
||||
this.biome = definition.build();
|
||||
this.fogDensity = config.getFloat(mcID, "fog_density", definition.getFodDensity());
|
||||
this.genChanceUnmutable = config.getFloat(mcID, "generation_chance", definition.getGenChance());
|
||||
this.edgeSize = config.getInt(mcID, "edge_size", 32);
|
||||
this.genChance = definition.getGenChance();
|
||||
this.fogDensity = definition.getFodDensity();
|
||||
}
|
||||
|
||||
public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance, boolean hasCaves, IdConfig config) {
|
||||
public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) {
|
||||
this.mcID = id;
|
||||
this.readStructureList();
|
||||
this.biome = biome;
|
||||
this.fogDensity = config.getFloat(mcID, "fog_density", fogDensity);
|
||||
this.genChanceUnmutable = config.getFloat(mcID, "generation_chance", genChance);
|
||||
this.edgeSize = config.getInt(mcID, "edge_size", 32);
|
||||
this.genChance = genChance;
|
||||
this.fogDensity = fogDensity;
|
||||
this.readStructureList();
|
||||
}
|
||||
|
||||
public BCLBiome getEdge() {
|
||||
|
@ -75,9 +72,8 @@ public class BCLBiome {
|
|||
}
|
||||
|
||||
public void addSubBiome(BCLBiome biome) {
|
||||
maxSubBiomeChance += biome.mutateGenChance(maxSubBiomeChance);
|
||||
biome.biomeParent = this;
|
||||
subbiomes.add(biome);
|
||||
subbiomes.add(biome, biome.getGenChance());
|
||||
}
|
||||
|
||||
public boolean containsSubBiome(BCLBiome biome) {
|
||||
|
@ -85,11 +81,7 @@ public class BCLBiome {
|
|||
}
|
||||
|
||||
public BCLBiome getSubBiome(Random random) {
|
||||
float chance = random.nextFloat() * maxSubBiomeChance;
|
||||
for (BCLBiome biome : subbiomes)
|
||||
if (biome.canGenerate(chance))
|
||||
return biome;
|
||||
return this;
|
||||
return subbiomes.get(random);
|
||||
}
|
||||
|
||||
public BCLBiome getParentBiome() {
|
||||
|
@ -108,16 +100,6 @@ public class BCLBiome {
|
|||
return biome == this || (biome.hasParentBiome() && biome.getParentBiome() == this);
|
||||
}
|
||||
|
||||
public boolean canGenerate(float chance) {
|
||||
return chance <= this.genChance;
|
||||
}
|
||||
|
||||
public float mutateGenChance(float chance) {
|
||||
genChance = genChanceUnmutable;
|
||||
genChance += chance;
|
||||
return genChance;
|
||||
}
|
||||
|
||||
public Biome getBiome() {
|
||||
return biome;
|
||||
}
|
||||
|
@ -172,10 +154,6 @@ public class BCLBiome {
|
|||
return this.genChance;
|
||||
}
|
||||
|
||||
public float getGenChanceImmutable() {
|
||||
return this.genChanceUnmutable;
|
||||
}
|
||||
|
||||
public void updateActualBiomes(Registry<Biome> biomeRegistry) {
|
||||
subbiomes.forEach((sub) -> {
|
||||
if (sub != this) {
|
||||
|
|
|
@ -34,6 +34,7 @@ import net.minecraft.world.level.levelgen.feature.configurations.ProbabilityFeat
|
|||
import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder;
|
||||
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration;
|
||||
import ru.bclib.config.IdConfig;
|
||||
import ru.bclib.util.ColorUtil;
|
||||
import ru.bclib.world.features.BCLFeature;
|
||||
import ru.bclib.world.structures.BCLStructureFeature;
|
||||
|
@ -85,8 +86,8 @@ public class BiomeDefinition {
|
|||
|
||||
/**
|
||||
* Create default definition for The Nether biome.
|
||||
* @param id
|
||||
* @return
|
||||
* @param id - {@ResourceLocation}.
|
||||
* @return {@link BiomeDefinition}.
|
||||
*/
|
||||
public static BiomeDefinition netherBiome(ResourceLocation id) {
|
||||
BiomeDefinition def = new BiomeDefinition(id);
|
||||
|
@ -98,8 +99,8 @@ public class BiomeDefinition {
|
|||
|
||||
/**
|
||||
* Create default definition for The End biome.
|
||||
* @param id
|
||||
* @return
|
||||
* @param id - {@ResourceLocation}.
|
||||
* @return {@link BiomeDefinition}.
|
||||
*/
|
||||
public static BiomeDefinition endBiome(ResourceLocation id) {
|
||||
BiomeDefinition def = new BiomeDefinition(id);
|
||||
|
@ -109,6 +110,23 @@ public class BiomeDefinition {
|
|||
return def;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to load biome settings from config.
|
||||
* @param config - {@link IdConfig}.
|
||||
* @return this {@link BiomeDefinition}.
|
||||
*/
|
||||
public BiomeDefinition loadConfigValues(IdConfig config) {
|
||||
this.fogDensity = config.getFloat(id, "fog_density", this.fogDensity);
|
||||
this.genChance = config.getFloat(id, "generation_chance", this.genChance);
|
||||
this.edgeSize = config.getInt(id, "edge_size", this.edgeSize);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set category of the biome.
|
||||
* @param category - {@link BiomeCategory}.
|
||||
* @return this {@link BiomeDefinition}.
|
||||
*/
|
||||
public BiomeDefinition setCategory(BiomeCategory category) {
|
||||
this.category = category;
|
||||
return this;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue