Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP 1.12 support #26

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
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
86 changes: 86 additions & 0 deletions src/main/java/com/gtnewhorizons/gtnhgradle/GTNHGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public static abstract class GTNHExtension implements ExtensionAware {
/** Logging service used by the plugin */
public final @NotNull Logger logger;

/** The MinecraftVersion enum associated with this project */
public final @NotNull MinecraftVersion minecraftVersion;

/** Parsed properties associated with this project */
public @NotNull PropertiesConfiguration configuration;

Expand Down Expand Up @@ -142,6 +145,7 @@ public static abstract class GTNHExtension implements ExtensionAware {
public GTNHExtension(final Project project) {
logger = Logging.getLogger(GTNHGradlePlugin.class);
configuration = PropertiesConfiguration.GradleUtils.makePropertiesFrom(project);
minecraftVersion = MinecraftVersion.getByVersionString(configuration.minecraftVersion);
}

/**
Expand Down Expand Up @@ -194,4 +198,86 @@ public void applyAllModules(final Project project) {
@Inject
public abstract @NotNull ExecOperations getExecOperations();
}

/**
* The enum stored in the GTNHExtension object representing the selected MC version
*/
public enum MinecraftVersion {

/** Minecraft 1.7.10 */
V1_7_10("1.7.10", "10.13.4.1614", "stable", "12", UpdateableConstants.NEWEST_UNIMIXINS,
UpdateableConstants.NEWEST_LWJGL3IFY, "unimixins", "unimixins"),

/** Minecraft 1.12.2 */
V1_12_2("1.12.2", "14.23.5.2847", "stable", "39", UpdateableConstants.NEWEST_MIXINBOOTER,
UpdateableConstants.NEWEST_LWJGL3IFY_1122, "mixinbooter", "mixin-booter");

/**
* Minecraft Version
*/
public final String version;

/**
* Forge Version
*/
public final String forgeVersion;

/**
* Obfuscation Mappings Channel
*/
public final String mappingsChannel;

/**
* Obfuscation Mappings Versions
*/
public final String mappingsVersion;

/**
* The full dependency spec for the version's Mixin provider(e.g. unimixins or mixinbooter)
*/
public final String mixinProviderSpec;

/**
* The full dependency spec for the version's lwjgl3ify
*/
public final String lwjgl3ifySpec;

/**
* The modrinth project slug for the version's mixin provider. Used to create relation on Modrinth publishing
*/
public final String modrinthMixinSlug;

/**
* The curseforge project slug for the version's mixin provider. Used to create relation on Curseforge
* publishing
*/
public final String curseMixinSlug;

MinecraftVersion(String version, String forgeVersion, String mappingsChannel, String mappingsVersion,
String mixinProviderSpec, String lwjgl3ifySpec, String modrinthMixinSlug, String curseMixinSlug) {
this.version = version;
this.forgeVersion = forgeVersion;
this.mappingsChannel = mappingsChannel;
this.mappingsVersion = mappingsVersion;
this.mixinProviderSpec = mixinProviderSpec;
this.lwjgl3ifySpec = lwjgl3ifySpec;
this.modrinthMixinSlug = modrinthMixinSlug;
this.curseMixinSlug = curseMixinSlug;
}

/**
* Find a MinecraftVersion based on the MC version string, e.g. "1.7.10" or "1.12.2"
*
* @param version The minecraft version string
* @return The matching MinecraftVersion enum
*/
public static MinecraftVersion getByVersionString(String version) {
for (MinecraftVersion v : MinecraftVersion.values()) {
if (v.version.equals(version)) {
return v;
}
}
throw new IllegalArgumentException("Invalid Minecraft Version" + version);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,6 @@ ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empt
""")
public @NotNull String minecraftVersion = "1.7.10";

/** See annotation */
@Prop(name = "forgeVersion", isSettings = false, preferPopulated = true, required = false, docComment = """
Version of Minecraft Forge to target
""")
public @NotNull String forgeVersion = "10.13.4.1614";

/** See annotation */
@Prop(name = "channel", isSettings = false, preferPopulated = true, required = false, docComment = """
Specify an MCP channel for dependency deobfuscation and the deobfParams task.
""")
public @NotNull String channel = "stable";

/** See annotation */
@Prop(name = "mappingsVersion", isSettings = false, preferPopulated = true, required = false, docComment = """
Specify an MCP mappings version for dependency deobfuscation and the deobfParams task.
""")
public @NotNull String mappingsVersion = "12";

/** See annotation */
@Prop(name = "remoteMappings", isSettings = false, preferPopulated = true, required = false, docComment = """
Defines other MCP mappings for dependency deobfuscation.
""")
public @NotNull String remoteMappings = "https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/";

/** See annotation */
@Prop(
name = "developmentEnvironmentUserName",
Expand Down Expand Up @@ -341,6 +317,21 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
""")
public boolean enableGenericInjection = false;

/** See annotation */
@Prop(
name = "stripForgeRequirements",
isSettings = false,
preferPopulated = true,
required = false,
docComment = """
1.12.2 ONLY
Some mods require a specific forge version to launch in. When you need to use one of those mods as a dependency,
and cannot launch with the forge version required, enable this to strip the forge version requirements from that mod.
This will add 'strip-latest-forge-requirements' as 'runtimeOnlyNonPublishable'.
Requires useMixins or forceEnableMixins to be true, as the mod uses mixins to function.
""")
public boolean stripForgeRequirements = false;

/** See annotation */
@Prop(
name = "generateGradleTokenClass",
Expand Down Expand Up @@ -430,9 +421,11 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
preferPopulated = true,
required = false,
docComment = """
Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
There can be multiple files in a space-separated list.
Specify the configuration file for Forge's access transformers here.
It can be placed into /src/main/resources/META-INF/ or /src/main/resources
There can be multiple files in a space-separated or comma-separated list.
Example value: mymodid_at.cfg nei_at.cfg
Example value: mymodid_at.cfg,nei_at.cfg
""")
public @NotNull String accessTransformersFile = "";

Expand Down Expand Up @@ -478,6 +471,17 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
""")
public @NotNull String mixinsPackage = "";

/** See annotation */
@Prop(
name = "mixinConfigRefmap",
isSettings = false,
preferPopulated = true,
required = false,
docComment = """
Location of the mixin config refmap. If left, blank, defaults to "mixins.${modId}.refmap.json". Target file must have the "json" extension.
""")
public @NotNull String mixinConfigRefmap = "";

/** See annotation */
@Prop(
name = "coreModClass",
Expand Down Expand Up @@ -549,7 +553,10 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
preferPopulated = true,
required = false,
docComment = """
Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
Adds the following well-known repositories:
CurseMaven
Modrinth
BlameJared(1.12.2 only)
""")
public boolean includeWellKnownRepositories = true;

Expand All @@ -564,6 +571,7 @@ Enables using modern Java syntax (up to version 17) via Jabel, while still targe
list of strings, with the acceptable keys being(case does not matter):
cursemaven
modrinth
blamejared
""")
public @NotNull String excludeWellKnownRepositories = "";

Expand All @@ -575,6 +583,7 @@ list of strings, with the acceptable keys being(case does not matter):
required = false,
hidden = true,
docComment = """
[1.7.10 only]
Adds a dependency override rule to use RFG-deobfuscated https://www.curseforge.com/minecraft/mc-mods/industrial-craft/files/2353971 instead of net.industrial-craft:industrialcraft-2:2.2.828-experimental:dev
""")
public boolean useIC2FromCurseforge = true;
Expand Down Expand Up @@ -620,7 +629,8 @@ list of strings, with the acceptable keys being(case does not matter):
type can be one of [project, version],
and the name is the Modrinth project or version slug/id of the other mod.
Example: required-project:fplib;optional-project:gasstation;incompatible-project:gregtech
Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
Note: on 1.7.10, UniMixins is automatically set as a required dependency if usesMixins = true
On 1.12.2, MixinBooter is automatically set as a required dependency
""")
public @NotNull String modrinthRelations = "";

Expand All @@ -645,7 +655,8 @@ list of strings, with the acceptable keys being(case does not matter):
Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
and the name is the CurseForge project slug of the other mod.
Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
Note: UniMixins is automatically set as a required dependency if usesMixins = true.
Note: On 1.7.10, UniMixins is automatically set as a required dependency if usesMixins = true.
On 1.12.2, MixinBooter is automatically set as a required dependency
""")
public @NotNull String curseForgeRelations = "";

