Skip to content

Commit 3775e9d

Browse files
committed
Bump tools for java 25
Disable reobf behavior by default for 1.20.5+ Add more descriptive error messages Fix OfficialChannelProvider for modern versions
1 parent 2fec3fd commit 3775e9d

10 files changed

Lines changed: 82 additions & 10 deletions

File tree

settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ dependencyResolutionManagement.versionCatalogs.register('libs') {
5353
library 'unsafe', 'net.minecraftforge:unsafe:0.2.0'
5454
library 'maven-artifact', 'org.apache.maven:maven-artifact:3.9.1'
5555
library 'httpclient', 'org.apache.httpcomponents:httpclient:4.5.14'
56-
library 'srgutils', 'net.minecraftforge:srgutils:0.5.10'
56+
library 'srgutils', 'net.minecraftforge:srgutils:0.6.2'
5757
library 'diffpatch', 'net.minecraftforge:DiffPatch:2.0.12'
5858

5959
library 'jarjar-metadata', 'net.minecraftforge:JarJarMetadata:0.3.19'

src/common/java/net/minecraftforge/gradle/common/config/MCPConfigV2.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
package net.minecraftforge.gradle.common.config;
77

8+
import com.google.gson.JsonSyntaxException;
89
import net.minecraftforge.gradle.common.util.Utils;
910
import org.apache.commons.io.IOUtils;
1011
import org.jetbrains.annotations.Nullable;
@@ -51,6 +52,8 @@ public static MCPConfigV2 getFromArchive(File path) throws IOException {
5152
}
5253

5354
return config;
55+
} catch (JsonSyntaxException e) {
56+
throw new IllegalStateException("Invalid MCP Config: " + path.getAbsolutePath() + " Json Exception", e);
5457
}
5558
}
5659

src/common/java/net/minecraftforge/gradle/common/config/UserdevConfigV1.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.HashMap;
1818
import java.util.List;
1919
import java.util.Map;
20+
import java.util.TreeMap;
2021

2122
public class UserdevConfigV1 extends Config {
2223
public static UserdevConfigV1 get(InputStream stream) {
@@ -94,7 +95,7 @@ public void addLibrary(String value) {
9495
}
9596
public void addRun(String name, RunConfig value) {
9697
if (this.runs == null)
97-
this.runs = new HashMap<>();
98+
this.runs = new TreeMap<>();
9899
this.runs.put(name, value);
99100
}
100101

src/common/java/net/minecraftforge/gradle/common/util/Utils.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.minecraftforge.gradle.common.tasks.ide.CopyIntellijResources;
2121
import net.minecraftforge.gradle.common.util.VersionJson.Download;
2222
import net.minecraftforge.gradle.common.util.runs.RunConfigGenerator;
23+
import net.minecraftforge.srgutils.MinecraftVersion;
2324
import org.apache.commons.io.FileUtils;
2425
import org.apache.commons.io.IOUtils;
2526
import org.gradle.api.Action;
@@ -86,10 +87,10 @@ public class Utils {
8687
public static final String MOJANG_MAVEN = "https://libraries.minecraft.net/";
8788
public static final String SPECIALSOURCE = "net.md-5:SpecialSource:1.11.2:shaded";
8889
public static final String BINPATCHER = art("binarypatcher", "1.2.0", "fatjar");
89-
public static final String ACCESSTRANSFORMER = art("accesstransformers", "8.2.1", "fatjar");
90-
public static final String FART = art("ForgeAutoRenamingTool", "1.0.6", "all" );
90+
public static final String ACCESSTRANSFORMER = art("accesstransformers", "8.2.14", "fatjar");
91+
public static final String FART = art("renamer", "2.0.4", "all" );
9192
public static final String SRG2SOURCE = art("Srg2Source", "8.0.9", "fatjar");
92-
public static final String SIDESTRIPPER = art("mergetool", "1.1.7", "fatjar");
93+
public static final String SIDESTRIPPER = art("mergetool", "1.2.5", "fatjar");
9394
public static final String INSTALLERTOOLS = art("installertools", "1.4.4", "fatjar");
9495
public static final String JARCOMPATIBILITYCHECKER = art("JarCompatibilityChecker", "0.1.28", "all" );
9596

@@ -541,4 +542,14 @@ public static void setupIDEResourceCopy(final Project project) {
541542
public static String getIntellijOutName(final SourceSet sourceSet) {
542543
return sourceSet.getName().equals(SourceSet.MAIN_SOURCE_SET_NAME) ? "production" : sourceSet.getName();
543544
}
545+
546+
private static final MinecraftVersion OFFICIAL_RUNTIME_START = MinecraftVersion.from("1.21.5");
547+
public static boolean isOfficialRuntime(String version) {
548+
return MinecraftVersion.from(version).compareTo(OFFICIAL_RUNTIME_START) >= 0;
549+
}
550+
551+
private static final MinecraftVersion UNOBFED_START = MinecraftVersion.from("26.1-snapshot-1");
552+
public static boolean isObfuscated(String version) {
553+
return MinecraftVersion.from(version).compareTo(UNOBFED_START) < 0;
554+
}
544555
}

src/mcp/java/net/minecraftforge/gradle/mcp/OfficialChannelProvider.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,20 @@
1212
import net.minecraftforge.gradle.common.util.MinecraftRepo;
1313
import net.minecraftforge.gradle.common.util.Utils;
1414
import net.minecraftforge.srgutils.IMappingFile;
15+
import net.minecraftforge.srgutils.MinecraftVersion;
1516
import org.gradle.api.Project;
1617
import org.jetbrains.annotations.Nullable;
1718

1819
import java.io.File;
1920
import java.io.FileOutputStream;
2021
import java.io.IOException;
22+
import java.nio.charset.StandardCharsets;
2123
import java.util.ArrayList;
2224
import java.util.List;
2325
import java.util.Map;
2426
import java.util.Set;
2527
import java.util.TreeMap;
28+
import java.util.zip.ZipEntry;
2629
import java.util.zip.ZipOutputStream;
2730

2831
class 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)

src/mcp/java/net/minecraftforge/gradle/mcp/tasks/DownloadMCPConfig.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public void downloadMCPConfig() throws IOException {
2424
File file = getConfigFile();
2525
File output = getOutput().get().getAsFile();
2626

27+
if (file == null)
28+
throw new IllegalStateException("Failed to download MCPConfig: " + getConfig().get());
29+
2730
if (output.exists()) {
2831
if (FileUtils.contentEquals(file, output)) {
2932
// NO-OP: The contents of both files are the same, we're up to date

src/patcher/java/net/minecraftforge/gradle/patcher/PatcherPlugin.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,11 @@ public void apply(Project project) {
633633
extension.getRuns().forEach(runConfig -> runConfig.tokens(tokens));
634634
if (extension.getCopyIdeResources().get() == Boolean.TRUE)
635635
Utils.setupIDEResourceCopy(project); // We need to have the copy resources task BEFORE the run config ones so we can detect them
636-
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets, createSrg2Mcp);
636+
637+
if (Utils.isObfuscated(extension.getMcVersion().get()))
638+
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets, createSrg2Mcp);
639+
else
640+
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets);
637641
});
638642
}
639643

src/userdev/java/net/minecraftforge/gradle/userdev/MinecraftUserRepo.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ public void validate(Configuration cfg, Map<String, RunConfig> runs, ExtractNati
249249
tokens.put("mc_version", mcp.getMCVersion());
250250
tokens.put("mcp_version", mcp.getArtifact().getVersion());
251251
tokens.put("mcp_mappings", MAPPING);
252-
tokens.put("mcp_to_srg", createSrgToMcp.getOutput().get().getAsFile().getAbsolutePath());
252+
if (Utils.isObfuscated(mcp.getMCVersion()))
253+
tokens.put("mcp_to_srg", createSrgToMcp.getOutput().get().getAsFile().getAbsolutePath());
253254
if (parent != null && !parent.getModules().isEmpty()) {
254255
Configuration modulesCfg = project.getConfigurations().create("modules_userdev_resolver");
255256
modulesCfg.setCanBeResolved(true);

src/userdev/java/net/minecraftforge/gradle/userdev/UserDevExtension.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
public abstract class UserDevExtension extends MinecraftExtension {
1212
public static final String EXTENSION_NAME = "minecraft";
1313

14+
boolean reobfDefault = true;
1415
private boolean reobf = true;
1516

1617
public UserDevExtension(final Project project) {
1718
super(project);
1819
}
1920

2021
public void setReobf(boolean value) {
21-
this.reobf = value;
22+
this.reobfDefault = false;
23+
this.reobf = value;
2224
}
2325

2426
public boolean getReobf() {

src/userdev/java/net/minecraftforge/gradle/userdev/UserDevPlugin.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public void apply(Project project) {
281281
downloadMCMeta.configure(t -> t.getMCVersion().convention(mcVer));
282282

283283
// Register reobfJar for the 'jar' task
284-
if (extension.getReobf()) {
284+
if (extension.getReobf() && (!extension.reobfDefault || !Utils.isOfficialRuntime(mcpVer))) {
285285
reobfExtension.create(JavaPlugin.JAR_TASK_NAME);
286286
project.getTasks().withType(JarJar.class).all(jarJar -> {
287287
logger.info("Creating reobfuscation task for JarJar task: {}", jarJar.getName());
@@ -313,7 +313,11 @@ public void apply(Project project) {
313313
extension.getRuns().forEach(runConfig -> runConfig.token("asset_index", finalAssetIndex));
314314
if (extension.getCopyIdeResources().get() == Boolean.TRUE)
315315
Utils.setupIDEResourceCopy(project); // We need to have the copy resources task BEFORE the run config ones so we can detect them
316-
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets, createSrgToMcp);
316+
317+
if (Utils.isObfuscated(mcVer))
318+
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets, createSrgToMcp);
319+
else
320+
Utils.createRunConfigTasks(extension, extractNatives, downloadAssets);
317321
});
318322
}
319323

0 commit comments

Comments
 (0)