Skip to content

Commit 9af707a

Browse files
committed
Fix 1.13.2 support
1 parent 22f1011 commit 9af707a

File tree

11 files changed

+43
-27
lines changed

11 files changed

+43
-27
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ dependencies {
165165
implementation libs.night.config.toml
166166

167167
// Legacy Forge patches
168-
implementation libs.lzma
168+
implementation libs.xz
169169

170170
// Testing
171171
testImplementation(gradleTestKit())

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ forge-diffpatch = "2.0.7"
2828
night-config = "3.6.6"
2929
datafixerupper = "6.0.8"
3030
at = "1.0.1"
31-
lzma = "1.3"
31+
xz = "1.8"
3232

3333
[libraries]
3434
# Loom compile libraries
@@ -63,7 +63,7 @@ forge-diffpatch = { module = "net.minecraftforge:DiffPatch", version.ref = "forg
6363
night-config-toml = { module = "com.electronwill.night-config:toml", version.ref = "night-config" }
6464
datafixerupper = { module = "com.mojang:datafixerupper", version.ref = "datafixerupper" }
6565
at = { module = "dev.architectury:at", version.ref = "at" }
66-
lzma = { module = "com.github.jponge:lzma-java", version.ref = "lzma" }
66+
xz = { module = "org.tukaani:xz", version.ref = "xz" }
6767

6868
[plugins]
6969
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

src/main/java/net/fabricmc/loom/LoomGradleExtension.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,12 @@ default boolean isForgeLikeAndNotOfficial() {
178178
return isForgeLike() && !getMcpConfigProvider().isOfficial();
179179
}
180180

181+
default int getForgeSpec() {
182+
return getForgeUserdevProvider().getForgeSpec();
183+
}
184+
181185
default boolean isLegacyForge() {
182-
return isForge() && getForgeUserdevProvider().isLegacyForge();
186+
return isForge() && getForgeSpec() <= 1;
183187
}
184188

185189
default boolean isModernForge() {

src/main/java/net/fabricmc/loom/configuration/CompileConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ private synchronized void setupMinecraft(ConfigContext configContext) throws Exc
227227
// but before MinecraftPatchedProvider.provide.
228228
setupDependencyProviders(project, extension);
229229

230-
if (extension.isLegacyForge()) {
230+
if (extension.getForgeSpec() <= 2) {
231231
extension.setIntermediateMappingsProvider(GeneratedIntermediateMappingsProvider.class, provider -> {
232232
provider.minecraftProvider = minecraftProvider;
233233
});
234234
}
235235

236-
if (extension.isForgeLike() && !extension.isLegacyForge()) {
236+
if (extension.isForgeLike() && extension.getForgeSpec() > 2) {
237237
// Excluded on legacy forge because it pulls in a log4j-api version newer than what forge wants and we don't
238238
// need it anyway
239239
project.getDependencies().add(Configurations.FORGE_EXTRA, LoomVersions.UNPROTECT.mavenNotation());

src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeMigratedMappingConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public ForgeMigratedMappingConfiguration(String mappingsIdentifier, Path mapping
5353
protected void manipulateMappings(Project project, Path mappingsJar) throws IOException {
5454
LoomGradleExtension extension = LoomGradleExtension.get(project);
5555

56-
if (extension.isLegacyForge()) {
56+
if (extension.getForgeSpec() <= 2) {
5757
// Legacy forge patches are in official namespace, so if the type of a field is changed by them, then that
5858
// is effectively a new field and not traceable to any mapping. Therefore this does not apply to it.
5959
return;

src/main/java/net/fabricmc/loom/configuration/providers/forge/ForgeUserdevProvider.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
5353
private JsonObject json;
5454
private UserdevConfig config;
5555
Path joinedPatches;
56-
private Boolean isLegacyForge;
56+
private Integer forgeSpec;
5757

5858
public ForgeUserdevProvider(Project project) {
5959
super(project);
@@ -88,10 +88,13 @@ public void provide(DependencyInfo dependency) throws Exception {
8888

8989
try (Reader reader = Files.newBufferedReader(configJson)) {
9090
json = new Gson().fromJson(reader, JsonObject.class);
91-
isLegacyForge = !json.has("mcp");
91+
// Some Forge versions for 1.13.2 specify mcp, but have spec=1. We just "hack" this here.
92+
forgeSpec = json.has("mcp") ? Math.max(2, json.get("spec").getAsInt()) : 1;
9293

93-
if (isLegacyForge) {
94+
if (forgeSpec <= 1) {
9495
json = createManifestFromForgeGradle2(dependency, json);
96+
} else if (forgeSpec <= 2) {
97+
addLegacyMCPRepo();
9598
}
9699

97100
config = UserdevConfig.CODEC.parse(JsonOps.INSTANCE, json)
@@ -106,7 +109,7 @@ public void provide(DependencyInfo dependency) throws Exception {
106109

107110
addDependency(config.universal(), Constants.Configurations.FORGE_UNIVERSAL);
108111

109-
if (!isLegacyForge && Files.notExists(joinedPatches)) {
112+
if (forgeSpec >= 2 && Files.notExists(joinedPatches)) {
110113
Files.write(joinedPatches, ZipUtils.unpack(userdevJar.toPath(), config.binpatches()));
111114
}
112115
}
@@ -177,6 +180,10 @@ private static JsonObject createLegacyRuns() {
177180
private static JsonArray createLegacyAts() {
178181
JsonArray array = new JsonArray();
179182
array.add("merged_at.cfg");
183+
array.add("forge_at.cfg");
184+
array.add("fml_at.cfg");
185+
array.add("src/main/resources/forge_at.cfg");
186+
array.add("src/main/resources/fml_at.cfg");
180187
return array;
181188
}
182189

@@ -217,12 +224,12 @@ private void addLegacyMCPRepo() {
217224
});
218225
}
219226

220-
public boolean isLegacyForge() {
221-
if (isLegacyForge == null) {
227+
public int getForgeSpec() {
228+
if (forgeSpec == null) {
222229
throw new IllegalArgumentException("Not yet resolved.");
223230
}
224231

225-
return isLegacyForge;
232+
return forgeSpec;
226233
}
227234

228235
public File getUserdevJar() {

src/main/java/net/fabricmc/loom/configuration/providers/forge/PatchProvider.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,11 @@
4343
import java.util.jar.JarOutputStream;
4444
import java.util.zip.ZipEntry;
4545

46-
import lzma.sdk.lzma.Decoder;
47-
import lzma.sdk.lzma.Encoder;
48-
import lzma.streams.LzmaInputStream;
49-
import lzma.streams.LzmaOutputStream;
5046
import org.apache.commons.io.IOUtils;
5147
import org.gradle.api.Project;
48+
import org.tukaani.xz.LZMA2Options;
49+
import org.tukaani.xz.LZMAInputStream;
50+
import org.tukaani.xz.LZMAOutputStream;
5251

5352
import net.fabricmc.loom.configuration.DependencyInfo;
5453
import net.fabricmc.loom.configuration.providers.forge.fg2.Pack200Provider;
@@ -100,11 +99,11 @@ private void init() {
10099
private void splitAndConvertLegacyPatches(Path joinedLegacyPatches) throws IOException {
101100
try (JarInputStream in = new JarInputStream(new ByteArrayInputStream(unpack200Lzma(joinedLegacyPatches)));
102101
OutputStream clientFileOut = Files.newOutputStream(clientPatches, CREATE, TRUNCATE_EXISTING);
103-
LzmaOutputStream clientLzmaOut = new LzmaOutputStream(clientFileOut, new Encoder());
102+
LZMAOutputStream clientLzmaOut = new LZMAOutputStream(clientFileOut, new LZMA2Options(), -1);
104103
JarOutputStream clientJarOut = new JarOutputStream(clientLzmaOut);
105104
OutputStream serverFileOut = Files.newOutputStream(serverPatches, CREATE, TRUNCATE_EXISTING);
106-
LzmaOutputStream serverLzmaOut = new LzmaOutputStream(serverFileOut, new Encoder());
107-
JarOutputStream serverJarOut = new JarOutputStream(serverLzmaOut);
105+
LZMAOutputStream serverLzmaOut = new LZMAOutputStream(serverFileOut, new LZMA2Options(), -1);
106+
JarOutputStream serverJarOut = new JarOutputStream(serverLzmaOut)
108107
) {
109108
for (JarEntry entry; (entry = in.getNextJarEntry()) != null;) {
110109
String name = entry.getName();
@@ -153,7 +152,7 @@ private byte[] unpack200(InputStream in) throws IOException {
153152
}
154153

155154
private byte[] unpack200Lzma(InputStream in) throws IOException {
156-
try (LzmaInputStream lzmaIn = new LzmaInputStream(in, new Decoder())) {
155+
try (LZMAInputStream lzmaIn = new LZMAInputStream(in)) {
157156
return unpack200(lzmaIn);
158157
}
159158
}

src/main/java/net/fabricmc/loom/configuration/providers/mappings/MappingConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private static void mergeSrg(Project project, Path source, Path target) throws I
319319
LoomGradleExtension extension = LoomGradleExtension.get(project);
320320

321321
// FIXME why is this special case necessary?
322-
ForgeMappingsMerger.ExtraMappings extraMappings = extension.isLegacyForge()
322+
ForgeMappingsMerger.ExtraMappings extraMappings = extension.getForgeSpec() <= 2
323323
? null
324324
: ForgeMappingsMerger.ExtraMappings.ofMojmapTsrg(getMojmapSrgFileIfPossible(project));
325325

@@ -419,7 +419,8 @@ private void readAndMergeMCP(Project project, ServiceFactory serviceFactory, Min
419419

420420
private boolean isMCP(Path path) throws IOException {
421421
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(path, false)) {
422-
return Files.exists(fs.getPath("fields.csv")) && Files.exists(fs.getPath("methods.csv"));
422+
return Files.exists(fs.getPath("fields.csv")) && Files.exists(fs.getPath("methods.csv"))
423+
|| (Files.exists(fs.getPath("conf/fields.csv")) && Files.exists(fs.getPath("conf/methods.csv")));
423424
}
424425
}
425426

src/main/java/net/fabricmc/loom/decompilers/cache/ClassEntry.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@ public record ClassEntry(String name, List<String> innerClasses, List<String> su
5050
throw new IllegalArgumentException("Class name must end with '.class': " + name);
5151
}
5252

53-
if (!name.contains("/")) {
54-
throw new IllegalArgumentException("Class name must be in a package: " + name);
55-
}
53+
// breaks in some 1.7.10 classes:
54+
// if (!name.contains("/")) {
55+
// throw new IllegalArgumentException("Class name must be in a package: " + name);
56+
// }
5657

5758
String className = name.replace(".class", "");
5859

src/main/java/net/fabricmc/loom/util/srg/MCPReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ private void injectMcp(Path mcpJar, Map<String, String> intermediaryToSrgMap, Ma
194194

195195
try (FileSystemUtil.Delegate fs = FileSystemUtil.getJarFileSystem(mcpJar, false)) {
196196
Path fields = fs.getPath("fields.csv");
197+
if (!Files.exists(fields)) fields = fs.getPath("conf/fields.csv");
197198
Path methods = fs.getPath("methods.csv");
199+
if (!Files.exists(methods)) methods = fs.getPath("conf/methods.csv");
198200
Path params = fs.getPath("params.csv");
201+
if (!Files.exists(params)) params = fs.getPath("conf/params.csv");
199202
Pattern paramsPattern = Pattern.compile("p_[^\\d]*(\\d+)_(\\d)+_?");
200203

201204
try (CSVReader reader = new CSVReader(Files.newBufferedReader(fields, StandardCharsets.UTF_8))) {

0 commit comments

Comments
 (0)