Skip to content

Commit

Permalink
add parchment mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Dec 6, 2022
1 parent 31b2717 commit 901382f
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 26 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ unified minecraft modding environment.
* ~~test user AT support~~
* ~~fix fg3 versions of 1.12.2~~
* ~~fabric aw support~~
* combined jar support : forge 1.13+ does this, do with the rest
* combined jar support : forge 1.13+ does this, do with the rest - also fix split jars on fg3
* ~~figure out how to get forge to recognise resources as part of the dev mod~~
* split fg2+ out of the mc jar
* figure out how to do automated testing
Expand All @@ -42,8 +42,8 @@ unified minecraft modding environment.
be part of the legacy mc version.json, or at least betacraft's, but it's not
* ~~make myself a maven to host this on~~: https://maven.wagyourtail.xyz
* ~~fix forge mappings on 1.17+~~
* mixin support

* ~~mixin support~~
* ~~add parchment mappings support~~

## Example Usage

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package net.fabricmc.mappingio.format

import com.google.gson.JsonObject
import com.google.gson.JsonParser
import net.fabricmc.mappingio.MappedElementKind
import net.fabricmc.mappingio.tree.MemoryMappingTree
import java.io.Reader

object ParchmentReader {

fun read(reader: Reader, targetNs: String, visitor: MemoryMappingTree) {
read(JsonParser.parseReader(reader).asJsonObject, targetNs, visitor)
}

fun read(json: JsonObject, targetNs: String, visitor: MemoryMappingTree) {

if (visitor.visitHeader()) {
visitor.visitNamespaces(targetNs, listOf(targetNs))
}

if (visitor.visitContent()) {

// packages
// json.get("packages")?.asJsonArray?.forEach {
// // mappingio doesn't support package comments
// }

// classes
json.get("classes")?.asJsonArray?.map { it.asJsonObject }?.forEach { clazz ->
val name = clazz.get("name").asString

if (visitor.visitClass(name)) {
val javadoc = clazz.get("javadoc")?.asJsonArray?.joinToString("\n") { it.asString }
if (javadoc != null) {
visitor.visitComment(MappedElementKind.CLASS, javadoc)
}

if (visitor.visitElementContent(MappedElementKind.CLASS)) {

// methods
clazz.get("methods")?.asJsonArray?.map { it.asJsonObject }?.forEach { method ->
val mname = method.get("name").asString
val descriptor = method.get("descriptor").asString

if (visitor.visitMethod(mname, descriptor)) {
val mjavadoc = method.get("javadoc")?.asJsonArray?.joinToString("\n") { it.asString }
if (mjavadoc != null) {
visitor.visitComment(MappedElementKind.METHOD, mjavadoc)
}

if (visitor.visitElementContent(MappedElementKind.METHOD)) {
method.get("parameters")?.asJsonArray?.map { it.asJsonObject }?.forEach { param ->
val index = param.get("index").asInt
val pname = param.get("name").asString

visitor.visitMethodArg(-1, index, null)
visitor.visitDstName(MappedElementKind.METHOD_ARG, 0, pname)
}
}
}

}

// fields
clazz.get("fields")?.asJsonArray?.map { it.asJsonObject }?.forEach { field ->
val fname = field.get("name").asString
val descriptor = field.get("descriptor").asString

if (visitor.visitField(fname, descriptor)) {
val fjavadoc = field.get("javadoc")?.asJsonArray?.joinToString("\n") { it.asString }
if (fjavadoc != null) {
visitor.visitComment(MappedElementKind.FIELD, fjavadoc)
}
}
}
}

}
}
}

visitor.visitEnd()
}
}
47 changes: 24 additions & 23 deletions src/mappings/kotlin/net/fabricmc/mappingio/format/ZipReader.kt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,16 @@ object ZipReader {
)
}
}

MappingType.PARCHMENT -> {
readInputStreamFor(entry, zip) {
ParchmentReader.read(
InputStreamReader(it),
"named",
mappingTree
)
}
}
}
break
}
Expand Down Expand Up @@ -332,6 +342,7 @@ object ZipReader {

enum class MappingType(val pattern: Regex) {
TINY(Regex("""(.+[/\\]|^)mappings.tiny$""")),
PARCHMENT(Regex("""(.+[/\\]|^)parchment.json$""")),
SRG_CLIENT(Regex("""(.+[/\\]|^)client.srg$""")),
SRG_SERVER(Regex("""(.+[/\\]|^)server.srg$""")),
SRG_MERGED(Regex("""(.+[/\\]|^)joined.srg$""")),
Expand All @@ -343,6 +354,13 @@ object ZipReader {
MCP_PARAMS(Regex("""(.+[/\\]|^)params.csv$""")),
MCP_FIELDS(Regex("""(.+[/\\]|^)fields.csv$""")),
MCP_PACKAGES(Regex("""(.+[/\\]|^)packages.csv$""")),
;

companion object {
fun allBut(set: Set<MappingType>): Set<MappingType> {
return values().toSet() - set
}
}
}

enum class MCPConfigVersion(
Expand All @@ -352,32 +370,15 @@ object ZipReader {
) {
TINY_JAR(
setOf(MappingType.TINY),
setOf(
MappingType.SRG_CLIENT,
MappingType.SRG_SERVER,
MappingType.SRG_MERGED,
MappingType.TSRG,
MappingType.RGS_CLIENT,
MappingType.RGS_SERVER,
MappingType.MCP_METHODS,
MappingType.MCP_PARAMS,
MappingType.MCP_FIELDS,
MappingType.MCP_CLASSES
)
MappingType.allBut(setOf(MappingType.TINY))
),
PARCHMENT_ZIP(
setOf(MappingType.PARCHMENT),
MappingType.allBut(setOf(MappingType.PARCHMENT))
),
NEW_MCPCONFIG(
setOf(MappingType.TSRG),
setOf(
MappingType.MCP_FIELDS,
MappingType.MCP_METHODS,
MappingType.MCP_PARAMS,
MappingType.MCP_CLASSES,
MappingType.RGS_SERVER,
MappingType.RGS_CLIENT,
MappingType.SRG_SERVER,
MappingType.SRG_CLIENT,
MappingType.SRG_MERGED
)
MappingType.allBut(setOf(MappingType.TSRG))
),
MCPCONFIG(
setOf(MappingType.SRG_MERGED),
Expand Down

0 comments on commit 901382f

Please sign in to comment.