Skip to content

Commit

Permalink
ADDED: Reading maven-metadata to download the latest parchment mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
WinPlay02 committed Oct 5, 2023
1 parent 219a4cc commit 990731f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
5 changes: 3 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To disabled versioning entirely (and only decompile), specify `--no-repo`.

To disable special versions (e.g. april fools or combat snapshots), specify `--skip-nonlinear`.

To use other mappings than mojmaps, specify `--mappings=<mapping>`. Supported mappings are `mojmap`, `fabric_intermediary` and `yarn`.
To use other mappings than mojmaps, specify `--mappings=<mapping>`. Supported mappings are `mojmap`, `mojmap_parchment`, `fabric_intermediary` and `yarn`.

Powered by:
- [Vineflower](https://github.com/Vineflower/vineflower)
Expand All @@ -29,6 +29,7 @@ Powered by:
- [Loom](https://github.com/FabricMC/fabric-loom)
- [Yarn](https://github.com/FabricMC/yarn)
- [Fabric Intermediary Mappings](https://github.com/FabricMC/intermediary)
- [Parchment](https://github.com/ParchmentMC/Parchment)

## Help / Usage

Expand All @@ -39,7 +40,7 @@ Options:
--mappings=<mapping> Specifies the mappings used to decompile the
source tree. Mojmaps are selected by default.
Possible values are: mojmap,
fabric_intermediary, yarn
fabric_intermediary, yarn, mojmap_parchment
--min-version=<version>
Specify the min. version to decompile. Each
following version will be decompiled afterwards,
Expand Down
16 changes: 7 additions & 9 deletions src/main/groovy/com/github/winplay02/MappingHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public Optional<Path> getMappingsPath(McVersion mcVersion) {
case MOJMAP_PARCHMENT -> {
try {
yield Optional.of(mappingsPathParchment(mcVersion));
} catch (IOException e) {
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Expand Down Expand Up @@ -165,19 +165,17 @@ public static MemoryMappingTree createIntermediaryMappingsProvider(McVersion mcV
return mappingTree;
}

private static Path mappingsPathParchment(McVersion mcVersion) throws IOException {
if (!mcVersion.version.equals("1.20.1")) {
throw new RuntimeException("This is a testing implementation, other versions are not yet supported");
}
Path mappingsFileTiny = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s.tiny", mcVersion.version, "1.20.1-2023.09.03"));
private static Path mappingsPathParchment(McVersion mcVersion) throws Exception {
String parchmentLatestReleaseVersionBuild = RemoteHelper.readMavenLatestRelease(String.format("https://maven.parchmentmc.org/org/parchmentmc/data/parchment-%s/maven-metadata.xml", mcVersion.version));
Path mappingsFileTiny = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s-%s.tiny", mcVersion.version, mcVersion.version, parchmentLatestReleaseVersionBuild));
if (mappingsFileTiny.toFile().exists()) {
return mappingsFileTiny;
}
Path mappingsFileJson = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s.json", mcVersion.version, "1.20.1-2023.09.03"));
Path mappingsFileJson = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s-%s.json", mcVersion.version, mcVersion.version, parchmentLatestReleaseVersionBuild));
if (!mappingsFileJson.toFile().exists()) {
Path mappingsFileJar = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s.jar", mcVersion.version, "1.20.1-2023.09.03"));
Path mappingsFileJar = GitCraft.MAPPINGS.resolve(String.format("%s-parchment-%s-%s.jar", mcVersion.version, mcVersion.version, parchmentLatestReleaseVersionBuild));
RemoteHelper.downloadToFileWithChecksumIfNotExistsNoRetry(
"https://maven.parchmentmc.org/org/parchmentmc/data/parchment-1.20.1/2023.09.03/parchment-1.20.1-2023.09.03.zip",
String.format("https://maven.parchmentmc.org/org/parchmentmc/data/parchment-%s/%s/parchment-%s-%s.zip", mcVersion.version, parchmentLatestReleaseVersionBuild, mcVersion.version, parchmentLatestReleaseVersionBuild),
mappingsFileJar,
null,
"parchment mapping",
Expand Down
8 changes: 8 additions & 0 deletions src/main/groovy/com/github/winplay02/RemoteHelper.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.github.winplay02;

import dex.mcgitmaker.GitCraft;
import org.w3c.dom.Document;

import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPathFactory;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -197,4 +200,9 @@ public static String urlencodedURL(String url) {
throw new RuntimeException(e);
}
}

public static String readMavenLatestRelease(String mavenMetadata) throws Exception {
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(mavenMetadata);
return XPathFactory.newInstance().newXPath().compile("/metadata/versioning/release").evaluate(document);
}
}

0 comments on commit 990731f

Please sign in to comment.