Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ void reportMissingMinecraftDependency() {
);
}

void reportMissingRenamerPluginForOldVersion(Dependency dependency) {
if (this.testFalse("net.minecraftforge.gradle.warnings.minecraft.legacy.renamer.missing")) return;

LOGGER.warn("WARNING: Renamer Gradle not present with legacy Forge version. See Problems report for details.");
this.report("legacy-missing-renamer", "Missing Renamer Gradle for legacy Minecraft dependency", spec -> spec
.details("""
A legacy Forge dependency was declared, but Renamer Gradle has not been applied to the project!
While the workspace will continue to function, this may cause problems with resultant artifacts not being renamed to obfuscated mappings.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something something "while your mod will work in dev, the built jar won't work in production without the renamer plugin applied and reobf used on it"

Legacy Forge versions use obfuscated mappings at runtime, so this is a requirement if you are publishing this project as a mod that uses Minecraft names.
Dependency: '%s'"""
.formatted(Util.toString(dependency)))
.severity(Severity.WARNING)
.solution("Apply the 'net.minecraftforge.renamer' plugin.")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mention looking at the MDK Examples repo as applying the plugin alone doesn't fix built jars iirc

.solution("Disable this warning in 'gradle.properties' if you are an advanced user: `net.minecraftforge.gradle.warnings.minecraft.legacy.renamer.missing=false`")
.solution("Consider building your project for a newer version of Forge targeting Minecraft 1.20.5 or newer.")
.solution(HELP_MESSAGE));
}

void reportMissingRenamerCheckFailed(Dependency dependency, Throwable e) {
LOGG
Comment on lines +117 to +118
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible typo?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no way, i forgot to finish that method. awesome.

}

RuntimeException invalidMinecraftDependencyType(Dependency dependency) {
return this.throwing(new IllegalArgumentException("Minecraft dependency is not a module dependency"), "unsupported-minecraft-dependency-type", "Non-module dependency used as Minecraft dependency", spec -> spec
.details("""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
class MavenizerInstanceImpl implements MavenizerInstance {
private static final Logger LOGGER = Logging.getLogger(MavenizerInstanceImpl.class);
private final MinecraftExtensionImpl.ForProjectImpl extension;
private final ForgeGradleProblems problems;
private final Provider<Boolean> valueSource;
private final ExternalModuleDependency dependency;
private final File jsonFile;
Expand All @@ -34,6 +35,7 @@ class MavenizerInstanceImpl implements MavenizerInstance {
File jsonFile
) {
this.extension = extension;
this.problems = this.extension.getObjects().newInstance(ForgeGradleProblems.class);
this.dependency = dependency;
this.valueSource = valueSource;
this.jsonFile = jsonFile;
Expand All @@ -45,12 +47,51 @@ class MavenizerInstanceImpl implements MavenizerInstance {
private Map<String, String> invoke() {
if (this.map == null) {
valueSource.get(); // Execute Mavenizer, probably called before, but just be sure.
this.map = (Map<String, String>) new JsonSlurper().parse(this.jsonFile, "UTF-8");
this.map = validate((Map<String, String>) new JsonSlurper().parse(this.jsonFile, "UTF-8"));
//this.map.forEach((k, v) -> this.extension.getProject().getLogger().lifecycle(k + " => " + v));
}
return this.map;
}

private Map<String, String> validate(Map<String, String> map) {
// this entire error check is gated behind a gradle property. if it's set to false, stop immediately.
// also don't bother checking if we aren't using Forge, which is net.minecraftforge:forge/fmlonly
// this code is kind of ugly but I don't know how to make it any cleaner without the nesting.
if (!problems.testFalse("net.minecraftforge.gradle.warnings.minecraft.legacy.renamer.missing")) {
var minecraftVersion = map.get("mc.version");
boolean forge = "net.minecraftforge".equals(dependency.getGroup())
&& ("forge".equals(dependency.getName()) || "fmlonly".equals(dependency.getName()))
if (minecraftVersion != null && !"UNKNOWN".equals(minecraftVersion)) {
boolean legacy = false;
try {
if (minecraftVersion.indexOf('w') > 0) {
var split = minecraftVersion.split("[w|a-z]");
int int1 = Integer.parseInt(split[0]);
int int2 = Integer.parseInt(split[1]);
legacy = int1 <= 24 && int2 <= 13; // 24w13a was the last snapshot before 1.20.5
} else {
var split = minecraftVersion.split("[.|-]");
int int1 = Integer.parseInt(split[0]);
int int2 = Integer.parseInt(split[1]);
int int3 = split.length > 2 ? Integer.parseInt(split[2]) : 0;
legacy = forge ? int1 <= 1 && int2 <= 20 && int3 < 5
: int1 < 26; // version < 1.20.5 == legacy for forge, 26 for vanilla
}
} catch (Exception e) {
// there are a number of things that could go wrong here.
// but it should never cause a build failure. stop immediately and report problem.
problems.reportMissingRenamerCheckFailed(dependency, e);
}

if (legacy && !extension.getProject().getPluginManager().hasPlugin("net.minecraftforge.renamer")) {
problems.reportMissingRenamerPluginForOldVersion(dependency);
}
}
}

return map;
}

private Provider<String> get(String key) {
return this.invoke.getting(key)
.orElse(this.extension.getProviders().provider(() -> {
Expand Down