Skip to content

Commit 007b2cd

Browse files
committed
Slime Launcher runs for dev environment
1 parent f78df62 commit 007b2cd

12 files changed

+1277
-12
lines changed

src/main/groovy/net/minecraftforge/forgedev/Constants.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private Constants() { }
1212
static final String MAVEN_CENTRAL = "https://repo1.maven.org/maven2/";
1313

1414
static final String MAVENIZER_NAME = "mavenizer";
15-
static final String MAVENIZER_VERSION = "0.4.2";
15+
static final String MAVENIZER_VERSION = "0.4.3";
1616
static final String MAVENIZER_DL_URL = FORGE_MAVEN + "net/minecraftforge/minecraft-mavenizer/" + MAVENIZER_VERSION + "/minecraft-mavenizer-" + MAVENIZER_VERSION + ".jar";
1717
static final String MAVENIZER_MAIN = "net.minecraftforge.mcmaven.cli.Main";
1818
static final int MAVENIZER_JAVA = 25;
@@ -62,4 +62,10 @@ private Constants() { }
6262
static final String FASTCSV_VERSION = "3.7.0";
6363
static final String FASTCSV_DL_URL = MAVEN_CENTRAL + "de/siegmar/fastcsv/" + FASTCSV_VERSION + "/fastcsv-" + FASTCSV_VERSION + ".jar";
6464
static final int FASTCSV_JAVA = 11;
65+
66+
static final String SLIMELAUNCHER_NAME = "slimelauncher";
67+
static final String SLIMELAUNCHER_VERSION = "0.1.6";
68+
static final String SLIMELAUNCHER_DL_URL = "https://maven.minecraftforge.net/net/minecraftforge/slime-launcher/" + SLIMELAUNCHER_VERSION + "/slime-launcher-" + SLIMELAUNCHER_VERSION + ".jar";
69+
static final int SLIMELAUNCHER_JAVA_VERSION = 8;
70+
static final String SLIMELAUNCHER_MAIN = "net.minecraftforge.launcher.Main";
6571
}

src/main/groovy/net/minecraftforge/forgedev/ForgeDevExtension.java

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraftforge.forgedev.tasks.compat.LegacyMergeFilesTask;
99
import net.minecraftforge.forgedev.tasks.filtering.LegacyFilterNewJar;
1010
import net.minecraftforge.forgedev.tasks.generation.GeneratePatcherConfigV2;
11+
import net.minecraftforge.forgedev.tasks.launcher.SlimeLauncherExec;
1112
import net.minecraftforge.forgedev.tasks.mappings.LegacyApplyMappings;
1213
import net.minecraftforge.forgedev.tasks.mappings.LegacyGenerateSRG;
1314
import net.minecraftforge.forgedev.tasks.mcp.MavenizerMCPDataTask;
@@ -26,10 +27,12 @@
2627
import org.gradle.api.Action;
2728
import org.gradle.api.Project;
2829
import org.gradle.api.artifacts.ExternalModuleDependency;
30+
import org.gradle.api.artifacts.ModuleIdentifier;
2931
import org.gradle.api.artifacts.repositories.MavenArtifactRepository;
3032
import org.gradle.api.attributes.Attribute;
3133
import org.gradle.api.file.Directory;
3234
import org.gradle.api.file.DirectoryProperty;
35+
import org.gradle.api.file.ProjectLayout;
3336
import org.gradle.api.model.ObjectFactory;
3437
import org.gradle.api.plugins.JavaPlugin;
3538
import org.gradle.api.plugins.JavaPluginExtension;
@@ -41,12 +44,14 @@
4144
import org.gradle.api.tasks.bundling.Jar;
4245
import org.gradle.api.tasks.bundling.Zip;
4346
import org.gradle.api.tasks.compile.JavaCompile;
47+
import org.gradle.plugins.ide.eclipse.model.EclipseModel;
4448
import org.jetbrains.annotations.VisibleForTesting;
4549

4650
import javax.inject.Inject;
4751
import java.io.File;
4852
import java.io.IOException;
4953
import java.nio.file.Files;
54+
import java.util.List;
5055
import java.util.function.Function;
5156

5257
// TODO [ForgeDev] Hide this and make a public interface
@@ -66,6 +71,8 @@ public abstract class ForgeDevExtension {
6671

6772
protected abstract @Inject ProviderFactory getProviders();
6873

74+
protected abstract @Inject ProjectLayout getProjectLayout();
75+
6976
@Inject
7077
public ForgeDevExtension(ForgeDevPlugin plugin, Project project) {
7178
this.mavenizerRepo.set(plugin.globalCaches().dir("repo").map(this.problems.ensureFileLocation()));
@@ -101,8 +108,10 @@ private void setup(ForgeDevPlugin plugin, Project project) {
101108
var setupMCP = tasks.register("setupMCP", MavenizerMCPSetup.class);
102109

103110
var syncMavenizer = tasks.register("syncMavenizer", MavenizerMCPMaven.class);
111+
var syncMavenizerForExtra = tasks.register("syncMavenizerForExtra", MavenizerMCPMaven.class);
104112
var syncMappingsMaven = tasks.register("syncMappingsMaven", MavenizerSyncMappings.class);
105113
Util.runFirst(project, syncMavenizer);
114+
Util.runFirst(project, syncMavenizerForExtra);
106115
Util.runFirst(project, syncMappingsMaven);
107116
var mappingsConfiguration = project.getConfigurations().detachedConfiguration();
108117
var mappingsZipFile = this.getProviders().provider(mappingsConfiguration::getSingleFile);
@@ -246,6 +255,25 @@ private void setup(ForgeDevPlugin plugin, Project project) {
246255
});
247256
var release = tasks.register("release", task -> task.dependsOn(srgSourcesJar, universalJar, userdevJar));
248257

258+
var sourceSetsDir = this.getObjects().directoryProperty().value(this.getProjectLayout().getBuildDirectory().dir("sourceSets"));
259+
var mergeSourceSets = this.problems.test("net.minecraftforge.gradle.merge-source-sets");
260+
project.getExtensions().getByType(JavaPluginExtension.class).getSourceSets().configureEach(sourceSet -> {
261+
if (mergeSourceSets) {
262+
// This is documented in SourceSetOutput's javadoc comment
263+
var unifiedDir = sourceSetsDir.dir(sourceSet.getName());
264+
sourceSet.getOutput().setResourcesDir(unifiedDir);
265+
sourceSet.getJava().getDestinationDirectory().set(unifiedDir);
266+
}
267+
268+
project.getPluginManager().withPlugin("eclipse", eclipsePlugin -> {
269+
var eclipse = project.getExtensions().getByType(EclipseModel.class);
270+
if (mergeSourceSets)
271+
eclipse.getClasspath().setDefaultOutputDir(sourceSetsDir.getAsFile().get());
272+
else
273+
System.out.println("WARNING: Source set will not be merged for " + sourceSet.getName() + "!");
274+
});
275+
});
276+
249277
project.afterEvaluate(p -> {
250278
// TODO Add mappings as a dependency to FG7???
251279
// Add mappings so that it can be used by reflection tools.
@@ -263,9 +291,15 @@ private void setup(ForgeDevPlugin plugin, Project project) {
263291
});
264292
})
265293
);
294+
var minecraftExtraDependency = project.getDependencies().create(
295+
"net.minecraft:client-extra:%s".formatted(legacyMcp.getVersion().get()),
296+
Closures.<ExternalModuleDependency>consumer(dependency -> dependency.setTransitive(false))
297+
);
266298
syncMavenizer.configure(task -> task.getArtifact().set(legacyMcp.getVersion()));
299+
syncMavenizerForExtra.configure(task -> task.getArtifact().set(legacyMcp.getVersion().map(v -> "net.minecraft:client-extra:" + v)));
267300
syncMappingsMaven.configure(task -> task.getVersion().set(legacyPatcher.getMappingVersion()));
268301
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, minecraftDependency);
302+
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, minecraftExtraDependency);
269303
project.getDependencies().add(JavaPlugin.IMPLEMENTATION_CONFIGURATION_NAME, mappingsDependency);
270304
mappingsConfiguration.withDependencies(d -> d.add(mappingsDependency));
271305

