Guest User

AssetsLoaderHelper

a guest
Sep 11th, 2019
785
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.05 KB | None | 0 0
  1. public final class AssetsLoaderHelper
  2. {
  3.     public static void loadAndProcessAssets(String directory, String extension, Consumer<Path> processor)
  4.     {
  5.         String PATH = "assets/" + Reference.MOD_ID + "/" + directory;
  6.  
  7.         ModContainer containerMageTech = FMLCommonHandler.instance().findContainerFor(MageTech.INSTANCE);
  8.         File sourceMageTech = containerMageTech.getSource();
  9.  
  10.         try
  11.         {
  12.             FileSystem fileSystemMageTech = FileSystems.newFileSystem(sourceMageTech.toPath(), null);
  13.             Path pathDirectory = fileSystemMageTech.getPath("/" + PATH);
  14.  
  15.             Iterator<Path> iterator = Files.walk(pathDirectory).iterator();
  16.  
  17.             while (iterator.hasNext())
  18.             {
  19.                 Path pathFile = iterator.next();
  20.  
  21.                 if (pathFile.toString().endsWith(extension))
  22.                     processor.accept(pathFile);
  23.             }
  24.  
  25.             IOUtils.closeQuietly(fileSystemMageTech);
  26.         }
  27.  
  28.         catch (IOException e)
  29.         {
  30.             LogHelper.error(e);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment