diff --git a/build.gradle b/build.gradle index a37d5c6..7585f57 100644 --- a/build.gradle +++ b/build.gradle @@ -34,15 +34,15 @@ dependencies { implementation ('org.zeroturnaround:zt-zip:1.13') implementation ('com.google.code.gson:gson:2.8.5') implementation ('com.google.guava:guava:27.1-jre') - implementation ('net.fabricmc:stitch:0.1.2.47') { + implementation ('net.fabricmc:stitch:0.1.2.49') { exclude module: 'enigma' } implementation ('net.fabricmc:tiny-remapper:0.1.0.29') { transitive = false } - implementation ('org.jetbrains:intellij-fernflower:1.0.0.7') + implementation ('org.jetbrains:intellij-fernflower:1.0.0.8') - implementation ('net.fabricmc:sponge-mixin:0.7.11.17') { + implementation ('net.fabricmc:sponge-mixin:0.7.11.21') { exclude module: 'launchwrapper' exclude module: 'guava' } diff --git a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java index 36f4ca3..4add936 100644 --- a/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java +++ b/src/main/java/net/fabricmc/loom/LoomGradlePlugin.java @@ -39,13 +39,15 @@ public class LoomGradlePlugin extends AbstractPlugin { makeTask("genSources", GenSourcesTask.class); - makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea").setGroup("ide"); - makeTask("vscode", GenVsCodeProjectTask.class).setGroup("ide"); - makeTask("genEclipseRuns", GenEclipseRunsTask.class).setGroup("ide"); + makeTask("downloadAssets", DownloadAssetsTask.class); + + makeTask("genIdeaWorkspace", GenIdeaProjectTask.class).dependsOn("idea", "downloadAssets").setGroup("ide"); + makeTask("genEclipseRuns", GenEclipseRunsTask.class).dependsOn("downloadAssets").setGroup("ide"); + makeTask("vscode", GenVsCodeProjectTask.class).dependsOn("downloadAssets").setGroup("ide"); makeTask("remapSourcesJar", RemapSourcesJar.class); - makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded").setGroup("minecraftMapped"); + makeTask("runClient", RunClientTask.class).dependsOn("buildNeeded", "downloadAssets").setGroup("minecraftMapped"); makeTask("runServer", RunServerTask.class).dependsOn("buildNeeded").setGroup("minecraftMapped"); } } diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java new file mode 100644 index 0000000..a938cf7 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftAssetsProvider.java @@ -0,0 +1,97 @@ +/* + * 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.providers; + +import com.google.gson.Gson; +import net.fabricmc.loom.LoomGradleExtension; +import net.fabricmc.loom.util.Checksum; +import net.fabricmc.loom.util.Constants; +import net.fabricmc.loom.util.DownloadUtil; +import net.fabricmc.loom.util.MinecraftVersionInfo; +import net.fabricmc.loom.util.assets.AssetIndex; +import net.fabricmc.loom.util.assets.AssetObject; +import net.fabricmc.loom.util.progress.ProgressLogger; +import org.gradle.api.Project; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.lang.ref.SoftReference; +import java.net.URL; +import java.util.Collection; +import java.util.Date; +import java.util.HashSet; +import java.util.Map; + +public class MinecraftAssetsProvider { + public static void provide(MinecraftProvider minecraftProvider, Project project) throws IOException { + LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + MinecraftVersionInfo versionInfo = minecraftProvider.versionInfo; + + MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex; + + // get existing cache files + File assets = new File(extension.getUserCache(), "assets"); + if (!assets.exists()) { + assets.mkdirs(); + } + + File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json"); + if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) { + project.getLogger().lifecycle(":downloading asset index"); + DownloadUtil.downloadIfChanged(new URL(assetIndex.url), assetsInfo, project.getLogger()); + } + + ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, MinecraftAssetsProvider.class.getName()); + progressLogger.start("Downloading assets...", "assets"); + FileReader fileReader = new FileReader(assetsInfo); + AssetIndex index = new Gson().fromJson(fileReader, AssetIndex.class); + fileReader.close(); + Map parent = index.getFileMap(); + final int totalSize = parent.size(); + int position = 0; + project.getLogger().lifecycle(":downloading assets..."); + for (Map.Entry entry : parent.entrySet()) { + AssetObject object = entry.getValue(); + String sha1 = object.getHash(); + String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1; + File file = new File(assets, filename); + + if (!file.exists() || !Checksum.equals(file, sha1)) { + project.getLogger().debug(":downloading asset " + entry.getKey()); + DownloadUtil.downloadIfChanged(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, project.getLogger(), true); + } + String assetName = entry.getKey(); + int end = assetName.lastIndexOf("/") + 1; + if (end > 0) { + assetName = assetName.substring(end); + } + progressLogger.progress(assetName + " - " + position + "/" + totalSize + " (" + (int) ((position / (double) totalSize) * 100) + "%) assets downloaded"); + position++; + } + + progressLogger.completed(); + } +} diff --git a/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java b/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java index d073bbd..8e1fd70 100644 --- a/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java +++ b/src/main/java/net/fabricmc/loom/providers/MinecraftLibraryProvider.java @@ -46,7 +46,6 @@ import java.util.Map; public class MinecraftLibraryProvider { public File MINECRAFT_LIBS; - public File MINECRAFT_NATIVES; private Collection libs = new HashSet<>(); @@ -69,50 +68,6 @@ public class MinecraftLibraryProvider { project.getDependencies().add(Constants.MINECRAFT_DEPENDENCIES, project.getDependencies().module(library.getArtifactName())); } } - - MinecraftVersionInfo.AssetIndex assetIndex = versionInfo.assetIndex; - - // get existing cache files - File assets = new File(extension.getUserCache(), "assets"); - if (!assets.exists()) { - assets.mkdirs(); - } - - File assetsInfo = new File(assets, "indexes" + File.separator + assetIndex.getFabricId(minecraftProvider.minecraftVersion) + ".json"); - if (!assetsInfo.exists() || !Checksum.equals(assetsInfo, assetIndex.sha1)) { - project.getLogger().lifecycle(":downloading asset index"); - DownloadUtil.downloadIfChanged(new URL(assetIndex.url), assetsInfo, project.getLogger()); - } - - ProgressLogger progressLogger = ProgressLogger.getProgressFactory(project, getClass().getName()); - progressLogger.start("Downloading assets...", "assets"); - FileReader fileReader = new FileReader(assetsInfo); - AssetIndex index = new Gson().fromJson(fileReader, AssetIndex.class); - fileReader.close(); - Map parent = index.getFileMap(); - final int totalSize = parent.size(); - int position = 0; - project.getLogger().lifecycle(":downloading assets..."); - for (Map.Entry entry : parent.entrySet()) { - AssetObject object = entry.getValue(); - String sha1 = object.getHash(); - String filename = "objects" + File.separator + sha1.substring(0, 2) + File.separator + sha1; - File file = new File(assets, filename); - - if (!file.exists() || !Checksum.equals(file, sha1)) { - project.getLogger().debug(":downloading asset " + entry.getKey()); - DownloadUtil.downloadIfChanged(new URL(Constants.RESOURCES_BASE + sha1.substring(0, 2) + "/" + sha1), file, project.getLogger(), true); - } - String assetName = entry.getKey(); - int end = assetName.lastIndexOf("/") + 1; - if (end > 0) { - assetName = assetName.substring(end); - } - progressLogger.progress(assetName + " - " + position + "/" + totalSize + " (" + (int) ((position / (double) totalSize) * 100) + "%) assets downloaded"); - position++; - } - - progressLogger.completed(); } public Collection getLibraries() { diff --git a/src/main/java/net/fabricmc/loom/task/DownloadAssetsTask.java b/src/main/java/net/fabricmc/loom/task/DownloadAssetsTask.java new file mode 100644 index 0000000..91a71a0 --- /dev/null +++ b/src/main/java/net/fabricmc/loom/task/DownloadAssetsTask.java @@ -0,0 +1,42 @@ +/* + * 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.LoomGradleExtension; +import net.fabricmc.loom.providers.MinecraftAssetsProvider; +import org.gradle.api.Project; +import org.gradle.api.tasks.TaskAction; + +import java.io.IOException; + +public class DownloadAssetsTask extends DefaultLoomTask { + @TaskAction + public void downloadAssets() throws IOException { + Project project = this.getProject(); + LoomGradleExtension extension = project.getExtensions().getByType(LoomGradleExtension.class); + + MinecraftAssetsProvider.provide(extension.getMinecraftProvider(), project); + } +} diff --git a/src/main/java/net/fabricmc/loom/task/LoomFernflowerDecompiler.java b/src/main/java/net/fabricmc/loom/task/LoomFernflowerDecompiler.java index 140d7e9..b7d627e 100644 --- a/src/main/java/net/fabricmc/loom/task/LoomFernflowerDecompiler.java +++ b/src/main/java/net/fabricmc/loom/task/LoomFernflowerDecompiler.java @@ -24,6 +24,7 @@ package net.fabricmc.loom.task; +import net.fabricmc.fernflower.api.IFabricResultSaver; import org.jetbrains.java.decompiler.main.decompiler.BaseDecompiler; import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler; import org.jetbrains.java.decompiler.main.extern.IBytecodeProvider; @@ -37,7 +38,7 @@ import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -public class LoomFernflowerDecompiler extends ConsoleDecompiler { +public class LoomFernflowerDecompiler extends ConsoleDecompiler implements IFabricResultSaver { private final Map differingMappings = new HashMap<>(); private final String jarName; @@ -82,13 +83,19 @@ public class LoomFernflowerDecompiler extends ConsoleDecompiler { } } + @Override + public void saveClassEntry(String s, String s1, String s2, String s3, String s4) { + System.err.println("Warning: No line mapping provided for " + s1 + " : " + s2 + "!"); + super.saveClassEntry(s, s1, s2, s3, s4); + } + @Override public void saveClassEntry(String s, String s1, String s2, String s3, String s4, int[] mapping) { if (mapping != null) { differingMappings.put(s2, mapping); } - super.saveClassEntry(s, jarName, s2, s3, s4, mapping); + super.saveClassEntry(s, jarName, s2, s3, s4); } @Override