@@ -316,6 +350,10 @@ private void setup(ForgeDevPlugin plugin, Project project) {
316350
}
317351
}
318352

353+
setupMCP.configure(task -> {
354+
task.getSideAnnotationStripperConfig().fileProvider(getProviders().provider(() -> legacyPatcher.getSideAnnotationStrippers().getSingleFile()));
355+
});
356+
319357
// TODO SAS! Used MCPFunction in FG6, I DON'T GIVE A SHIT RIGHT NOW!!!
320358

321359
if (!legacyPatcher.getExtraMappings().isEmpty()) {
@@ -405,6 +443,35 @@ private void setup(ForgeDevPlugin plugin, Project project) {
405443
});
406444
}
407445
}
446+
447+
// TODO Clean up please
448+
record SimpleModuleIdentifier(String getGroup, String getName) implements ModuleIdentifier {
449+
SimpleModuleIdentifier() {
450+
this("net.minecraft", "joined");
451+
}
452+
}
453+
454+
if (!legacyPatcher.runs.isEmpty()) {
455+
var genEclipseRuns = project.getTasks().register("genEclipseRuns", task -> {
456+
task.setGroup("IDE");
457+
task.setDescription("Generates the run configuration launch files for Eclipse.");
458+
});
459+
460+
File eclipseOutputDir;
461+
var eclipse = project.getExtensions().findByType(EclipseModel.class);
462+
if (eclipse != null) {
463+
eclipse.synchronizationTasks(genEclipseRuns);
464+
eclipseOutputDir = eclipse.getClasspath().getDefaultOutputDir();
465+
} else {
466+
eclipseOutputDir = getProjectLayout().getProjectDirectory().dir("bin").getAsFile();
467+
}
468+
469+
for (var sourceSet : List.of(main.get(), java.getSourceSets().named(SourceSet.TEST_SOURCE_SET_NAME).get())) {
470+
legacyPatcher.runs.forEach(options -> {
471+
var task = SlimeLauncherExec.register(project, sourceSet, options, new SimpleModuleIdentifier(), legacyMcp.getVersion().get(), eclipseOutputDir);
472+
});
473+
}
474+
}
408475
});
409476
}
410477
}

src/main/groovy/net/minecraftforge/forgedev/LegacyMinecraftExtension.java

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
*/
55
package net.minecraftforge.forgedev;
66

7+
import groovy.lang.Closure;
8+
import groovy.lang.DelegatesTo;
9+
import groovy.transform.stc.ClosureParams;
10+
import groovy.transform.stc.FromString;
11+
import net.minecraftforge.forgedev.tasks.launcher.SlimeLauncherOptions;
12+
import net.minecraftforge.forgedev.tasks.launcher.SlimeLauncherOptionsImpl;
13+
import net.minecraftforge.gradleutils.shared.Closures;
14+
import org.gradle.api.Action;
15+
import org.gradle.api.NamedDomainObjectContainer;
716
import org.gradle.api.Project;
817
import org.gradle.api.file.ConfigurableFileCollection;
918
import org.gradle.api.model.ObjectFactory;
@@ -16,24 +25,21 @@
1625

1726
@VisibleForTesting
1827
public abstract class LegacyMinecraftExtension {
19-
protected final Project project;
2028
protected final ConfigurableFileCollection accessTransformers = this.getObjects().fileCollection();
2129

2230
private final Property<String> mapping = this.getObjects().property(String.class);
2331

32+
final NamedDomainObjectContainer<SlimeLauncherOptionsImpl> runs = this.getObjects().domainObjectContainer(SlimeLauncherOptionsImpl.class);
33+
2434
protected abstract @Inject ObjectFactory getObjects();
2535

36+
protected abstract @Inject Project getProject();
37+
2638
@Inject
27-
public LegacyMinecraftExtension(Project project) {
28-
this.project = project;
39+
public LegacyMinecraftExtension() {
2940
this.mapping.set(getMappingChannel().zip(getMappingVersion(), (ch, ver) -> ch + '_' + ver));
3041
}
3142

32-
public Project getProject() {
33-
return project;
34-
}
35-
36-
3743
public abstract Property<String> getMappingChannel();
3844

3945
public abstract Property<String> getMappingVersion();
@@ -63,6 +69,22 @@ public void mappings(Map<String, ? extends CharSequence> mappings) {
6369
mappings(channel.toString(), version.toString());
6470
}
6571

72+
public NamedDomainObjectContainer<? extends SlimeLauncherOptions> getRuns() {
73+
return this.runs;
74+
}
75+
76+
public void runs(
77+
@DelegatesTo(NamedDomainObjectContainer.class)
78+
@ClosureParams(value = FromString.class, options = "org.gradle.api.NamedDomainObjectContainer<net.minecraftforge.forgedev.tasks.launcher.SlimeLauncherOptions>")
79+
Closure<?> closure
80+
) {
81+
this.runs.configure(closure);
82+
}
83+
84+
public void runs(Action<? super NamedDomainObjectContainer<? extends SlimeLauncherOptions>> action) {
85+
this.runs(Closures.action(this, action));
86+
}
87+
6688
public ConfigurableFileCollection getAccessTransformers() {
6789
return accessTransformers;
6890
}

src/main/groovy/net/minecraftforge/forgedev/LegacyPatcherExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.jetbrains.annotations.VisibleForTesting;
1515

1616
import javax.annotation.Nullable;
17+
import javax.inject.Inject;
1718
import java.io.File;
1819
import java.io.IOException;
1920
import java.util.ArrayList;
@@ -35,9 +36,8 @@ public abstract class LegacyPatcherExtension extends LegacyMinecraftExtension {
3536
@Nullable
3637
private PatcherConfig.V2.DataFunction processor;
3738

38-
public LegacyPatcherExtension(final Project project) {
39-
super(project);
40-
}
39+
@Inject
40+
public LegacyPatcherExtension() { }
4141

4242
public abstract Property<Project> getParent();
4343

src/main/groovy/net/minecraftforge/forgedev/OSValueSource.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
/*
2+
* Copyright (c) Forge Development LLC and contributors
3+
* SPDX-License-Identifier: LGPL-2.1-only
4+
*/
15
package net.minecraftforge.forgedev;
26

37
import net.minecraftforge.util.os.OS;

src/main/groovy/net/minecraftforge/forgedev/Tools.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ private Tools() { }
3535
public static final Tool JARCOMPATIBILITYCHECKER = tool(Constants.JARCOMPATIBILITYCHECKER_NAME, Constants.JARCOMPATIBILITYCHECKER_VERSION, Constants.JARCOMPATIBILITYCHECKER_DL_URL, Constants.JARCOMPATIBILITYCHECKER_JAVA, Constants.JARCOMPATIBILITYCHECKER_MAIN);
3636
public static final Tool FART = tool(Constants.FART_NAME, Constants.FART_VERSION, Constants.FART_DL_URL, Constants.FART_JAVA, Constants.FART_MAIN);
3737
public static final Tool SRG2SRC = tool(Constants.SRG2SRC_NAME, Constants.SRG2SRC_VERSION, Constants.SRG2SRC_DL_URL, Constants.SRG2SRC_JAVA, Constants.SRG2SRC_MAIN);
38+
public static final Tool SLIMELAUNCHER = tool(Constants.SLIMELAUNCHER_NAME, Constants.SLIMELAUNCHER_VERSION, Constants.SLIMELAUNCHER_DL_URL, Constants.SLIMELAUNCHER_JAVA_VERSION, Constants.SLIMELAUNCHER_MAIN);
3839

3940
// LIBRARIES
4041
public static final Tool SRGUTILS = tool(Constants.SRGUTILS_NAME, Constants.SRGUTILS_VERSION, Constants.SRGUTILS_DL_URL, Constants.SRGUTILS_JAVA);

0 commit comments

Comments
 (0)