New experimental way of remapping mods, this may not stay

dev/0.11
modmuss50 2018-11-05 20:33:57 +00:00
parent 94c7137086
commit c5a19955ff
5 changed files with 65 additions and 17 deletions

View File

@ -28,9 +28,9 @@ import com.google.common.collect.ImmutableMap;
import net.fabricmc.loom.providers.MinecraftProvider; import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.ModRemapperProvider; import net.fabricmc.loom.providers.ModRemapperProvider;
import net.fabricmc.loom.providers.PomfProvider; import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.loom.task.RemapModsTask;
import net.fabricmc.loom.util.Constants; import net.fabricmc.loom.util.Constants;
import net.fabricmc.loom.util.LoomDependencyManager; import net.fabricmc.loom.util.LoomDependencyManager;
import net.fabricmc.loom.util.ModRemapper;
import net.fabricmc.loom.util.SetupIntelijRunConfigs; import net.fabricmc.loom.util.SetupIntelijRunConfigs;
import org.gradle.api.Plugin; import org.gradle.api.Plugin;
import org.gradle.api.Project; import org.gradle.api.Project;
@ -219,16 +219,19 @@ public class AbstractPlugin implements Plugin<Project> {
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace")); project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
SetupIntelijRunConfigs.setup(project1); SetupIntelijRunConfigs.setup(project1);
//Enables the default mod remapper
if(extension.remapMod){
RemapModsTask remapModsTask = (RemapModsTask) project1.getTasks().findByName("remapMod");
remapModsTask.from(main.getOutput());
remapModsTask.doLast(task -> project1.getArtifacts().add("archives", remapModsTask));
project1.getTasks().getByName("build").finalizedBy(remapModsTask);
}
}); });
project.getTasks().getByName("jar").doLast(task -> { //Disables the creation of a standard jar
project.getLogger().lifecycle(":remapping mods"); project.getTasks().getByName("jar").onlyIf(element -> false);
try {
ModRemapper.remap(project);
} catch (IOException e) {
e.printStackTrace();
}
});
} }
} }

View File

@ -34,6 +34,7 @@ import java.io.File;
public class LoomGradleExtension { public class LoomGradleExtension {
public String runDir = "run"; public String runDir = "run";
public String refmapName; public String refmapName;
public boolean remapMod = true;
//Not to be set in the build.gradle //Not to be set in the build.gradle
private Project project; private Project project;

View File

@ -24,7 +24,10 @@
package net.fabricmc.loom; package net.fabricmc.loom;
import net.fabricmc.loom.task.*; import net.fabricmc.loom.task.GenIdeaProjectTask;
import net.fabricmc.loom.task.RemapModsTask;
import net.fabricmc.loom.task.RunClientTask;
import net.fabricmc.loom.task.RunServerTask;
import org.gradle.api.Project; import org.gradle.api.Project;
public class LoomGradlePlugin extends AbstractPlugin { public class LoomGradlePlugin extends AbstractPlugin {
@ -32,6 +35,8 @@ public class LoomGradlePlugin extends AbstractPlugin {
public void apply(Project target) { public void apply(Project target) {
super.apply(target); super.apply(target);
makeTask("remapMod", RemapModsTask.class);
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide"); makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraft"); makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraft");

View File

@ -0,0 +1,38 @@
/*
* 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.util.ModRemapper;
import org.gradle.api.tasks.TaskAction;
import org.gradle.jvm.tasks.Jar;
public class RemapModsTask extends Jar {
@TaskAction
public void remap() {
ModRemapper.remap(this);
}
}

View File

@ -25,33 +25,31 @@
package net.fabricmc.loom.util; package net.fabricmc.loom.util;
import net.fabricmc.loom.LoomGradleExtension; import net.fabricmc.loom.LoomGradleExtension;
import net.fabricmc.loom.providers.MinecraftProvider;
import net.fabricmc.loom.providers.PomfProvider; import net.fabricmc.loom.providers.PomfProvider;
import net.fabricmc.loom.task.RemapModsTask;
import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.OutputConsumerPath;
import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.TinyRemapper;
import net.fabricmc.tinyremapper.TinyUtils; import net.fabricmc.tinyremapper.TinyUtils;
import org.gradle.api.Project; import org.gradle.api.Project;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class ModRemapper { public class ModRemapper {
public static void remap(Project project) throws IOException { public static void remap(RemapModsTask task) {
Project project = task.getProject();
LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class);
// TODO: What's the proper way of doing this?
File libsDir = new File(project.getBuildDir(), "libs"); File modJar = task.getArchivePath();
File modJar = new File(libsDir, project.getName() + "-" + project.getVersion() + ".jar");
if (!modJar.exists()) { if (!modJar.exists()) {
project.getLogger().error("This is can be fixed by adding a 'settings.gradle' file specifying 'rootProject.name'"); project.getLogger().error("This is can be fixed by adding a 'settings.gradle' file specifying 'rootProject.name'");
return; return;
} }
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
PomfProvider pomfProvider = extension.getPomfProvider(); PomfProvider pomfProvider = extension.getPomfProvider();
Path mappings = pomfProvider.MAPPINGS_TINY.toPath(); Path mappings = pomfProvider.MAPPINGS_TINY.toPath();
@ -73,6 +71,9 @@ public class ModRemapper {
remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM)); remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
} }
project.getLogger().lifecycle("Remapping " + modJar.getName());
TinyRemapper remapper = remapperBuilder.build(); TinyRemapper remapper = remapperBuilder.build();
try { try {