-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24fdb57
commit 61a86eb
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/commonMain/kotlin/xyz/wagyourtail/unimined/mapping/formats/mcp/v6/MCPv6PackageReader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} | ||
} | ||
} |