Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 1.13.2 support #11

Open
wants to merge 4 commits into
base: dev/1.6
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ dependencies {
implementation libs.night.config.toml

// Legacy Forge patches
implementation libs.lzma
implementation libs.xz

// Testing
testImplementation(gradleTestKit())
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ forge-diffpatch = "2.0.7"
night-config = "3.6.6"
datafixerupper = "6.0.8"
at = "1.0.1"
lzma = "1.3"
xz = "1.8"

[libraries]
# Loom compile libraries
Expand Down Expand Up @@ -65,7 +65,7 @@ forge-diffpatch = { module = "net.minecraftforge:DiffPatch", version.ref = "forg
night-config-toml = { module = "com.electronwill.night-config:toml", version.ref = "night-config" }
datafixerupper = { module = "com.mojang:datafixerupper", version.ref = "datafixerupper" }
at = { module = "dev.architectury:at", version.ref = "at" }
lzma = { module = "com.github.jponge:lzma-java", version.ref = "lzma" }
xz = { module = "org.tukaani:xz", version.ref = "xz" }

[plugins]
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/net/fabricmc/loom/LoomGradleExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ default boolean isForgeLikeAndNotOfficial() {
return isForgeLike() && !getMcpConfigProvider().isOfficial();
}

default int getForgeSpec() {
return getForgeUserdevProvider().getForgeSpec();
}

default boolean isLegacyForge() {
return isForge() && getForgeUserdevProvider().isLegacyForge();
return isForge() && getForgeSpec() <= 1;
}

default boolean isModernForge() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ private synchronized void setupMinecraft(ConfigContext configContext) throws Exc
// but before MinecraftPatchedProvider.provide.
setupDependencyProviders(project, extension);

if (extension.isLegacyForge()) {
if (extension.getForgeSpec() <= 2) {
extension.setIntermediateMappingsProvider(GeneratedIntermediateMappingsProvider.class, provider -> {
provider.minecraftProvider = minecraftProvider;
});
}

if (extension.isForgeLike() && !extension.isLegacyForge()) {
if (extension.isForgeLike() && extension.getForgeSpec() > 2) {
// Excluded on legacy forge because it pulls in a log4j-api version newer than what forge wants and we don't
// need it anyway
project.getDependencies().add(Constants.Configurations.FORGE_EXTRA, LoomVersions.UNPROTECT.mavenNotation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ForgeMigratedMappingConfiguration(String mappingsIdentifier, Path mapping
protected void manipulateMappings(Project project, Path mappingsJar) throws IOException {
LoomGradleExtension extension = LoomGradleExtension.get(project);

if (extension.isLegacyForge()) {
if (extension.getForgeSpec() <= 2) {
// Legacy forge patches are in official namespace, so if the type of a field is changed by them, then that
// is effectively a new field and not traceable to any mapping. Therefore this does not apply to it.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ForgeUserdevProvider extends DependencyProvider {
private JsonObject json;
private UserdevConfig config;
Path joinedPatches;
private Boolean isLegacyForge;
private Integer forgeSpec;

public ForgeUserdevProvider(Project project) {
super(project);
Expand Down Expand Up @@ -88,10 +88,13 @@ public void provide(DependencyInfo dependency) throws Exception {

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

if (isLegacyForge) {
if (forgeSpec <= 1) {
json = createManifestFromForgeGradle2(dependency, json);
} else if (forgeSpec <= 2) {
addLegacyMCPRepo();
}

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

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

if (!isLegacyForge && Files.notExists(joinedPatches)) {
if (forgeSpec >= 2 && Files.notExists(joinedPatches)) {
Files.write(joinedPatches, ZipUtils.unpack(userdevJar.toPath(), config.binpatches()));
}
}
Expand Down Expand Up @@ -210,12 +213,12 @@ private void addLegacyMCPRepo() {
});
}

public boolean isLegacyForge() {
if (isLegacyForge == null) {
public int getForgeSpec() {
if (forgeSpec == null) {
throw new IllegalArgumentException("Not yet resolved.");
}

return isLegacyForge;
return forgeSpec;
}

public File getUserdevJar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;

import lzma.sdk.lzma.Decoder;
import lzma.sdk.lzma.Encoder;
import lzma.streams.LzmaInputStream;
import lzma.streams.LzmaOutputStream;
import org.apache.commons.io.IOUtils;
import org.gradle.api.Project;
import org.tukaani.xz.LZMA2Options;
import org.tukaani.xz.LZMAInputStream;
import org.tukaani.xz.LZMAOutputStream;

import net.fabricmc.loom.configuration.DependencyInfo;
import net.fabricmc.loom.configuration.providers.forge.fg2.Pack200Provider;
Expand Down Expand Up @@ -99,12 +98,12 @@ private void init() {

private void splitAndConvertLegacyPatches(Path joinedLegacyPatches) throws IOException {
try (JarInputStream in = new JarInputStream(new ByteArrayInputStream(unpack200Lzma(joinedLegacyPatches)));
OutputStream clientFileOut = Files.newOutputStream(clientPatches, CREATE, TRUNCATE_EXISTING);
LzmaOutputStream clientLzmaOut = new LzmaOutputStream(clientFileOut, new Encoder());
JarOutputStream clientJarOut = new JarOutputStream(clientLzmaOut);
OutputStream serverFileOut = Files.newOutputStream(serverPatches, CREATE, TRUNCATE_EXISTING);
LzmaOutputStream serverLzmaOut = new LzmaOutputStream(serverFileOut, new Encoder());
JarOutputStream serverJarOut = new JarOutputStream(serverLzmaOut);
OutputStream clientFileOut = Files.newOutputStream(clientPatches, CREATE, TRUNCATE_EXISTING);
LZMAOutputStream clientLzmaOut = new LZMAOutputStream(clientFileOut, new LZMA2Options(), -1);
JarOutputStream clientJarOut = new JarOutputStream(clientLzmaOut);
OutputStream serverFileOut = Files.newOutputStream(serverPatches, CREATE, TRUNCATE_EXISTING);
LZMAOutputStream serverLzmaOut = new LZMAOutputStream(serverFileOut, new LZMA2Options(), -1);
JarOutputStream serverJarOut = new JarOutputStream(serverLzmaOut)
) {
for (JarEntry entry; (entry = in.getNextJarEntry()) != null;) {
String name = entry.getName();
Expand Down Expand Up @@ -153,7 +152,7 @@ private byte[] unpack200(InputStream in) throws IOException {
}

private byte[] unpack200Lzma(InputStream in) throws IOException {
try (LzmaInputStream lzmaIn = new LzmaInputStream(in, new Decoder())) {
try (LZMAInputStream lzmaIn = new LZMAInputStream(in)) {
return unpack200(lzmaIn);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ForgeTest extends Specification implements GradleProjectTestTrait {
'1.16.5' | '36.2.4' | '8' | '"de.oceanlabs.mcp:mcp_snapshot:20210309-1.16.5"'
'1.14.4' | "28.2.23" | '8' | "loom.officialMojangMappings()"
'1.14.4' | "28.2.23" | '8' | '"net.fabricmc:yarn:1.14.4+build.18:v2"'
'1.13.2' | "25.0.223" | '8' | '"de.oceanlabs.mcp:mcp_stable:47-1.13.2"'
'1.12.2' | "14.23.0.2486" | '8' | '"de.oceanlabs.mcp:mcp_snapshot:20170615-1.12"'
'1.8.9' | "11.15.1.2318-1.8.9" | '8' | '"de.oceanlabs.mcp:mcp_stable:22-1.8.9"'
}
Expand Down