Biome include lists

This commit is contained in:
paulevsGitch 2021-11-20 20:24:00 +03:00
parent c0b7ccca72
commit df214cdb24
8 changed files with 57 additions and 13 deletions

View file

@ -21,8 +21,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public abstract class Config { public abstract class Config {
protected final static Map<AutoSyncID, Config> AUTO_SYNC_CONFIGS = new HashMap<>();
public static final String CONFIG_SYNC_PREFIX = "CONFIG_"; public static final String CONFIG_SYNC_PREFIX = "CONFIG_";
protected final static Map<AutoSyncID, Config> autoSyncConfigs = new HashMap<>();
protected final ConfigKeeper keeper; protected final ConfigKeeper keeper;
protected final boolean autoSync; protected final boolean autoSync;
public final String configID; public final String configID;
@ -51,7 +51,7 @@ public abstract class Config {
else else
DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile()); DataExchangeAPI.addAutoSyncFile(aid.modID, aid.uniqueID, keeper.getConfigFile());
autoSyncConfigs.put(aid, this); AUTO_SYNC_CONFIGS.put(aid, this);
BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")"); BCLib.LOGGER.info("Added Config " + configID + " to auto sync (" + (diffContent?"content diff":"file hash") + ")");
} }
} }
@ -70,7 +70,7 @@ public abstract class Config {
} }
public static void reloadSyncedConfig(AutoSyncID aid, File file) { public static void reloadSyncedConfig(AutoSyncID aid, File file) {
Config cfg = autoSyncConfigs.get(aid); Config cfg = AUTO_SYNC_CONFIGS.get(aid);
if (cfg != null) { if (cfg != null) {
cfg.reload(); cfg.reload();
} }

View file

@ -23,9 +23,9 @@ import java.util.function.Supplier;
public final class ConfigKeeper { public final class ConfigKeeper {
private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap(); private final Map<ConfigKey, Entry<?>> configEntries = Maps.newHashMap();
private JsonObject configObject;
private final ConfigWriter writer; private final ConfigWriter writer;
private JsonObject configObject;
private boolean changed = false; private boolean changed = false;
public ConfigKeeper(String modID, String group) { public ConfigKeeper(String modID, String group) {
@ -33,7 +33,7 @@ public final class ConfigKeeper {
this.configObject = writer.load(); this.configObject = writer.load();
} }
File getConfigFile() { public File getConfigFile() {
return this.writer.getConfigFile(); return this.writer.getConfigFile();
} }
@ -141,7 +141,9 @@ public final class ConfigKeeper {
} }
String paramKey = key.getEntry(); String paramKey = key.getEntry();
paramKey += " [default: " + entry.getDefault() + "]"; if (entry.hasDefaultInName()) {
paramKey += " [default: " + entry.getDefault() + "]";
}
this.changed |= entry.setLocation(obj, paramKey); this.changed |= entry.setLocation(obj, paramKey);
} }
@ -328,7 +330,6 @@ public final class ConfigKeeper {
} }
public static class StringArrayEntry extends ArrayEntry<String> { public static class StringArrayEntry extends ArrayEntry<String> {
public StringArrayEntry(List<String> defaultValue) { public StringArrayEntry(List<String> defaultValue) {
super(defaultValue); super(defaultValue);
} }
@ -341,10 +342,14 @@ public final class ConfigKeeper {
protected void add(JsonArray array, String el){ protected void add(JsonArray array, String el){
array.add(el); array.add(el);
} }
@Override
protected boolean hasDefaultInName() {
return false;
}
} }
public static class EnumEntry<T extends Enum<T>> extends Entry<T> { public static class EnumEntry<T extends Enum<T>> extends Entry<T> {
private final Type type; private final Type type;
public EnumEntry(T defaultValue) { public EnumEntry(T defaultValue) {
@ -372,7 +377,6 @@ public final class ConfigKeeper {
} }
public static abstract class RangeEntry<T extends Comparable<T>> extends Entry<T> { public static abstract class RangeEntry<T extends Comparable<T>> extends Entry<T> {
private final T min, max; private final T min, max;
public RangeEntry(T defaultValue, T minVal, T maxVal) { public RangeEntry(T defaultValue, T minVal, T maxVal) {
@ -396,7 +400,6 @@ public final class ConfigKeeper {
} }
public static abstract class Entry<T> { public static abstract class Entry<T> {
protected final T defaultValue; protected final T defaultValue;
protected Consumer<T> writer; protected Consumer<T> writer;
protected Supplier<T> reader; protected Supplier<T> reader;
@ -448,5 +451,9 @@ public final class ConfigKeeper {
public void setDefault() { public void setDefault() {
this.setValue(defaultValue); this.setValue(defaultValue);
} }
protected boolean hasDefaultInName() {
return true;
}
} }
} }

View file

@ -3,6 +3,9 @@ package ru.bclib.config;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import java.util.Collections;
public class Configs { public class Configs {
// Client and Server-Config must be the first entries. They are not part of the Auto-Sync process // Client and Server-Config must be the first entries. They are not part of the Auto-Sync process
@ -13,15 +16,22 @@ public class Configs {
public static final PathConfig GENERATOR_CONFIG = new PathConfig(BCLib.MOD_ID, "generator", false); 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 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 RECIPE_CONFIG = new PathConfig(BCLib.MOD_ID, "recipes");
public static final PathConfig BIOMES_CONFIG = new PathConfig(BCLib.MOD_ID, "biomes", false); public static final PathConfig BIOMES_CONFIG = new PathConfig(BCLib.MOD_ID, "biomes", false);
public static final String MAIN_PATCH_CATEGORY = "patches";
public static void save() { public static void save() {
MAIN_CONFIG.saveChanges(); MAIN_CONFIG.saveChanges();
RECIPE_CONFIG.saveChanges(); RECIPE_CONFIG.saveChanges();
GENERATOR_CONFIG.saveChanges(); GENERATOR_CONFIG.saveChanges();
initForcedConfig();
}
private static void initForcedConfig() {
BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("end_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST));
BIOMES_CONFIG.keeper.registerEntry(new ConfigKey("nether_biomes", "force_include"), new StringArrayEntry(Collections.EMPTY_LIST));
BIOMES_CONFIG.saveChanges(); BIOMES_CONFIG.saveChanges();
} }
} }

View file

@ -6,7 +6,6 @@ import ru.bclib.config.ConfigKeeper.FloatRange;
import ru.bclib.config.ConfigKeeper.IntegerRange; import ru.bclib.config.ConfigKeeper.IntegerRange;
public class PathConfig extends Config { public class PathConfig extends Config {
public PathConfig(String modID, String group, boolean autoSync, boolean diffContent) { public PathConfig(String modID, String group, boolean autoSync, boolean diffContent) {
super(modID, group, autoSync, diffContent); super(modID, group, autoSync, diffContent);
} }

View file

@ -14,7 +14,7 @@ import ru.bclib.world.generator.BCLibEndBiomeSource;
import ru.bclib.world.generator.BCLibNetherBiomeSource; import ru.bclib.world.generator.BCLibNetherBiomeSource;
import ru.bclib.world.generator.GeneratorOptions; import ru.bclib.world.generator.GeneratorOptions;
@Mixin(value = DimensionType.class, priority = 100) @Mixin(value = DimensionType.class, priority = 10)
public class DimensionTypeMixin { public class DimensionTypeMixin {
@Inject(method = "defaultNetherGenerator", at = @At("HEAD"), cancellable = true) @Inject(method = "defaultNetherGenerator", at = @At("HEAD"), cancellable = true)
private static void be_replaceNetherBiomeSource(Registry<Biome> biomeRegistry, Registry<NoiseGeneratorSettings> chunkGeneratorSettingsRegistry, long seed, CallbackInfoReturnable<ChunkGenerator> info) { private static void be_replaceNetherBiomeSource(Registry<Biome> biomeRegistry, Registry<NoiseGeneratorSettings> chunkGeneratorSettingsRegistry, long seed, CallbackInfoReturnable<ChunkGenerator> info) {

View file

@ -14,6 +14,7 @@ import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.synth.SimplexNoise; import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.noise.OpenSimplexNoise; import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
@ -87,8 +88,15 @@ public class BCLibEndBiomeSource extends BiomeSource {
} }
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) { private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "end_biomes", StringArrayEntry.class).getValue();
return biomeRegistry.stream().filter(biome -> { return biomeRegistry.stream().filter(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome); ResourceLocation key = biomeRegistry.getKey(biome);
if (include.contains(key.toString())) {
return true;
}
BCLBiome bclBiome = BiomeAPI.getBiome(key); BCLBiome bclBiome = BiomeAPI.getBiome(key);
if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome != BiomeAPI.EMPTY_BIOME) {
if (bclBiome.hasParentBiome()) { if (bclBiome.hasParentBiome()) {

View file

@ -10,6 +10,7 @@ import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.BiomeSource; import net.minecraft.world.level.biome.BiomeSource;
import ru.bclib.BCLib; import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI; import ru.bclib.api.BiomeAPI;
import ru.bclib.config.ConfigKeeper.StringArrayEntry;
import ru.bclib.config.Configs; import ru.bclib.config.Configs;
import ru.bclib.world.biomes.BCLBiome; import ru.bclib.world.biomes.BCLBiome;
@ -65,8 +66,15 @@ public class BCLibNetherBiomeSource extends BiomeSource {
} }
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) { private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue();
return biomeRegistry.stream().filter(biome -> { return biomeRegistry.stream().filter(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome); ResourceLocation key = biomeRegistry.getKey(biome);
if (include.contains(key.toString())) {
return true;
}
BCLBiome bclBiome = BiomeAPI.getBiome(key); BCLBiome bclBiome = BiomeAPI.getBiome(key);
if (bclBiome != BiomeAPI.EMPTY_BIOME) { if (bclBiome != BiomeAPI.EMPTY_BIOME) {
if (bclBiome.hasParentBiome()) { if (bclBiome.hasParentBiome()) {

View file

@ -14,6 +14,8 @@ public class GeneratorOptions {
private static boolean farEndBiomes = true; private static boolean farEndBiomes = true;
private static boolean customNetherBiomeSource = true; private static boolean customNetherBiomeSource = true;
private static boolean customEndBiomeSource = true; private static boolean customEndBiomeSource = true;
private static boolean addNetherBiomesByCategory = false;
private static boolean addEndBiomesByCategory = false;
public static void init() { public static void init() {
biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256); biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256);
@ -21,6 +23,8 @@ public class GeneratorOptions {
biomeSizeEndVoid = Configs.GENERATOR_CONFIG.getInt("end.biomeMap", "biomeSizeVoid", 256); biomeSizeEndVoid = Configs.GENERATOR_CONFIG.getInt("end.biomeMap", "biomeSizeVoid", 256);
customNetherBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customNetherBiomeSource", true); customNetherBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customNetherBiomeSource", true);
customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true); customEndBiomeSource = Configs.GENERATOR_CONFIG.getBoolean("options", "customEndBiomeSource", true);
addNetherBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addNetherBiomesByCategory", false);
addEndBiomesByCategory = Configs.GENERATOR_CONFIG.getBoolean("options", "addEndBiomesByCategory", false);
} }
public static int getBiomeSizeNether() { public static int getBiomeSizeNether() {
@ -58,4 +62,12 @@ public class GeneratorOptions {
public static boolean customEndBiomeSource() { public static boolean customEndBiomeSource() {
return customEndBiomeSource; return customEndBiomeSource;
} }
public static boolean addNetherBiomesByCategory() {
return addNetherBiomesByCategory;
}
public static boolean addEndBiomesByCategory() {
return addEndBiomesByCategory;
}
} }