Skip to content

Commit

Permalink
MCP package reader
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Jul 25, 2024
1 parent 24fdb57 commit 61a86eb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ object FormatRegistry {
FormatProvider(MCPv3ClassesReader),
FormatProvider(MCPv3MethodReader, mustBeAfter = listOf(MCPv3ClassesReader)),
FormatProvider(MCPv3FieldReader, mustBeAfter = listOf(MCPv3ClassesReader)),
FormatProvider(MCPv6PackageReader, mustBeAfter = listOf(SrgReader)),
FormatProvider(MCPExceptionReader, mustBeAfter = listOf(RetroguardReader, MCPv3ClassesReader, SrgReader, TsrgV1Reader, TsrgV2Reader)),
FormatProvider(MCPv6MethodReader, MCPv6MethodWriter, mustBeAfter = listOf(SrgReader, TsrgV1Reader, TsrgV2Reader)),
FormatProvider(MCPv6FieldReader, MCPv6FieldWriter, mustBeAfter = listOf(SrgReader, TsrgV1Reader, TsrgV2Reader)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package xyz.wagyourtail.unimined.mapping.formats.mcp.v6

import okio.BufferedSource
import xyz.wagyourtail.unimined.mapping.EnvType
import xyz.wagyourtail.unimined.mapping.Namespace
import xyz.wagyourtail.unimined.mapping.formats.FormatReader
import xyz.wagyourtail.unimined.mapping.jvms.four.two.one.InternalName
import xyz.wagyourtail.unimined.mapping.tree.AbstractMappingTree
import xyz.wagyourtail.unimined.mapping.util.CharReader
import xyz.wagyourtail.unimined.mapping.visitor.MappingVisitor
import xyz.wagyourtail.unimined.mapping.visitor.use

object MCPv6PackageReader : FormatReader {
override fun isFormat(fileName: String, input: BufferedSource, envType: EnvType): Boolean {
if (fileName.substringAfterLast('/') != "packages.csv") return false
return input.peek().readUtf8Line()?.startsWith("class,package") ?: false
}

override suspend fun read(
input: CharReader,
context: AbstractMappingTree?,
into: MappingVisitor,
envType: EnvType,
nsMapping: Map<String, String>
) {
val srcNs = Namespace(nsMapping["source"] ?: "source")
val dstNs = Namespace(nsMapping["target"] ?: "target")

val header = input.takeLine()
if (!header.startsWith("class,package")) {
throw IllegalArgumentException("invalid header: $header")
}

into.use {
visitHeader(srcNs.name, dstNs.name)

while (!input.exhausted()) {
if (input.peek() == '\n') {
input.take()
continue
}
val cls = input.takeCol().second
val pkg = input.takeCol().second

into.visitClass(mapOf(
srcNs to InternalName.read("net/minecraft/src/$cls"),
dstNs to InternalName.read("$pkg/$cls")
))?.visitEnd()
}
}
}
}

0 comments on commit 61a86eb

Please sign in to comment.