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 5 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
32 changes: 32 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,8 @@ public static abstract class GTNHExtension implements ExtensionAware {
/** Logging service used by the plugin */
public final @NotNull Logger logger;

public final @NotNull MinecraftVersion minecraftVersion;

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

Expand Down Expand Up @@ -142,6 +144,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 +197,33 @@ 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 {

V1_7_10("1.7.10"),
V1_12_2("1.12.2");

private final String version;

MinecraftVersion(String version) {
this.version = version;
}

public String getVersion() {
return version;
}

public static MinecraftVersion getByVersionString(String version) {
for (MinecraftVersion v : MinecraftVersion.values()) {
if (v.getVersion()
.equals(version)) {
return v;
}
}
throw new IllegalArgumentException("Invalid Minecraft Version" + version);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,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 +567,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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ 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:9.3";
Copy link
Contributor

Choose a reason for hiding this comment

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

10.1


/** 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 */
Expand All @@ -27,6 +30,8 @@ public class UpdateableConstants {
/** Latest version of GTNHLib 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 lwjgl3ify for modern Java support on 1.12 */
public static final @NotNull String NEWEST_LWJGL3IFY_1122 = "io.github.twilightflower:lwjgl3ify:1.0.1";
/** Latest version of GTNHLib for modern Java support */
// https://github.com/GTNewHorizons/Hodgepodge/releases
public static final @NotNull String NEWEST_HODGEPODGE = "com.github.GTNewHorizons:Hodgepodge:2.5.74";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,18 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
}
}

final String mixinProviderSpecNoClassifer = UpdateableConstants.NEWEST_UNIMIXINS;
final String mixinProviderSpec = mixinProviderSpecNoClassifer + ":dev";
String mixinProviderSpecNoClassifer;
String mixinProviderSpec;
if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10) {
mixinProviderSpecNoClassifer = UpdateableConstants.NEWEST_UNIMIXINS;
mixinProviderSpec = mixinProviderSpecNoClassifer + ":dev";
} else if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_12_2) {
mixinProviderSpecNoClassifer = UpdateableConstants.NEWEST_MIXINBOOTER;
mixinProviderSpec = mixinProviderSpecNoClassifer;
} else {
throw new IllegalArgumentException("Unsupported Minecraft Version: " + gtnh.configuration.minecraftVersion);
}

project.getExtensions()
.getExtraProperties()
.set("mixinProviderSpec", mixinProviderSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,37 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
});
ext.set("java17PatchDependenciesCfg", java17PatchDependenciesCfg);

String mixinSpec = "";
String lwjgl3ifySpec = "";

if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10) {
mixinSpec = UpdateableConstants.NEWEST_UNIMIXINS;
lwjgl3ifySpec = UpdateableConstants.NEWEST_LWJGL3IFY;
} else if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_12_2) {
mixinSpec = UpdateableConstants.NEWEST_MIXINBOOTER;
lwjgl3ifySpec = UpdateableConstants.NEWEST_LWJGL3IFY_1122;
} else {
throw new IllegalArgumentException("Unsupported Minecraft Version: " + gtnh.configuration.minecraftVersion);
}

if (!gtnh.configuration.modId.equals("lwjgl3ify")) {
deps.add(java17DependenciesCfg.getName(), UpdateableConstants.NEWEST_LWJGL3IFY);
((ModuleDependency) deps
.add(java17PatchDependenciesCfg.getName(), UpdateableConstants.NEWEST_LWJGL3IFY + ":forgePatches"))
.setTransitive(false);
deps.add(java17DependenciesCfg.getName(), lwjgl3ifySpec);
((ModuleDependency) deps.add(java17PatchDependenciesCfg.getName(), lwjgl3ifySpec + ":forgePatches"))
.setTransitive(false);
}
if (!gtnh.configuration.modId.equals("hodgepodge")) {

if (!gtnh.configuration.modId.equals("hodgepodge")
&& gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10) {
final ModuleDependency hodgepodge = (ModuleDependency) deps
.add(java17DependenciesCfg.getName(), UpdateableConstants.NEWEST_HODGEPODGE);
if (gtnh.configuration.modId.equals("gtnhlib")) {
hodgepodge.exclude(ImmutableMap.of("module", "GTNHLib"));
}
}

deps.getConstraints()
.add(java17DependenciesCfg.getName(), UpdateableConstants.NEWEST_UNIMIXINS)
.because("Use latest UniMixins known to GTNHGradle.");
.add(java17DependenciesCfg.getName(), mixinSpec)
.because("Use latest UniMixins or MixinBooter known to GTNHGradle.");

final List<String> java17JvmArgs = new ArrayList<>(Arrays.asList(JAVA_17_ARGS));
final List<String> hotswapJvmArgs = new ArrayList<>(Arrays.asList(HOTSWAP_JVM_ARGS));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@

import javax.inject.Inject;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
Expand Down Expand Up @@ -98,6 +100,17 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
});
});

