use of net.modificationstation.stationapi.api.client.resource.Resource in project StationAPI by ModificationStation.
the class SpriteAtlasTexture method loadSprites.
private Collection<Sprite.Info> loadSprites(TexturePack resourceManager, Set<Identifier> ids) {
ArrayList<CompletableFuture<Void>> list = new ArrayList<>();
ConcurrentLinkedQueue<Sprite.Info> concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
for (Identifier identifier : ids) {
if (MissingSprite.getMissingSpriteId().equals(identifier))
continue;
list.add(CompletableFuture.runAsync(() -> {
Sprite.Info info3;
Identifier identifier2 = this.getTexturePath(identifier);
try (Resource resource = Resource.of(resourceManager.getResourceAsStream(ResourceManager.ASSETS.toPath(identifier2)))) {
BufferedImage image = ImageIO.read(resource.getInputStream());
AnimationResourceMetadata animationResourceMetadata = resource.getMetadata(AnimationResourceMetadata.READER);
if (animationResourceMetadata == null)
animationResourceMetadata = AnimationResourceMetadata.EMPTY;
Pair<Integer, Integer> pair = animationResourceMetadata.getResolution(image.getWidth(), image.getHeight());
info3 = new Sprite.Info(identifier, pair.getFirst(), pair.getSecond(), animationResourceMetadata);
} catch (RuntimeException runtimeException) {
LOGGER.error("Unable to parse metadata from {} : {}", identifier2, runtimeException);
return;
} catch (IOException iOException) {
LOGGER.error("Using missing texture, unable to load {} : {}", identifier2, iOException);
return;
}
concurrentLinkedQueue.add(info3);
}, Util.getMainWorkerExecutor()));
}
CompletableFuture.allOf(list.toArray(new CompletableFuture[0])).join();
return concurrentLinkedQueue;
}
Aggregations