use of io.github.lukebemish.excavated_variants.data.ModData in project excavated_variants by lukebemish.
the class ExcavatedVariantsClient method init.
public static void init() {
LangBuilder langBuilder = new LangBuilder();
Collection<String> modids = Services.PLATFORM.getModIds();
// Texture/asset extraction. Not shared with common code, so it's not visible from the oreStoneList.
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);
}
}
}
}
List<String> extractedOres = new ArrayList<>();
Map<String, Pair<BaseOre, BaseStone>> extractorMap = new HashMap<>();
for (ModData mod : ExcavatedVariants.getConfig().mods) {
if (modids.containsAll(mod.mod_id)) {
Map<String, BaseStone> internalStoneMap = new HashMap<>();
for (BaseStone stone : mod.provided_stones) {
if (!ExcavatedVariants.getConfig().blacklist_stones.contains(stone.id)) {
internalStoneMap.put(stone.id, stone);
}
}
for (BaseOre ore : mod.provided_ores) {
if (!extractedOres.contains(ore.id)) {
for (String stone_id : ore.stone) {
if (internalStoneMap.get(stone_id) != null && extractorMap.get(ore.id) == null) {
var extractor = new Pair<>(ore, internalStoneMap.get(stone_id));
extractorMap.put(ore.id, extractor);
} else if (stoneMap.get(stone_id) != null && extractorMap.get(ore.id) == null) {
var extractor = new Pair<>(ore, stoneMap.get(stone_id));
extractorMap.put(ore.id, extractor);
}
}
extractedOres.add(ore.id);
}
}
}
}
for (List<BaseOre> oreList : oreMap.values()) {
BaseOre ore = oreList.get(0);
for (String stone_id : ore.stone) {
if (stoneMap.get(stone_id) != null && extractorMap.get(ore.id) == null) {
var extractor = new Pair<>(ore, stoneMap.get(stone_id));
extractorMap.put(ore.id, extractor);
}
}
}
List<Pair<BaseOre, BaseStone>> to_make = new ArrayList<>();
ExcavatedVariants.setupMap();
for (Pair<BaseOre, HashSet<BaseStone>> p : ExcavatedVariants.oreStoneList) {
var ore = p.first();
for (BaseStone stone : p.last()) {
String full_id = stone.id + "_" + ore.id;
to_make.add(new Pair<>(ore, stone));
DynAssetGeneratorClientAPI.planLoadingStream(new ResourceLocation(ExcavatedVariants.MOD_ID, "models/item/" + full_id + ".json"), JsonHelper.getItemModel(full_id));
langBuilder.add(full_id, stone, ore);
}
}
DynAssetGeneratorClientAPI.planLoadingStream(new ResourceLocation(ExcavatedVariants.MOD_ID, "lang/en_us.json"), langBuilder.build());
BlockStateAssembler.setupClientAssets(extractorMap.values(), to_make);
}
use of io.github.lukebemish.excavated_variants.data.ModData 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