Skip to content

Commit

Permalink
Fix refmaps not being recognized when using QMJ
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGlitch76 committed Oct 20, 2024
1 parent 99954c2 commit e218ffb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 20 deletions.
73 changes: 64 additions & 9 deletions patches/0002-Support-QMJ.patch
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,30 @@ index a50d0a99615ff2a23013f90b9381f36ec713b9b9..c70ffbe4be44d5370db4e955b795fe9d
}

private byte[] remapAccessWidener(byte[] input) {
diff --git a/src/main/java/net/fabricmc/loom/task/service/MixinRefmapService.java b/src/main/java/net/fabricmc/loom/task/service/MixinRefmapService.java
index da98bd78505d6763196b73027c55bbc93bbb9670..f1719cae723e82b5b8f5e39a3a86004512169a27 100644
--- a/src/main/java/net/fabricmc/loom/task/service/MixinRefmapService.java
+++ b/src/main/java/net/fabricmc/loom/task/service/MixinRefmapService.java
@@ -32,6 +32,10 @@ import java.util.Objects;
import java.util.stream.Collectors;

import com.google.gson.JsonObject;
+
+import net.fabricmc.loom.api.metadata.ModJson;
+import net.fabricmc.loom.util.metadata.ModJsonFactory;
+
import org.gradle.api.Project;
import org.gradle.api.provider.ListProperty;
import org.gradle.api.provider.Property;
@@ -106,7 +110,7 @@ public class MixinRefmapService extends Service<MixinRefmapService.Options> {
}

public void applyToJar(Path path) throws IOException {
- final FabricModJson fabricModJson = FabricModJsonFactory.createFromZipNullable(path);
+ final ModJson fabricModJson = ModJsonFactory.createFromZipNullable(path);

if (fabricModJson == null) {
return;
diff --git a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJson.java b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJson.java
index 617019cb93a5722de3be614322f4143bb98f1efd..90a0712caa28ccf9dbb669acadaf57eb52e0e377 100644
--- a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJson.java
Expand Down Expand Up @@ -967,7 +991,7 @@ index 617019cb93a5722de3be614322f4143bb98f1efd..90a0712caa28ccf9dbb669acadaf57eb
+ }
}
diff --git a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
index 8c64cecbe7b7a40e7ebc1b47a16eafb419443f7e..3f0c080f06f1b97067038d9a1708ee6582481c8e 100644
index 8c64cecbe7b7a40e7ebc1b47a16eafb419443f7e..784556605cc4130aabd907757b691673ff37f89f 100644
--- a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
+++ b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
@@ -32,6 +32,7 @@ import java.io.Reader;
Expand All @@ -993,7 +1017,7 @@ index 8c64cecbe7b7a40e7ebc1b47a16eafb419443f7e..3f0c080f06f1b97067038d9a1708ee65

private static final Logger LOGGER = LoggerFactory.getLogger(FabricModJsonFactory.class);

@@ -69,7 +71,7 @@ public final class FabricModJsonFactory {
@@ -69,11 +71,12 @@ public final class FabricModJsonFactory {
case 0 -> new FabricModJsonV0(jsonObject, source);
case 1 -> new FabricModJsonV1(jsonObject, source);
case 2 -> new FabricModJsonV2(jsonObject, source);
Expand All @@ -1002,7 +1026,38 @@ index 8c64cecbe7b7a40e7ebc1b47a16eafb419443f7e..3f0c080f06f1b97067038d9a1708ee65
};
}

@@ -117,7 +119,7 @@ public final class FabricModJsonFactory {
- public static FabricModJson createFromZip(Path zipPath) {
+ // Quilt Loom: Add 0 to the end of all factory names so new upstream usages are caught at comptime to be changed to ModJsonFactory
+ public static FabricModJson createFromZip0(Path zipPath) {
try {
return create(ZipUtils.unpackGson(zipPath, FABRIC_MOD_JSON, JsonObject.class), new FabricModJsonSource.ZipSource(zipPath));
} catch (IOException e) {
@@ -84,7 +87,7 @@ public final class FabricModJsonFactory {
}

@Nullable
- public static FabricModJson createFromZipNullable(Path zipPath) {
+ public static FabricModJson createFromZipNullable0(Path zipPath) {
JsonObject jsonObject;

try {
@@ -102,12 +105,12 @@ public final class FabricModJsonFactory {
return create(jsonObject, new FabricModJsonSource.ZipSource(zipPath));
}

- public static Optional<FabricModJson> createFromZipOptional(Path zipPath) {
- return Optional.ofNullable(createFromZipNullable(zipPath));
+ public static Optional<FabricModJson> createFromZipOptional0(Path zipPath) {
+ return Optional.ofNullable(createFromZipNullable0(zipPath));
}

@Nullable
- public static FabricModJson createFromSourceSetsNullable(SourceSet... sourceSets) throws IOException {
+ public static FabricModJson createFromSourceSetsNullable0(SourceSet... sourceSets) throws IOException {
final File file = SourceSetHelper.findFirstFileInResource(FABRIC_MOD_JSON, sourceSets);

if (file == null) {
@@ -117,7 +120,7 @@ public final class FabricModJsonFactory {
try (Reader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
return create(LoomGradlePlugin.GSON.fromJson(reader, JsonObject.class), new FabricModJsonSource.SourceSetSource(sourceSets));
} catch (JsonSyntaxException e) {
Expand All @@ -1011,7 +1066,7 @@ index 8c64cecbe7b7a40e7ebc1b47a16eafb419443f7e..3f0c080f06f1b97067038d9a1708ee65
return null;
} catch (IOException e) {
throw new UncheckedIOException("Failed to read " + file.getAbsolutePath(), e);
@@ -129,10 +131,26 @@ public final class FabricModJsonFactory {
@@ -129,10 +132,26 @@ public final class FabricModJsonFactory {
}

public static boolean isModJar(Path input) {
Expand Down Expand Up @@ -1205,7 +1260,7 @@ index 16239e0bc34a9529bdb10393bbf23697ec504dd7..92ad87480fab5c8ad7a66c6be781b543
}
diff --git a/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java
new file mode 100644
index 0000000000000000000000000000000000000000..7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7
index 0000000000000000000000000000000000000000..2efa025ffca563ae9777111e38874a15ae6f8890
--- /dev/null
+++ b/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java
@@ -0,0 +1,76 @@
Expand Down Expand Up @@ -1254,23 +1309,23 @@ index 0000000000000000000000000000000000000000..7bbcc7cb14f8cab527f11a45c4ff1ece
+ if (FabricModJsonFactory.isQuiltMod(zipPath)) {
+ return QuiltModJsonFactory.createFromZip(zipPath);
+ } else {
+ return FabricModJsonFactory.createFromZip(zipPath);
+ return FabricModJsonFactory.createFromZip0(zipPath);
+ }
+ }
+
+ public static ModJson createFromZipNullable(Path zipPath) {
+ if (FabricModJsonFactory.isQuiltMod(zipPath)) {
+ return QuiltModJsonFactory.createFromZipNullable(zipPath);
+ } else {
+ return FabricModJsonFactory.createFromZipNullable(zipPath);
+ return FabricModJsonFactory.createFromZipNullable0(zipPath);
+ }
+ }
+
+ public static Optional<? extends ModJson> createFromZipOptional(Path zipPath) {
+ if (FabricModJsonFactory.isQuiltMod(zipPath)) {
+ return QuiltModJsonFactory.createFromZipOptional(zipPath);
+ } else {
+ return FabricModJsonFactory.createFromZipOptional(zipPath);
+ return FabricModJsonFactory.createFromZipOptional0(zipPath);
+ }
+ }
+
Expand All @@ -1281,7 +1336,7 @@ index 0000000000000000000000000000000000000000..7bbcc7cb14f8cab527f11a45c4ff1ece
+ if (file != null) {
+ return QuiltModJsonFactory.createFromSourceSetsNullable(sourceSets);
+ } else {
+ return FabricModJsonFactory.createFromSourceSetsNullable(sourceSets);
+ return FabricModJsonFactory.createFromSourceSetsNullable0(sourceSets);
+ }
+ }
+}
Expand Down
18 changes: 9 additions & 9 deletions patches/0004-Support-QMJ5.patch
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ index 9d73a4c24bc02d075165bf1a6f59fb85d6c05ce2..ef3bc3a3c5fab04b887a84e113349dd4
public interface UnsafeUnaryOperator<T> {
T apply(T arg) throws IOException;
diff --git a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
index 3f0c080f06f1b97067038d9a1708ee6582481c8e..48d49e1a115bffceeaaf8eb69c92e9a76a07aa24 100644
index 784556605cc4130aabd907757b691673ff37f89f..e37c6d709704be64836138c0730ba2227f030501 100644
--- a/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
+++ b/src/main/java/net/fabricmc/loom/util/fmj/FabricModJsonFactory.java
@@ -131,11 +131,15 @@ public final class FabricModJsonFactory {
@@ -132,11 +132,15 @@ public final class FabricModJsonFactory {
}

public static boolean isModJar(Path input) {
Expand All @@ -235,7 +235,7 @@ index 3f0c080f06f1b97067038d9a1708ee6582481c8e..48d49e1a115bffceeaaf8eb69c92e9a7
}

public static boolean isQuiltMod(Path jar) {
@@ -150,7 +154,25 @@ public final class FabricModJsonFactory {
@@ -151,7 +155,25 @@ public final class FabricModJsonFactory {
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ index d0e1e13b984c9360bf60e3b63cf81121410eca45..dca62d1a748ea65fa1da24b78c1073df
// Returns a list of Mods found in the provided project's main or client sourcesets
public static List<ModJson> getModsInProject(Project project) {
diff --git a/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java
index 7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7..b52165453eff6054518e7bbbc46021f2e11bc042 100644
index 2efa025ffca563ae9777111e38874a15ae6f8890..09096afa467f2c6d4ae6b61715e025548d661777 100644
--- a/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java
+++ b/src/main/java/net/fabricmc/loom/util/metadata/ModJsonFactory.java
@@ -40,7 +40,9 @@ import net.fabricmc.loom.util.qmj.QuiltModJsonFactory;
Expand All @@ -288,7 +288,7 @@ index 7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7..b52165453eff6054518e7bbbc46021f2
+ } else if (FabricModJsonFactory.isQuiltMod(zipPath)) {
return QuiltModJsonFactory.createFromZip(zipPath);
} else {
return FabricModJsonFactory.createFromZip(zipPath);
return FabricModJsonFactory.createFromZip0(zipPath);
@@ -48,7 +50,9 @@ public class ModJsonFactory {
}

Expand All @@ -299,7 +299,7 @@ index 7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7..b52165453eff6054518e7bbbc46021f2
+ } else if (FabricModJsonFactory.isQuiltMod(zipPath)) {
return QuiltModJsonFactory.createFromZipNullable(zipPath);
} else {
return FabricModJsonFactory.createFromZipNullable(zipPath);
return FabricModJsonFactory.createFromZipNullable0(zipPath);
@@ -56,7 +60,9 @@ public class ModJsonFactory {
}

Expand All @@ -310,7 +310,7 @@ index 7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7..b52165453eff6054518e7bbbc46021f2
+ } else if (FabricModJsonFactory.isQuiltMod(zipPath)) {
return QuiltModJsonFactory.createFromZipOptional(zipPath);
} else {
return FabricModJsonFactory.createFromZipOptional(zipPath);
return FabricModJsonFactory.createFromZipOptional0(zipPath);
@@ -65,12 +71,18 @@ public class ModJsonFactory {

@Nullable
Expand All @@ -322,15 +322,15 @@ index 7bbcc7cb14f8cab527f11a45c4ff1ece52e56dd7..b52165453eff6054518e7bbbc46021f2
- return QuiltModJsonFactory.createFromSourceSetsNullable(sourceSets);
+ return QuiltModJsonFactory.createFromJson5SourceSetsNullable(sourceSets);
} else {
- return FabricModJsonFactory.createFromSourceSetsNullable(sourceSets);
- return FabricModJsonFactory.createFromSourceSetsNullable0(sourceSets);
+ File qmjFile = SourceSetHelper.findFirstFileInResource(FabricModJsonHelpers.QUILT_MOD_JSON, sourceSets);
+
+ if (qmjFile != null) {
+ return QuiltModJsonFactory.createFromSourceSetsNullable(sourceSets);
+ }
}
+
+ return FabricModJsonFactory.createFromSourceSetsNullable(sourceSets);
+ return FabricModJsonFactory.createFromSourceSetsNullable0(sourceSets);
}
}
diff --git a/src/main/java/net/fabricmc/loom/util/qmj/QuiltModJsonFactory.java b/src/main/java/net/fabricmc/loom/util/qmj/QuiltModJsonFactory.java
Expand Down
28 changes: 26 additions & 2 deletions patches/0005-Prefer-Quilt-over-Fabric-Loader.patch
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,34 @@ index 009d91ecafc42640135d9ebf5c1eb06be323e115..ac9c0ac012c82a50cb95eb4a9ac8a776
// Go through all the configs to find artifacts to remap and
diff --git a/src/main/java/net/fabricmc/loom/util/FabricCapabilities.java b/src/main/java/net/fabricmc/loom/util/FabricCapabilities.java
new file mode 100644
index 0000000000000000000000000000000000000000..18a7fd910a93e363852f16bd6c686ce4a68436f7
index 0000000000000000000000000000000000000000..a0b77bedca33b58cc7112002dae4527cc5aa61c1
--- /dev/null
+++ b/src/main/java/net/fabricmc/loom/util/FabricCapabilities.java
@@ -0,0 +1,19 @@
@@ -0,0 +1,43 @@
+/*
+ * This file is part of fabric-loom, licensed under the MIT License (MIT).
+ *
+ * Copyright (c) 2024 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.util;
+
+import org.gradle.api.artifacts.CacheableRule;
Expand Down

0 comments on commit e218ffb

Please sign in to comment.