More config refinement to ensure configs are not loaded multiple times with different defaults
This commit is contained in:
parent
f0c77abba6
commit
e6d481387d
2 changed files with 27 additions and 15 deletions
|
@ -15,6 +15,7 @@ import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.api.biomes.BiomeAPI;
|
||||
import ru.bclib.config.Configs;
|
||||
import ru.bclib.util.WeightedList;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -388,4 +389,29 @@ public class BCLBiome {
|
|||
public String configGroup() {
|
||||
return biomeID.getNamespace() + "." + biomeID.getPath();
|
||||
}
|
||||
|
||||
private boolean didLoadConfig = false;
|
||||
/**
|
||||
* Set Biome configuartion from Config
|
||||
* @return This instance
|
||||
*/
|
||||
public BCLBiome setupFromConfig() {
|
||||
if (didLoadConfig) return this;
|
||||
didLoadConfig = true;
|
||||
|
||||
String group = this.configGroup();
|
||||
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", this.getGenChance());
|
||||
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", this.getFogDensity());
|
||||
this.setGenChance(chance)
|
||||
.setFogDensity(fog);
|
||||
|
||||
if (this.getEdge()!=null){
|
||||
int edgeSize = Configs.BIOMES_CONFIG.getInt(group, "edge_size", this.getEdgeSize());
|
||||
this.setEdgeSize(edgeSize);
|
||||
}
|
||||
|
||||
Configs.BIOMES_CONFIG.saveChanges();
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,27 +27,13 @@ public abstract class BCLBiomeSource extends BiomeSource {
|
|||
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) {
|
||||
String group = bclBiome.configGroup();
|
||||
float chance = Configs.BIOMES_CONFIG.getFloat(group, "generation_chance", bclBiome.getGenChance());
|
||||
float fog = Configs.BIOMES_CONFIG.getFloat(group, "fog_density", bclBiome.getFogDensity());
|
||||
bclBiome.setGenChance(chance)
|
||||
.setFogDensity(fog);
|
||||
|
||||
if (bclBiome.getEdge()!=null){
|
||||
int edgeSize = Configs.BIOMES_CONFIG.getInt(group, "edge_size", bclBiome.getEdgeSize());
|
||||
bclBiome.setEdgeSize(edgeSize);
|
||||
}
|
||||
|
||||
Configs.BIOMES_CONFIG.saveChanges();
|
||||
|
||||
bclBiome.setupFromConfig();
|
||||
return bclBiome;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue