1212import net .minecraftforge .gradle .common .util .MinecraftRepo ;
1313import net .minecraftforge .gradle .common .util .Utils ;
1414import net .minecraftforge .srgutils .IMappingFile ;
15+ import net .minecraftforge .srgutils .MinecraftVersion ;
1516import org .gradle .api .Project ;
1617import org .jetbrains .annotations .Nullable ;
1718
1819import java .io .File ;
1920import java .io .FileOutputStream ;
2021import java .io .IOException ;
22+ import java .nio .charset .StandardCharsets ;
2123import java .util .ArrayList ;
2224import java .util .List ;
2325import java .util .Map ;
2426import java .util .Set ;
2527import java .util .TreeMap ;
28+ import java .util .zip .ZipEntry ;
2629import java .util .zip .ZipOutputStream ;
2730
2831class OfficialChannelProvider implements ChannelProvider {
@@ -40,6 +43,46 @@ public File getMappingsFile(MCPRepo mcpRepo, Project project, String channel, St
4043 //mcpversion = version.substring(idx);
4144 version = version .substring (0 , idx );
4245 }
46+ if (!Utils .isObfuscated (version )) {
47+ // We are in uobfuscated territory, so return an empty zip
48+ return emptyFile (mcpRepo , mcpversion );
49+ } else {
50+ return getCsvFile (mcpRepo , project , version , mcpversion );
51+ }
52+ }
53+
54+ private File emptyFile (MCPRepo mcpRepo , String mcpversion ) throws IOException {
55+ File mcp = mcpRepo .getMCP (mcpversion );
56+ if (mcp == null )
57+ return null ;
58+
59+ File mappings = mcpRepo .cacheMC ("mapping" , mcpversion , "mapping" , "zip" );
60+ HashStore cache = mcpRepo .commonHash (mcp )
61+ .load (mcpRepo .cacheMC ("mapping" , mcpversion , "mapping" , "zip.input" ));
62+
63+ if (!cache .isSame () || !mappings .exists ()) {
64+ if (!mappings .getParentFile ().exists ())
65+ mappings .getParentFile ().mkdirs ();
66+
67+ byte [] header = String .join ("," , "searge" , "name" , "side" , "desc" ).getBytes (StandardCharsets .UTF_8 );
68+
69+ try (FileOutputStream fos = new FileOutputStream (mappings );
70+ ZipOutputStream out = new ZipOutputStream (fos )) {
71+ out .putNextEntry (Utils .getStableEntry ("fields.csv" ));
72+ out .write (header );
73+ out .closeEntry ();
74+ out .putNextEntry (Utils .getStableEntry ("methods.csv" ));
75+ out .write (header );
76+ out .closeEntry ();
77+ }
78+
79+ cache .save ();
80+ Utils .updateHash (mappings , HashFunction .SHA1 );
81+ }
82+ return mappings ;
83+ }
84+
85+ private File getCsvFile (MCPRepo mcpRepo , Project project , String version , String mcpversion ) throws IOException {
4386 File client = MavenArtifactDownloader .generate (project , "net.minecraft:client:" + version + ":mappings@txt" , true );
4487 File server = MavenArtifactDownloader .generate (project , "net.minecraft:server:" + version + ":mappings@txt" , true );
4588 if (client == null || server == null )
0 commit comments