add minVersion filling support - fix #34
parent
fe194ea64d
commit
83d6a2da42
|
@ -41,7 +41,7 @@ dependencies {
|
||||||
// implementation ('org.benf:cfr:0.136')
|
// implementation ('org.benf:cfr:0.136')
|
||||||
implementation ('org.jetbrains:intellij-fernflower:1.0.0.2')
|
implementation ('org.jetbrains:intellij-fernflower:1.0.0.2')
|
||||||
|
|
||||||
implementation ('net.fabricmc:sponge-mixin:0.7.11.4') {
|
implementation ('net.fabricmc:sponge-mixin:0.7.11.10') {
|
||||||
exclude module: 'launchwrapper'
|
exclude module: 'launchwrapper'
|
||||||
exclude module: 'guava'
|
exclude module: 'guava'
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,14 @@ import net.fabricmc.loom.providers.MinecraftMappedProvider;
|
||||||
import net.fabricmc.loom.providers.MinecraftProvider;
|
import net.fabricmc.loom.providers.MinecraftProvider;
|
||||||
import net.fabricmc.loom.util.LoomDependencyManager;
|
import net.fabricmc.loom.util.LoomDependencyManager;
|
||||||
import org.gradle.api.Project;
|
import org.gradle.api.Project;
|
||||||
|
import org.gradle.api.artifacts.Dependency;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class LoomGradleExtension {
|
public class LoomGradleExtension {
|
||||||
public String runDir = "run";
|
public String runDir = "run";
|
||||||
|
@ -74,6 +77,24 @@ public class LoomGradleExtension {
|
||||||
return projectCache;
|
return projectCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getMixinVersion() {
|
||||||
|
for (Dependency dependency : project.getConfigurations().getByName("compile").getDependencies()) {
|
||||||
|
if (dependency.getName().equalsIgnoreCase("mixin") && dependency.getGroup().equals("org.spongepowered")) {
|
||||||
|
return dependency.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dependency.getName().equals("sponge-mixin") && dependency.getGroup().equals("net.fabricmc")) {
|
||||||
|
if (Objects.requireNonNull(dependency.getVersion()).split("\\.").length >= 4) {
|
||||||
|
return dependency.getVersion().substring(0, dependency.getVersion().lastIndexOf('.')) + "-SNAPSHOT";
|
||||||
|
}
|
||||||
|
return dependency.getVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public LoomDependencyManager getDependencyManager() {
|
public LoomDependencyManager getDependencyManager() {
|
||||||
return dependencyManager;
|
return dependencyManager;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class LoomDependencyManager {
|
||||||
}
|
}
|
||||||
for(String config : targetConfigs){
|
for(String config : targetConfigs){
|
||||||
Configuration configuration = project.getConfigurations().getByName(config);
|
Configuration configuration = project.getConfigurations().getByName(config);
|
||||||
configuration.getDependencies().stream().forEach(dependency -> {
|
configuration.getDependencies().forEach(dependency -> {
|
||||||
for(DependencyProvider provider : dependencyProviderList){
|
for(DependencyProvider provider : dependencyProviderList){
|
||||||
if(provider.getTargetConfig().equals(config)){
|
if(provider.getTargetConfig().equals(config)){
|
||||||
DependencyProvider.DependencyInfo info = new DependencyProvider.DependencyInfo(dependency, configuration);
|
DependencyProvider.DependencyInfo info = new DependencyProvider.DependencyInfo(dependency, configuration);
|
||||||
|
|
|
@ -50,7 +50,7 @@ public final class MixinRefmapHelper {
|
||||||
private MixinRefmapHelper() {
|
private MixinRefmapHelper() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public static boolean addRefmapName(String filename, File output) {
|
public static boolean addRefmapName(String filename, String mixinVersion, File output) {
|
||||||
Set<String> mixinFilenames = findMixins(output, true);
|
Set<String> mixinFilenames = findMixins(output, true);
|
||||||
|
|
||||||
if (mixinFilenames.size() > 0) {
|
if (mixinFilenames.size() > 0) {
|
||||||
|
@ -61,7 +61,12 @@ public final class MixinRefmapHelper {
|
||||||
@Override
|
@Override
|
||||||
protected String transform(ZipEntry zipEntry, String input) throws IOException {
|
protected String transform(ZipEntry zipEntry, String input) throws IOException {
|
||||||
JsonObject json = GSON.fromJson(input, JsonObject.class);
|
JsonObject json = GSON.fromJson(input, JsonObject.class);
|
||||||
json.addProperty("refmap", filename);
|
if (!json.has("refmap")) {
|
||||||
|
json.addProperty("refmap", filename);
|
||||||
|
}
|
||||||
|
if (!json.has("minVersion") && mixinVersion != null) {
|
||||||
|
json.addProperty("minVersion", mixinVersion);
|
||||||
|
}
|
||||||
return GSON.toJson(json);
|
return GSON.toJson(json);
|
||||||
}
|
}
|
||||||
})).toArray(ZipEntryTransformerEntry[]::new)
|
})).toArray(ZipEntryTransformerEntry[]::new)
|
||||||
|
@ -82,7 +87,7 @@ public final class MixinRefmapHelper {
|
||||||
try {
|
try {
|
||||||
JsonObject json = GSON.fromJson(inputStreamReader, JsonObject.class);
|
JsonObject json = GSON.fromJson(inputStreamReader, JsonObject.class);
|
||||||
if (json != null && json.has("mixins") && json.get("mixins").isJsonArray()) {
|
if (json != null && json.has("mixins") && json.get("mixins").isJsonArray()) {
|
||||||
if (!onlyWithoutRefmap || !json.has("refmap")) {
|
if (!onlyWithoutRefmap || !json.has("refmap") || !json.has("minVersion")) {
|
||||||
mixinFilename.add(entry.getName());
|
mixinFilename.add(entry.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ 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 org.gradle.api.artifacts.Dependency;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -100,7 +101,7 @@ public class ModRemapper {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (extension.refmapName != null && extension.refmapName.length() > 0) {
|
if (extension.refmapName != null && extension.refmapName.length() > 0) {
|
||||||
if (MixinRefmapHelper.addRefmapName(extension.refmapName, modJarOutput)) {
|
if (MixinRefmapHelper.addRefmapName(extension.refmapName, extension.getMixinVersion(), modJarOutput)) {
|
||||||
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
|
project.getLogger().debug("Transformed mixin reference maps in output JAR!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue