tterrag1098

Untitled

Dec 5th, 2019
477
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.58 KB | None | 0 0
  1.  src/fmllauncher/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java
  2. index defe1005e..122c4c75a 100644
  3. @@ -92,7 +92,7 @@ public class ModFile implements IModFile {
  4.      private List<CoreModFile> coreMods;
  5.      private Path accessTransformer;
  6.  
  7. -    private static final Attributes.Name TYPE = new Attributes.Name("FMLModType");
  8. +    public static final Attributes.Name TYPE = new Attributes.Name("FMLModType");
  9.  
  10.      public ModFile(final Path file, final IModLocator locator) {
  11.          this.locator = locator;
  12.  
  13. ------ src/userdev/java/net/minecraftforge/userdev/ClasspathLocator.java ------
  14. index 2c7f2e74c..2d4cec3f2 100644
  15. @@ -25,24 +25,27 @@ import java.io.IOException;
  16.  import java.net.URL;
  17.  import java.nio.file.Files;
  18.  import java.nio.file.Path;
  19. -import java.util.ArrayList;
  20.  import java.util.Enumeration;
  21. +import java.util.LinkedHashSet;
  22.  import java.util.List;
  23.  import java.util.Map;
  24. +import java.util.Set;
  25.  import java.util.stream.Collectors;
  26.  
  27. -import net.minecraftforge.forgespi.locating.IModFile;
  28. +import org.antlr.v4.runtime.misc.Predicate;
  29.  import org.apache.logging.log4j.LogManager;
  30.  import org.apache.logging.log4j.Logger;
  31.  
  32.  import net.minecraftforge.fml.loading.LibraryFinder;
  33.  import net.minecraftforge.fml.loading.moddiscovery.AbstractJarFileLocator;
  34.  import net.minecraftforge.fml.loading.moddiscovery.ModFile;
  35. +import net.minecraftforge.forgespi.locating.IModFile;
  36.  
  37.  public class ClasspathLocator extends AbstractJarFileLocator {
  38.      private static final Logger LOGGER = LogManager.getLogger();
  39.      private static final String MODS_TOML = "META-INF/mods.toml";
  40. -    private List<Path> modCoords;
  41. +    private static final String MANIFEST = "META-INF/MANIFEST.MF";
  42. +    private Set<Path> modCoords;
  43.  
  44.      @Override
  45.      public List<IModFile> scanMods() {
  46. @@ -60,20 +63,27 @@ public class ClasspathLocator extends AbstractJarFileLocator {
  47.      @Override
  48.      public void initArguments(Map<String, ?> arguments) {
  49.          try {
  50. -            modCoords = new ArrayList<>();
  51. -            final Enumeration<URL> resources = ClassLoader.getSystemClassLoader().getResources(MODS_TOML);
  52. -            while (resources.hasMoreElements()) {
  53. -                URL url = resources.nextElement();
  54. -                Path path = LibraryFinder.findJarPathFor(MODS_TOML, "classpath_mod", url);
  55. -                if (Files.isDirectory(path))
  56. -                    continue;
  57. +            modCoords = new LinkedHashSet<>();
  58. +            locateMods(MODS_TOML, $ -> true);
  59. +            locateMods(MANIFEST, path -> findManifest(path).map(m -> m.getMainAttributes().getValue(ModFile.TYPE)).isPresent());
  60. +        } catch (IOException e) {
  61. +            LOGGER.fatal(CORE,"Error trying to find resources", e);
  62. +            throw new RuntimeException("wha?", e);
  63. +        }
  64. +    }
  65. +    
  66. +    private void locateMods(String resource, Predicate<Path> filter) throws IOException {
  67. +        final Enumeration<URL> modsTomls = ClassLoader.getSystemClassLoader().getResources(MODS_TOML);
  68. +        while (modsTomls.hasMoreElements()) {
  69. +            URL url = modsTomls.nextElement();
  70. +            Path path = LibraryFinder.findJarPathFor(MODS_TOML, "classpath_mod", url);
  71. +            if (Files.isDirectory(path))
  72. +                continue;
  73.  
  74. +            if (filter.test(path)) {
  75.                  LOGGER.debug(CORE, "Found classpath mod: {}", path);
  76.                  this.modCoords.add(path);
  77.              }
  78. -        } catch (IOException e) {
  79. -            LOGGER.fatal(CORE,"Error trying to find resources", e);
  80. -            throw new RuntimeException("wha?", e);
  81.          }
  82.      }
  83.  }
Advertisement
Add Comment
Please, Sign In to add comment