Search in sources :

Example 1 with ModData

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);
}
Also used : ModData(io.github.lukebemish.excavated_variants.data.ModData) BaseStone(io.github.lukebemish.excavated_variants.data.BaseStone) BaseOre(io.github.lukebemish.excavated_variants.data.BaseOre) ResourceLocation(net.minecraft.resources.ResourceLocation) Pair(io.github.lukebemish.excavated_variants.util.Pair)

Example 2 with ModData

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;
}
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

BaseOre (io.github.lukebemish.excavated_variants.data.BaseOre)2 BaseStone (io.github.lukebemish.excavated_variants.data.BaseStone)2 ModData (io.github.lukebemish.excavated_variants.data.ModData)2 Pair (io.github.lukebemish.excavated_variants.util.Pair)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 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 ModConfig (io.github.lukebemish.excavated_variants.data.ModConfig)1 Services (io.github.lukebemish.excavated_variants.platform.Services)1 OreConversionRecipe (io.github.lukebemish.excavated_variants.recipe.OreConversionRecipe)1 java.util (java.util)1 BiConsumer (java.util.function.BiConsumer)1 BiFunction (java.util.function.BiFunction)1 Supplier (java.util.function.Supplier)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