Biome config

This commit is contained in:
paulevsGitch 2021-11-20 13:41:03 +03:00
parent 69d11c0e5a
commit a2dec40b0a
6 changed files with 44 additions and 7 deletions

View file

@ -24,6 +24,7 @@ import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import org.jetbrains.annotations.Nullable;
import ru.bclib.config.Configs;
import ru.bclib.util.MHelper;
import ru.bclib.world.biomes.BCLBiome;
import ru.bclib.world.biomes.FabricBiomesData;
@ -85,6 +86,11 @@ public class BiomeAPI {
* @return {@link BCLBiome}
*/
public static BCLBiome registerBiome(BCLBiome biome) {
String biomePath = biome.getID().getNamespace() + "." + biome.getID().getPath();
if (!Configs.BIOMES_CONFIG.getBoolean(biomePath, "enabled", true)) {
return biome;
}
if (BuiltinRegistries.BIOME.get(biome.getID()) == null) {
Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome());
}
@ -93,6 +99,11 @@ public class BiomeAPI {
}
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
String biomePath = subBiome.getID().getNamespace() + "." + subBiome.getID().getPath();
if (!Configs.BIOMES_CONFIG.getBoolean(biomePath, "enabled", true)) {
return subBiome;
}
registerBiome(subBiome);
parent.addSubBiome(subBiome);
return subBiome;

View file

@ -11,18 +11,17 @@ public class Configs {
public static final ClientConfig CLIENT_CONFIG = new ClientConfig();
public static final ServerConfig SERVER_CONFIG = new ServerConfig();
public static final PathConfig GENERATOR_CONFIG = new PathConfig(BCLib.MOD_ID, "generator", false);
public static final PathConfig MAIN_CONFIG = new PathConfig(BCLib.MOD_ID, "main", true, true);
public static final String MAIN_PATCH_CATEGORY = "patches";
public static final PathConfig RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes");
public static final PathConfig BIOMES_CONFIG = new PathConfig(BCLib.MOD_ID, "biomes", false);
public static void save() {
MAIN_CONFIG.saveChanges();
RECIPE_CONFIG.saveChanges();
GENERATOR_CONFIG.saveChanges();
BIOMES_CONFIG.saveChanges();
}
}

View file

@ -7,6 +7,8 @@ import com.google.gson.JsonObject;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import ru.bclib.config.Configs;
import ru.bclib.util.JsonFactory;
import ru.bclib.util.StructureHelper;
import ru.bclib.util.WeightedList;
@ -38,6 +40,7 @@ public class BCLBiome {
private Biome actualBiome;
public BCLBiome(BCLBiomeDef definition) {
definition.loadConfigValues(Configs.BIOMES_CONFIG);
this.mcID = definition.getID();
this.readStructureList();
if (structuresFeature != null) {
@ -53,8 +56,15 @@ public class BCLBiome {
public BCLBiome(ResourceLocation id, Biome biome, float fogDensity, float genChance) {
this.mcID = id;
this.biome = biome;
this.genChance = genChance;
this.fogDensity = fogDensity;
if (id.equals(Biomes.THE_VOID.location())) {
this.genChance = fogDensity;
this.fogDensity = genChance;
}
else {
String biomePath = id.getNamespace() + "." + id.getPath();
this.genChance = Configs.BIOMES_CONFIG.getFloat(biomePath, "generation_chance", genChance);
this.fogDensity = Configs.BIOMES_CONFIG.getFloat(biomePath, "fog_density", fogDensity);
}
this.readStructureList();
this.customData = Maps.newHashMap();
subbiomes.add(this, 1);

View file

@ -32,6 +32,7 @@ import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuild
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilder;
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderBaseConfiguration;
import ru.bclib.config.IdConfig;
import ru.bclib.config.PathConfig;
import ru.bclib.util.ColorUtil;
import ru.bclib.world.features.BCLFeature;
import ru.bclib.world.structures.BCLStructureFeature;
@ -113,7 +114,6 @@ public class BCLBiomeDef {
/**
* Used to load biome settings from config.
*
* @param config - {@link IdConfig}.
* @return this {@link BCLBiomeDef}.
*/
@ -124,9 +124,21 @@ public class BCLBiomeDef {
return this;
}
/**
* Used to load biome settings from config.
* @param config - {@link PathConfig}.
* @return this {@link BCLBiomeDef}.
*/
public BCLBiomeDef loadConfigValues(PathConfig config) {
String biomePath = id.getNamespace() + "." + id.getPath();
this.fogDensity = config.getFloat(biomePath, "fog_density", this.fogDensity);
this.genChance = config.getFloat(biomePath, "generation_chance", this.genChance);
this.edgeSize = config.getInt(biomePath, "edge_size", this.edgeSize);
return this;
}
/**
* Set category of the biome.
*
* @param category - {@link BiomeCategory}.
* @return this {@link BCLBiomeDef}.
*/

View file

@ -14,6 +14,7 @@ import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI;
import ru.bclib.config.Configs;
import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome;
@ -62,6 +63,8 @@ public class BCLibEndBiomeSource extends BiomeSource {
}
});
Configs.BIOMES_CONFIG.saveChanges();
BiomeAPI.END_LAND_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry));
BiomeAPI.END_VOID_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry));

View file

@ -10,6 +10,7 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.BiomeSource;
import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI;
import ru.bclib.config.Configs;
import ru.bclib.world.biomes.BCLBiome;
import java.util.LinkedList;
@ -52,6 +53,7 @@ public class BCLibNetherBiomeSource extends BiomeSource {
}
});
Configs.BIOMES_CONFIG.saveChanges();
BiomeAPI.NETHER_BIOME_PICKER.getBiomes().forEach(biome -> biome.updateActualBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.rebuild();