New experimental way of remapping mods, this may not stay
This commit is contained in:
parent
94c7137086
commit
c5a19955ff
5 changed files with 65 additions and 17 deletions
|
@ -28,9 +28,9 @@ import com.google.common.collect.ImmutableMap;
|
|||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.providers.ModRemapperProvider;
|
||||
import net.fabricmc.loom.providers.PomfProvider;
|
||||
import net.fabricmc.loom.task.RemapModsTask;
|
||||
import net.fabricmc.loom.util.Constants;
|
||||
import net.fabricmc.loom.util.LoomDependencyManager;
|
||||
import net.fabricmc.loom.util.ModRemapper;
|
||||
import net.fabricmc.loom.util.SetupIntelijRunConfigs;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
|
@ -219,16 +219,19 @@ public class AbstractPlugin implements Plugin<Project> {
|
|||
project1.getTasks().getByName("idea").finalizedBy(project1.getTasks().getByName("genIdeaWorkspace"));
|
||||
|
||||
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 -> {
|
||||
project.getLogger().lifecycle(":remapping mods");
|
||||
try {
|
||||
ModRemapper.remap(project);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
//Disables the creation of a standard jar
|
||||
project.getTasks().getByName("jar").onlyIf(element -> false);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,6 +34,7 @@ import java.io.File;
|
|||
public class LoomGradleExtension {
|
||||
public String runDir = "run";
|
||||
public String refmapName;
|
||||
public boolean remapMod = true;
|
||||
|
||||
//Not to be set in the build.gradle
|
||||
private Project project;
|
||||
|
|
|
@ -24,7 +24,10 @@
|
|||
|
||||
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;
|
||||
|
||||
public class LoomGradlePlugin extends AbstractPlugin {
|
||||
|
@ -32,6 +35,8 @@ public class LoomGradlePlugin extends AbstractPlugin {
|
|||
public void apply(Project target) {
|
||||
super.apply(target);
|
||||
|
||||
makeTask("remapMod", RemapModsTask.class);
|
||||
|
||||
makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide");
|
||||
|
||||
makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraft");
|
||||
|
|
38
src/main/java/net/fabricmc/loom/task/RemapModsTask.java
Normal file
38
src/main/java/net/fabricmc/loom/task/RemapModsTask.java
Normal 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,33 +25,31 @@
|
|||
package net.fabricmc.loom.util;
|
||||
|
||||
import net.fabricmc.loom.LoomGradleExtension;
|
||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||
import net.fabricmc.loom.providers.PomfProvider;
|
||||
import net.fabricmc.loom.task.RemapModsTask;
|
||||
import net.fabricmc.tinyremapper.OutputConsumerPath;
|
||||
import net.fabricmc.tinyremapper.TinyRemapper;
|
||||
import net.fabricmc.tinyremapper.TinyUtils;
|
||||
import org.gradle.api.Project;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
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);
|
||||
// TODO: What's the proper way of doing this?
|
||||
File libsDir = new File(project.getBuildDir(), "libs");
|
||||
File modJar = new File(libsDir, project.getName() + "-" + project.getVersion() + ".jar");
|
||||
|
||||
File modJar = task.getArchivePath();
|
||||
|
||||
if (!modJar.exists()) {
|
||||
project.getLogger().error("This is can be fixed by adding a 'settings.gradle' file specifying 'rootProject.name'");
|
||||
return;
|
||||
}
|
||||
|
||||
MinecraftProvider minecraftProvider = extension.getMinecraftProvider();
|
||||
PomfProvider pomfProvider = extension.getPomfProvider();
|
||||
|
||||
Path mappings = pomfProvider.MAPPINGS_TINY.toPath();
|
||||
|
@ -73,6 +71,9 @@ public class ModRemapper {
|
|||
remapperBuilder = remapperBuilder.withMappings(TinyUtils.createTinyMappingProvider(mixinMapPath, fromM, toM));
|
||||
}
|
||||
|
||||
|
||||
project.getLogger().lifecycle("Remapping " + modJar.getName());
|
||||
|
||||
TinyRemapper remapper = remapperBuilder.build();
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue