Search in sources :

Example 1 with IOreListModifier

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;
}
Also used : OreConversionRecipe(io.github.lukebemish.excavated_variants.recipe.OreConversionRecipe) ResourceLocation(net.minecraft.resources.ResourceLocation) NoneFeatureConfiguration(net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration) java.util(java.util) BaseStone(io.github.lukebemish.excavated_variants.data.BaseStone) Item(net.minecraft.world.item.Item) BiFunction(java.util.function.BiFunction) Pair(io.github.lukebemish.excavated_variants.util.Pair) Supplier(java.util.function.Supplier) DynAssetGeneratorServerAPI(io.github.lukebemish.dynamic_asset_generator.api.DynAssetGeneratorServerAPI) Services(io.github.lukebemish.excavated_variants.platform.Services) BiConsumer(java.util.function.BiConsumer) BaseOre(io.github.lukebemish.excavated_variants.data.BaseOre) BlockItem(net.minecraft.world.item.BlockItem) RecipeSerializer(net.minecraft.world.item.crafting.RecipeSerializer) IOreListModifier(io.github.lukebemish.excavated_variants.api.IOreListModifier) SimpleRecipeSerializer(net.minecraft.world.item.crafting.SimpleRecipeSerializer) ClientServices(io.github.lukebemish.excavated_variants.client.ClientServices) ConfiguredFeature(net.minecraft.world.level.levelgen.feature.ConfiguredFeature) Logger(org.apache.logging.log4j.Logger) PlacedFeature(net.minecraft.world.level.levelgen.placement.PlacedFeature) ModConfig(io.github.lukebemish.excavated_variants.data.ModConfig) Block(net.minecraft.world.level.block.Block) LogManager(org.apache.logging.log4j.LogManager) ModData(io.github.lukebemish.excavated_variants.data.ModData) ModData(io.github.lukebemish.excavated_variants.data.ModData) BaseStone(io.github.lukebemish.excavated_variants.data.BaseStone) BaseOre(io.github.lukebemish.excavated_variants.data.BaseOre) IOreListModifier(io.github.lukebemish.excavated_variants.api.IOreListModifier) Pair(io.github.lukebemish.excavated_variants.util.Pair)

Aggregations

DynAssetGeneratorServerAPI (io.github.lukebemish.dynamic_asset_generator.api.DynAssetGeneratorServerAPI)1 IOreListModifier (io.github.lukebemish.excavated_variants.api.IOreListModifier)1 ClientServices (io.github.lukebemish.excavated_variants.client.ClientServices)1 BaseOre (io.github.lukebemish.excavated_variants.data.BaseOre)1 BaseStone (io.github.lukebemish.excavated_variants.data.BaseStone)1 ModConfig (io.github.lukebemish.excavated_variants.data.ModConfig)1 ModData (io.github.lukebemish.excavated_variants.data.ModData)1 Services (io.github.lukebemish.excavated_variants.platform.Services)1 OreConversionRecipe (io.github.lukebemish.excavated_variants.recipe.OreConversionRecipe)1 Pair (io.github.lukebemish.excavated_variants.util.Pair)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1 BiFunction (java.util.function.BiFunction)1 Supplier (java.util.function.Supplier)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 BlockItem (net.minecraft.world.item.BlockItem)1 Item (net.minecraft.world.item.Item)1 RecipeSerializer (net.minecraft.world.item.crafting.RecipeSerializer)1 SimpleRecipeSerializer (net.minecraft.world.item.crafting.SimpleRecipeSerializer)1 Block (net.minecraft.world.level.block.Block)1