77import net .minecraftforge .mcmaven .impl .GlobalOptions ;
88import net .minecraftforge .mcmaven .impl .mappings .Mappings ;
99import net .minecraftforge .mcmaven .impl .repo .mcpconfig .MCPSide ;
10- import net .minecraftforge .mcmaven .impl .util .Artifact ;
1110import net .minecraftforge .util .file .FileUtils ;
1211import net .minecraftforge .util .hash .HashFunction ;
1312import net .minecraftforge .util .hash .HashStore ;
1413import net .minecraftforge .mcmaven .impl .util .Task ;
14+ import net .minecraftforge .srgutils .IMappingFile ;
1515import net .minecraftforge .util .hash .HashUtils ;
1616import org .apache .commons .io .IOUtils ;
1717
2020import java .io .FileOutputStream ;
2121import java .io .IOException ;
2222import java .nio .charset .StandardCharsets ;
23+ import java .util .HashSet ;
24+ import java .util .Set ;
2325import java .util .zip .ZipInputStream ;
2426import java .util .zip .ZipOutputStream ;
2527
@@ -67,20 +69,23 @@ public String name() {
6769 private Task remapSources (Task input , File outputDir , Mappings provider ) {
6870 var output = new File (outputDir , !this .javadocs ? "remapped.jar" : "remapped-javadoc.jar" );
6971 var mappings = provider .getCsvZip (side );
72+ var srg = this .javadocs ? side .getTasks ().getMappings () : null ;
7073 return Task .named ("remap[" + this .name + "][" + provider + ']' + (!this .javadocs ? "" : "[javadoc]" ),
71- Task .deps (input , mappings ),
72- () -> remapSourcesImpl (input , mappings , output , javadocs )
74+ Task .deps (input , mappings , srg ),
75+ () -> remapSourcesImpl (input , mappings , output , srg )
7376 );
7477 }
7578
76- private static File remapSourcesImpl (Task inputTask , Task mappingsTask , File output , boolean javadocs ) {
79+ private static File remapSourcesImpl (Task inputTask , Task mappingsTask , File output , Task srgTask ) {
7780 var input = inputTask .execute ();
7881 var mappings = mappingsTask .execute ();
82+ var srg = srgTask == null ? null : srgTask .execute ();
7983
8084 var cache = HashStore .fromFile (output );
8185 cache .add ("input" , input );
8286 cache .add ("mappings" , mappings );
83- cache .add ("javadocs" , javadocs ? "true" : "false" );
87+ if (srg != null )
88+ cache .add ("whitelist" , srg );
8489
8590 if (output .exists () && cache .isSame ())
8691 return output ;
@@ -90,6 +95,16 @@ private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File out
9095 try {
9196 var names = MCPNames .load (mappings );
9297
98+ Set <String > vanillaClasses = null ;
99+ if (srg != null ) {
100+ vanillaClasses = new HashSet <>();
101+ var map = IMappingFile .load (srg );
102+ for (var cls : map .getClasses ()) {
103+ if (cls .getMapped ().indexOf ('$' ) == -1 ) // Outer classes only
104+ vanillaClasses .add (cls .getMapped () + ".java" );
105+ }
106+ }
107+
93108 // TODO: [MCMavenizer][Renamer] This garbage was copy-pasted from FG.
94109 // I changed the while loop to a for loop, though. I guess it is fine?
95110 FileUtils .ensureParent (output );
@@ -99,6 +114,8 @@ private static File remapSourcesImpl(Task inputTask, Task mappingsTask, File out
99114 zout .putNextEntry (FileUtils .getStableEntry (entry .getName ()));
100115
101116 if (entry .getName ().endsWith (".java" )) {
117+ // We only care about injecting javadocs into decompiled classes, patcher classes should have their own docs
118+ var javadocs = vanillaClasses != null && vanillaClasses .contains (entry .getName ());
102119 var mapped = names .rename (zin , javadocs , javadocs );
103120 IOUtils .write (mapped , zout , StandardCharsets .UTF_8 );
104121 } else {
0 commit comments