mirror of
https://github.com/architectury/architectury-loom.git
synced 2026-04-02 13:37:45 -05:00
Data Generator for Forge
This commit is contained in:
@@ -95,6 +95,7 @@ public class LoomGradleExtension {
|
||||
|
||||
// Not to be set in the build.gradle
|
||||
private final Project project;
|
||||
private List<String> dataGenMods = new ArrayList<>();
|
||||
private LoomDependencyManager dependencyManager;
|
||||
private JarProcessorManager jarProcessorManager;
|
||||
private JsonObject installerJson;
|
||||
@@ -145,6 +146,14 @@ public class LoomGradleExtension {
|
||||
action.execute(new SourceSetConsumer());
|
||||
}
|
||||
|
||||
public boolean isDataGenEnabled() {
|
||||
return isForge() && !dataGenMods.isEmpty();
|
||||
}
|
||||
|
||||
public List<String> getDataGenMods() {
|
||||
return dataGenMods;
|
||||
}
|
||||
|
||||
public class SourceSetConsumer {
|
||||
public void add(Object... sourceSets) {
|
||||
for (Object sourceSet : sourceSets) {
|
||||
@@ -157,6 +166,20 @@ public class LoomGradleExtension {
|
||||
}
|
||||
}
|
||||
|
||||
public void dataGen(Action<DataGenConsumer> action) {
|
||||
if (!isForge()) {
|
||||
throw new UnsupportedOperationException("Not running with Forge support.");
|
||||
}
|
||||
|
||||
action.execute(new DataGenConsumer());
|
||||
}
|
||||
|
||||
public class DataGenConsumer {
|
||||
public void mod(String... modIds) {
|
||||
dataGenMods.addAll(Arrays.asList(modIds));
|
||||
}
|
||||
}
|
||||
|
||||
public void addTaskBeforeRun(String task) {
|
||||
this.tasksBeforeRun.add(task);
|
||||
}
|
||||
@@ -164,7 +187,7 @@ public class LoomGradleExtension {
|
||||
public List<String> getTasksBeforeRun() {
|
||||
return tasksBeforeRun;
|
||||
}
|
||||
|
||||
|
||||
public void mixinConfig(String config) {
|
||||
mixinConfigs.add(config);
|
||||
}
|
||||
|
||||
@@ -108,6 +108,12 @@ public final class CompileConfiguration {
|
||||
Configuration srg = project.getConfigurations().maybeCreate(Constants.Configurations.SRG);
|
||||
srg.setTransitive(false);
|
||||
}
|
||||
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).isDataGenEnabled()) {
|
||||
project.getConvention().getPlugin(JavaPluginConvention.class).getSourceSets().getByName("main").resources(files -> {
|
||||
files.srcDir(project.file("src/generated/resources"));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (project.getExtensions().getByType(LoomGradleExtension.class).isForge()) {
|
||||
|
||||
@@ -213,6 +213,19 @@ public class RunConfig {
|
||||
return ideaServer;
|
||||
}
|
||||
|
||||
public static RunConfig dataRunConfig(Project project) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
RunConfig ideaServer = new RunConfig();
|
||||
ideaServer.configName = "Generate Data";
|
||||
ideaServer.programArgs = "";
|
||||
populate(project, extension, ideaServer, "data");
|
||||
ideaServer.vmArgs += " -Dfabric.dli.main=" + getMainClass("data", extension);
|
||||
ideaServer.vscodeBeforeRun = new ArrayList<>(extension.getTasksBeforeRun());
|
||||
|
||||
return ideaServer;
|
||||
}
|
||||
|
||||
// This can be removed at somepoint, its not ideal but its the best solution I could thing of
|
||||
public static boolean needsUpgrade(File file) throws IOException {
|
||||
String contents = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
|
||||
@@ -74,6 +74,7 @@ public class SetupIntelijRunConfigs {
|
||||
File runConfigsDir = new File(projectDir, "runConfigurations");
|
||||
File clientRunConfigs = new File(runConfigsDir, "Minecraft_Client" + projectPath + ".xml");
|
||||
File serverRunConfigs = new File(runConfigsDir, "Minecraft_Server" + projectPath + ".xml");
|
||||
File dataRunConfigs = new File(runConfigsDir, "Minecraft_Data" + projectPath + ".xml");
|
||||
|
||||
if (!runConfigsDir.exists()) {
|
||||
runConfigsDir.mkdirs();
|
||||
@@ -89,5 +90,13 @@ public class SetupIntelijRunConfigs {
|
||||
if (!serverRunConfigs.exists() || RunConfig.needsUpgrade(serverRunConfigs)) {
|
||||
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
if (extension.isDataGenEnabled()) {
|
||||
String dataRunConfig = RunConfig.dataRunConfig(project).fromDummy("idea_run_config_template.xml");
|
||||
|
||||
if (!dataRunConfigs.exists() || RunConfig.needsUpgrade(dataRunConfigs)) {
|
||||
FileUtils.writeStringToFile(dataRunConfigs, dataRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,14 @@ public class LaunchProvider extends DependencyProvider {
|
||||
.argument("server", "--launchTarget")
|
||||
.argument("server", "fmluserdevserver")
|
||||
|
||||
.argument("data", "--launchTarget")
|
||||
.argument("data", "fmluserdevdata")
|
||||
.argument("data", "--all")
|
||||
.argument("data", "--mod")
|
||||
.argument("data", String.join(",", getExtension().getDataGenMods()))
|
||||
.argument("data", "--output")
|
||||
.argument("data", getProject().file("src/generated/resources").getAbsolutePath())
|
||||
|
||||
.property("mixin.env.remapRefMap", "true");
|
||||
|
||||
if (getExtension().useFabricMixin) {
|
||||
|
||||
@@ -40,6 +40,7 @@ public class GenEclipseRunsTask extends AbstractLoomTask {
|
||||
EclipseModel eclipseModel = getProject().getExtensions().getByType(EclipseModel.class);
|
||||
File clientRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_client.launch");
|
||||
File serverRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_server.launch");
|
||||
File dataRunConfigs = new File(getProject().getRootDir(), eclipseModel.getProject().getName() + "_data.launch");
|
||||
|
||||
String clientRunConfig = RunConfig.clientRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml");
|
||||
String serverRunConfig = RunConfig.serverRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml");
|
||||
@@ -52,6 +53,14 @@ public class GenEclipseRunsTask extends AbstractLoomTask {
|
||||
FileUtils.writeStringToFile(serverRunConfigs, serverRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
if (getExtension().isDataGenEnabled()) {
|
||||
String dataRunConfig = RunConfig.dataRunConfig(getProject()).fromDummy("eclipse_run_config_template.xml");
|
||||
|
||||
if (!dataRunConfigs.exists() || RunConfig.needsUpgrade(dataRunConfigs)) {
|
||||
FileUtils.writeStringToFile(dataRunConfigs, dataRunConfig, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
||||
|
||||
File runDir = new File(getProject().getRootDir(), getExtension().runDir);
|
||||
|
||||
if (!runDir.exists()) {
|
||||
|
||||
@@ -85,6 +85,10 @@ public class GenIdeaProjectTask extends AbstractLoomTask {
|
||||
runManager.appendChild(RunConfig.clientRunConfig(project).genRuns(runManager));
|
||||
runManager.appendChild(RunConfig.serverRunConfig(project).genRuns(runManager));
|
||||
|
||||
if (extension.isDataGenEnabled()) {
|
||||
runManager.appendChild(RunConfig.dataRunConfig(project).genRuns(runManager));
|
||||
}
|
||||
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource source = new DOMSource(doc);
|
||||
|
||||
@@ -97,6 +97,10 @@ public class GenVsCodeProjectTask extends AbstractLoomTask {
|
||||
launch.add(RunConfig.clientRunConfig(project));
|
||||
launch.add(RunConfig.serverRunConfig(project));
|
||||
|
||||
if (extension.isDataGenEnabled()) {
|
||||
launch.add(RunConfig.dataRunConfig(project));
|
||||
}
|
||||
|
||||
String json = gson.toJson(launch);
|
||||
|
||||
try {
|
||||
|
||||
@@ -52,7 +52,7 @@ public final class LoomTasks {
|
||||
tasks.register("remapSourcesJar", RemapSourcesJarTask.class, t -> t.setDescription("Remaps the project sources jar to intermediary names."));
|
||||
|
||||
registerIDETasks(tasks);
|
||||
registerRunTasks(tasks);
|
||||
registerRunTasks(tasks, project);
|
||||
registerDecompileTasks(tasks, project);
|
||||
}
|
||||
|
||||
@@ -81,7 +81,9 @@ public final class LoomTasks {
|
||||
});
|
||||
}
|
||||
|
||||
private static void registerRunTasks(TaskContainer tasks) {
|
||||
private static void registerRunTasks(TaskContainer tasks, Project project) {
|
||||
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
|
||||
|
||||
tasks.register("runClient", RunClientTask.class, t -> {
|
||||
t.setDescription("Starts a development version of the Minecraft client.");
|
||||
t.dependsOn("downloadAssets");
|
||||
@@ -92,6 +94,15 @@ public final class LoomTasks {
|
||||
t.setDescription("Starts a development version of the Minecraft server.");
|
||||
t.setGroup("fabric");
|
||||
});
|
||||
|
||||
project.afterEvaluate(p -> {
|
||||
if (extension.isDataGenEnabled()) {
|
||||
tasks.register("runData", RunDataTask.class, t -> {
|
||||
t.setDescription("Starts a development version of the Minecraft data.");
|
||||
t.setGroup("fabric");
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void registerDecompileTasks(TaskContainer tasks, Project project) {
|
||||
|
||||
33
src/main/java/net/fabricmc/loom/task/RunDataTask.java
Normal file
33
src/main/java/net/fabricmc/loom/task/RunDataTask.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of fabric-loom, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) 2016, 2017, 2018 FabricMC
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package net.fabricmc.loom.task;
|
||||
|
||||
import net.fabricmc.loom.configuration.ide.RunConfig;
|
||||
|
||||
public class RunDataTask extends AbstractRunTask {
|
||||
public RunDataTask() {
|
||||
super(RunConfig::dataRunConfig);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user