package org.betterx.bclib.config; import org.betterx.bclib.BCLib; import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI; import java.util.*; public class BiomesConfig extends PathConfig { private Map> BIOME_INCLUDE_LIST = null; private Map> BIOME_EXCLUDE_LIST = null; public static final BiomeAPI.BiomeType[] endTypes = { BiomeAPI.BiomeType.END_LAND, BiomeAPI.BiomeType.END_VOID, BiomeAPI.BiomeType.END_CENTER, BiomeAPI.BiomeType.END_BARRENS }; public static final BiomeAPI.BiomeType[] netherTypes = { BiomeAPI.BiomeType.NETHER }; private static final BiomeAPI.BiomeType[] includeTypes = all(); private static final BiomeAPI.BiomeType[] excludeTypes = {BiomeAPI.BiomeType.NETHER, BiomeAPI.BiomeType.END}; public BiomesConfig() { super(BCLib.MOD_ID, "biomes", true); for (var type : includeTypes) { keeper.registerEntry( new ConfigKey(type.getName(), "force_include"), new ConfigKeeper.StringArrayEntry(Collections.EMPTY_LIST) ); } for (var type : excludeTypes) { keeper.registerEntry( new ConfigKey(type.getName(), "force_exclude"), new ConfigKeeper.StringArrayEntry(Collections.EMPTY_LIST) ); } } private static BiomeAPI.BiomeType[] all() { BiomeAPI.BiomeType[] res = new BiomeAPI.BiomeType[endTypes.length + netherTypes.length]; System.arraycopy(netherTypes, 0, res, 0, netherTypes.length); System.arraycopy(endTypes, 0, res, netherTypes.length, endTypes.length); return res; } private List getBiomeIncludeList(BiomeAPI.BiomeType type) { var entry = getEntry( "force_include", type.getName(), ConfigKeeper.StringArrayEntry.class ); if (entry == null) return List.of(); return entry.getValue(); } private List getBiomeExcludeList(BiomeAPI.BiomeType type) { var entry = getEntry( "force_exclude", type.getName(), ConfigKeeper.StringArrayEntry.class ); if (entry == null) return List.of(); return entry.getValue(); } public List getIncludeMatching(BiomeAPI.BiomeType type) { return getBiomeIncludeMap().entrySet() .stream() .filter(e -> e.getKey().is(type)) .map(e -> e.getValue()) .flatMap(Collection::stream) .toList(); } public List getExcludeMatching(BiomeAPI.BiomeType type) { return getBiomeExcludeMap().entrySet() .stream() .filter(e -> e.getKey().is(type)) .map(e -> e.getValue()) .flatMap(Collection::stream) .toList(); } public Map> getBiomeIncludeMap() { if (BIOME_INCLUDE_LIST == null) { BIOME_INCLUDE_LIST = new HashMap<>(); for (BiomeAPI.BiomeType type : includeTypes) { BIOME_INCLUDE_LIST.put(type, getBiomeIncludeList(type)); } } return BIOME_INCLUDE_LIST; } public Map> getBiomeExcludeMap() { if (BIOME_EXCLUDE_LIST == null) { BIOME_EXCLUDE_LIST = new HashMap<>(); for (BiomeAPI.BiomeType type : excludeTypes) { BIOME_EXCLUDE_LIST.put(type, getBiomeExcludeList(type)); } } return BIOME_EXCLUDE_LIST; } }