Data Generator for Forge

This commit is contained in:
shedaniel
2021-01-29 10:39:20 +08:00
parent b880d3f9d5
commit 71392052eb
10 changed files with 123 additions and 3 deletions

View File

@@ -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()) {

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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) {

View 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);
}
}