if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_12_2) {
repos.maven(mvn -> {
mvn.setName("Cleanroom Maven");
mvn.setUrl("https://maven.cleanroommc.com");
});
repos.maven(mvn -> {
mvn.setName("GTCEu Maven");
mvn.setUrl("https://maven.gtceu.com");
});
}

// Provide a runtimeOnlyNonPublishable configuration
final ConfigurationContainer cfg = project.getConfigurations();
final Configuration runtimeOnlyNonPublishable = cfg.create("runtimeOnlyNonPublishable", c -> {
Expand Down Expand Up @@ -224,6 +237,9 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
final ModUtils modUtils = project.getExtensions()
.getByType(ModUtils.class);

minecraft.getMcVersion()
.set(gtnh.configuration.minecraftVersion);

// Tag injection
if (!gtnh.configuration.replaceGradleTokenInFile.isEmpty()) {
for (final String f : gtnh.configuration.replaceGradleTokenInFile.split(",")) {
Expand Down Expand Up @@ -351,10 +367,14 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
.provider(
() -> Objects.requireNonNull(project.getVersion())
.toString());
props.put("minecraftVersion", minecraft.getMcVersion());
props.put(
gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10 ? "minecraftVersion" : "mcversion",
minecraft.getMcVersion());
props.put("modId", gtnh.configuration.modId);
props.put("modName", gtnh.configuration.modName);
props.put("modVersion", modVersion);
props.put(
gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10 ? "modVersion" : "version",
modVersion);
}

tasks.named("processResources", ProcessResources.class)
Expand Down Expand Up @@ -385,14 +405,20 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
manifest.attributes(ImmutableMap.of("FMLCorePlugin", props.modGroup + "." + props.coreModClass));
}
if (props.usesMixins) {
manifest.attributes(
ImmutableMap.of(
"TweakClass",
"org.spongepowered.asm.launch.MixinTweaker",
"MixinConfigs",
"mixins." + props.modId + ".json",
"ForceLoadAsMod",
!props.containsMixinsAndOrCoreModOnly));
final Path output = project.file(
"src/" + modUtils.mixinSourceSet.get()
.getName() + "/resources/mixins." + gtnh.configuration.modId + ".json")
.toPath();
if (Files.exists(output)) {
manifest.attributes(
ImmutableMap.of(
"TweakClass",
"org.spongepowered.asm.launch.MixinTweaker",
"MixinConfigs",
"mixins." + props.modId + ".json",
"ForceLoadAsMod",
!props.containsMixinsAndOrCoreModOnly));
}
}
});
project.getExtensions()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,12 @@ public void apply(GTNHGradlePlugin.@NotNull GTNHExtension gtnh, @NotNull Project
ec.filter(f -> { f.includeGroup("maven.modrinth"); });
});
}

if (!excludes.contains("BLAMEJARED") && gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_12_2) {
repos.maven(mvn -> {
mvn.setName("BlameJared Maven");
mvn.setUrl("https://maven.blamejared.com");
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void setup(Project project, GTNHGradlePlugin.GTNHExtension gtnh) {
mcpTasks.getTaskPackagePatchedMc(),
"jar");
getMainClass().set((side == Distribution.CLIENT) ? "GradleStart" : "GradleStartServer");
getMcVersion().set(gtnh.configuration.minecraftVersion);
getUsername().set(minecraft.getUsername());
getUserUUID().set(minecraft.getUserUUID());
if (side == Distribution.DEDICATED_SERVER) {
Expand All @@ -108,6 +109,15 @@ public void setup(Project project, GTNHGradlePlugin.GTNHExtension gtnh) {
systemProperty("gradlestart.bouncerServer", "com.gtnewhorizons.retrofuturabootstrap.Main");

if (gtnh.configuration.usesMixins) {
String mixinSpec;
if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_7_10) {
mixinSpec = UpdateableConstants.NEWEST_UNIMIXINS;
} else if (gtnh.minecraftVersion == GTNHGradlePlugin.MinecraftVersion.V1_12_2) {
mixinSpec = UpdateableConstants.NEWEST_MIXINBOOTER;
} else {
throw new IllegalArgumentException(
"Unsupported Minecraft Version: " + gtnh.configuration.minecraftVersion);
}
this.getExtraJvmArgs()
.addAll(project.provider(() -> {
final Configuration mixinCfg = project.getConfigurations()
Expand Down
Loading