use of gg.moonflower.pollen.pinwheel.api.client.FileCache 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);
}
Aggregations