use of io.github.lukebemish.excavated_variants.api.IOreListModifier in project excavated_variants by lukebemish.
the class ExcavatedVariants method internalSetupMap.
private static synchronized void internalSetupMap(Collection<String> modids) {
// Yeah, yeah, I don't like static synchronized either. This way, though, it should only ever fire once, since
// this is an internal method and only ever locks if the list is null or empty. And I don't really want to
// build the list more than once, since that causes issues, so...
oreStoneList = new ArrayList<>();
Map<String, BaseStone> stoneMap = new HashMap<>();
Map<String, List<BaseOre>> oreMap = new HashMap<>();
for (ModData mod : ExcavatedVariants.getConfig().mods) {
if (modids.containsAll(mod.mod_id)) {
for (BaseStone stone : mod.provided_stones) {
if (!ExcavatedVariants.getConfig().blacklist_stones.contains(stone.id)) {
stoneMap.put(stone.id, stone);
}
}
for (BaseOre ore : mod.provided_ores) {
if (!ExcavatedVariants.getConfig().blacklist_ores.contains(ore.id)) {
oreMap.computeIfAbsent(ore.id, k -> new ArrayList<>());
oreMap.get(ore.id).add(ore);
}
}
}
}
for (String id : oreMap.keySet()) {
List<BaseOre> oreList = oreMap.get(id);
List<String> stones = new ArrayList<>();
for (BaseOre ore : oreList) {
stones.addAll(ore.stone);
}
Pair<BaseOre, HashSet<BaseStone>> pair = new Pair<>(oreList.get(0).clone(), new HashSet<>());
if (oreList.size() > 1) {
pair.first().block_id = new ArrayList<>();
pair.first().orename = new ArrayList<>();
pair.first().stone = new ArrayList<>();
pair.first().types = new ArrayList<>();
for (BaseOre baseOre : oreList) {
pair.first().block_id.addAll(baseOre.block_id);
pair.first().orename.addAll(baseOre.orename);
pair.first().stone.addAll(baseOre.stone);
pair.first().types.addAll(baseOre.types);
}
List<String> types = new HashSet<>(pair.first().types).stream().toList();
pair.first().types.clear();
pair.first().types.addAll(types);
List<String> orenames = new HashSet<>(pair.first().orename).stream().toList();
pair.first().orename.clear();
pair.first().orename.addAll(orenames);
}
oreStoneList.add(pair);
for (BaseStone stone : stoneMap.values()) {
if (!stones.contains(stone.id) && oreList.stream().anyMatch(x -> x.types.stream().anyMatch(stone.types::contains))) {
String full_id = stone.id + "_" + id;
if (!ExcavatedVariants.getConfig().blacklist_ids.contains(full_id)) {
pair.last().add(stone);
}
}
}
}
var listListeners = Services.COMPAT.getOreListModifiers();
for (IOreListModifier listListener : listListeners) {
oreStoneList = listListener.modify(oreStoneList, stoneMap.values());
}
HashSet<String> done_ids = new HashSet<>();
ArrayList<Pair<BaseOre, HashSet<BaseStone>>> out = new ArrayList<>();
for (Pair<BaseOre, HashSet<BaseStone>> p : oreStoneList) {
BaseOre ore = p.first();
if (!done_ids.contains(ore.id)) {
done_ids.add(ore.id);
Pair<BaseOre, HashSet<BaseStone>> o = new Pair<>(ore, new HashSet<>());
out.add(o);
for (BaseStone stone : p.last()) {
String full_id = stone.id + "_" + ore.id;
if (!ExcavatedVariants.getConfig().blacklist_ids.contains(full_id)) {
o.last().add(stone);
}
}
}
}
oreStoneList = out;
}
Aggregations