Expand Down Expand Up @@ -736,6 +747,32 @@ Uncomment this to disable Checkstyle checks (currently wildcard import check).
This is meant to be set in $HOME/.gradle/gradle.properties.
""")
public boolean ideaCheckSpotlessOnBuild = true;

@Prop(
name = "releaseType",
isSettings = false,
preferPopulated = false,
required = false,
defaultInComment = "release",
docComment = """
This project's release type on CurseForge and/or Modrinth.
Alternatively this can be set with the 'RELEASE_TYPE' environment variable.
Allowed types: release, beta, alpha
Leave blank to use the old release type, with -pre designations
""")
public String releaseType = "release";

@Prop(
name = "separateRunDirs",
isSettings = false,
preferPopulated = false,
required = false,
defaultInComment = "false",
docComment = """
Separate run directories into "run/client" for runClient task, and "run/server" for runServer task.
Useful for debugging a server and client simultaneously. If not enabled, it will be in the standard location "run/"
""")
public boolean separateRunDirs = false;
// </editor-fold>
// </editor-fold>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,23 @@ public class UpdateableConstants {
// https://github.com/GTNewHorizons/ExampleMod1.7.10/releases
public static final @NotNull String NEWEST_BLOWDRYER_TAG = "0.2.2";

/** Latest version of UniMixins */
/** Latest version of UniMixins for 1.7.10 */
public static final String NEWEST_UNIMIXINS = "io.github.legacymoddingmc:unimixins:0.1.18";

/** Latest version of MixinBooter for 1.12.2 */
public static final String NEWEST_MIXINBOOTER = "zone.rong:mixinbooter:10.2";

/** Latest version of Jabel for modern Java support */
public static final @NotNull String NEWEST_JABEL = "com.github.bsideup.jabel:jabel-javac-plugin:1.0.1";
/** Latest version of GTNHLib for modern Java support */
// https://github.com/GTNewHorizons/GTNHLib/releases
public static final @NotNull String NEWEST_GTNH_LIB = "com.github.GTNewHorizons:GTNHLib:0.5.18";
/** Latest version of GTNHLib for modern Java support */
/** Latest version of lwjgl3ify for modern Java support */
// https://github.com/GTNewHorizons/lwjgl3ify/releases
public static final @NotNull String NEWEST_LWJGL3IFY = "com.github.GTNewHorizons:lwjgl3ify:2.1.4";
/** Latest version of GTNHLib for modern Java support */
/** Latest version of lwjgl3ify for modern Java support on 1.12.2 */
public static final @NotNull String NEWEST_LWJGL3IFY_1122 = "io.github.twilightflower:lwjgl3ify:1.0.1";
/** Latest version of Hodgepodge for modern Java support */
// https://github.com/GTNewHorizons/Hodgepodge/releases
public static final @NotNull String NEWEST_HODGEPODGE = "com.github.GTNewHorizons:Hodgepodge:2.5.74";
/** Latest version of LWJGL3 for modern Java support */
Expand All @@ -50,4 +55,7 @@ public class UpdateableConstants {

/** Latest Industrial Craft 2 version */
public static final @NotNull String NEWEST_IC2_SPEC = "curse.maven:ic2-242638:2353971";

/** Latest strip-latest-forge-requirements for 1.12.2 */
public static final @NotNull String NEWEST_STRIP_FORGE_REQUIREMENTS = "com.cleanroommc:strip-latest-forge-requirements:1.0";
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,28 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
.resolve("main")
.resolve("resources")
.resolve("META-INF");
final Path resources = projectRoot.resolve("src")
.resolve("main")
.resolve("resources");

final SourceSetContainer sourceSets = project.getExtensions()
.getByType(JavaPluginExtension.class)
.getSourceSets();
final ConfigurableFileCollection atList = mcpTasks.getDeobfuscationATs();

if (!gtnh.configuration.accessTransformersFile.isEmpty()) {
for (String atFile : gtnh.configuration.accessTransformersFile.split(" ")) {
final Path targetFile = metaInf.resolve(atFile.trim());
if (!Files.exists(metaInf.resolve(targetFile))) {
throw new GradleException(
"Could not resolve \"accessTransformersFile\"! Could not find " + targetFile);
String commaSeparated = gtnh.configuration.accessTransformersFile.replaceAll("\\s+(\\s*)", ",$1");
for (String atFile : commaSeparated.split(",")) {
atFile = atFile.trim();
final Path targetFile;
final Path targetFileResources = resources.resolve(atFile);
final Path targetFileMetaInf = metaInf.resolve(atFile);
if (Files.exists(resources.resolve(targetFileResources))) {
targetFile = targetFileResources;
} else if (Files.exists(metaInf.resolve(targetFileMetaInf))) {
targetFile = targetFileMetaInf;
} else {
throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + atFile);
}
atList.from(projectRoot.relativize(targetFile));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,8 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
final RunMinecraftTask runClient = tasks.named("runClient", RunMinecraftTask.class)
.get();
final var run = ijClientRun.get();
run.setWorkingDirectory(
runClient.getWorkingDir()
.getAbsolutePath());
File clientFile = new File(runClient.getWorkingDir(), gtnh.configuration.separateRunDirs ? "client" : "");
run.setWorkingDirectory(clientFile.getAbsolutePath());
run.setProgramParameters(quotedJoin(runClient.calculateArgs()));
run.setJvmArgs(
quotedJoin(runClient.calculateJvmArgs()) + ' ' + quotedPropJoin(runClient.getSystemProperties()));
Expand All @@ -192,9 +191,8 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
final RunMinecraftTask runServer = tasks.named("runServer", RunMinecraftTask.class)
.get();
final var run = ijServerRun.get();
run.setWorkingDirectory(
runServer.getWorkingDir()
.getAbsolutePath());
File serverFile = new File(runServer.getWorkingDir(), gtnh.configuration.separateRunDirs ? "server" : "");
run.setWorkingDirectory(serverFile.getAbsolutePath());
run.setProgramParameters(quotedJoin(runServer.calculateArgs()));
run.setJvmArgs(
quotedJoin(runServer.calculateJvmArgs()) + ' ' + quotedPropJoin(runServer.getSystemProperties()));
Expand Down
Loading