Search in sources :

Example 1 with ModelEntitlement

use of gg.moonflower.pollen.core.client.entitlement.ModelEntitlement in project pollen by MoonflowerTeam.

the class CosmeticModelLoader method reload.

@Override
public CompletableFuture<Map<ResourceLocation, GeometryModel>> reload(ResourceManager resourceManager, Executor backgroundExecutor, Executor gameExecutor) {
    ExecutorService executor = FileCache.createOnlineWorker();
    FileCache cache = FileCache.timed(executor, 1, TimeUnit.DAYS);
    Map<ResourceLocation, GeometryModel> models = new ConcurrentHashMap<>();
    return CompletableFuture.allOf(EntitlementManager.getAllEntitlements().filter(entitlement -> entitlement instanceof ModelEntitlement).flatMap(entitlement -> Arrays.stream(((ModelEntitlement) entitlement).getModelUrls())).distinct().map(url -> loadModel(cache, url).thenAcceptAsync(json -> {
        if (json == null)
            return;
        try {
            for (GeometryModelData model : GeometryModelParser.parseModel(json)) {
                ResourceLocation id = new ResourceLocation(Pollen.MOD_ID, model.getDescription().getIdentifier());
                if (models.put(id, GeometryModel.create(model)) != null)
                    LOGGER.warn("Duplicate geometry model with id: " + id);
            }
        } catch (Exception e) {
            LOGGER.error("Failed to parse cosmetic model: " + json, e);
        }
    }, gameExecutor)).toArray(CompletableFuture[]::new)).thenApplyAsync(__ -> {
        executor.shutdown();
        try {
            if (!executor.awaitTermination(10, TimeUnit.SECONDS))
                LOGGER.warn("Took more than 10 seconds to terminate online worker");
        } catch (Exception e) {
            LOGGER.error("Failed to terminate online worker", e);
        }
        return models;
    }, gameExecutor);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) Platform(gg.moonflower.pollen.api.platform.Platform) Arrays(java.util.Arrays) BackgroundLoader(gg.moonflower.pollen.pinwheel.api.common.util.BackgroundLoader) java.util.concurrent(java.util.concurrent) EntitlementManager(gg.moonflower.pollen.core.client.entitlement.EntitlementManager) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) FileInputStream(java.io.FileInputStream) JsonParser(com.google.gson.JsonParser) Pollen(gg.moonflower.pollen.core.Pollen) FileCache(gg.moonflower.pollen.pinwheel.api.client.FileCache) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) InputStreamReader(java.io.InputStreamReader) GeometryModelParser(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) ModelEntitlement(gg.moonflower.pollen.core.client.entitlement.ModelEntitlement) LogManager(org.apache.logging.log4j.LogManager) GeometryModel(gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel) ResourceLocation(net.minecraft.resources.ResourceLocation) ModelEntitlement(gg.moonflower.pollen.core.client.entitlement.ModelEntitlement) GeometryModelData(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData) FileCache(gg.moonflower.pollen.pinwheel.api.client.FileCache)

Aggregations

JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 Platform (gg.moonflower.pollen.api.platform.Platform)1 Pollen (gg.moonflower.pollen.core.Pollen)1 EntitlementManager (gg.moonflower.pollen.core.client.entitlement.EntitlementManager)1 ModelEntitlement (gg.moonflower.pollen.core.client.entitlement.ModelEntitlement)1 FileCache (gg.moonflower.pollen.pinwheel.api.client.FileCache)1 GeometryModel (gg.moonflower.pollen.pinwheel.api.client.geometry.GeometryModel)1 GeometryModelData (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelData)1 GeometryModelParser (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser)1 BackgroundLoader (gg.moonflower.pollen.pinwheel.api.common.util.BackgroundLoader)1 FileInputStream (java.io.FileInputStream)1 InputStreamReader (java.io.InputStreamReader)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 java.util.concurrent (java.util.concurrent)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 ResourceManager (net.minecraft.server.packs.resources.ResourceManager)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1