@@ -56,6 +56,10 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
5656 override val namedToMojangManager: MappingsManager ?
5757 get() = namedToMojangManagerField
5858
59+ private var mappingNamespacesField = emptyList<String >()
60+ val mappingNamespaces: List <String >
61+ get() = mappingNamespacesField
62+
5963 override val moduleType = FabricModuleType
6064 override val type = PlatformType .FABRIC
6165 override val icon = PlatformAssets .FABRIC_ICON
@@ -79,60 +83,74 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
7983 }
8084
8185 override fun refresh () {
82- namedToMojangManagerField = if (detectYarn()) {
86+ val mappingDetection = detectMappings()
87+
88+ namedToMojangManagerField = if (mappingDetection.yarnDetected) {
8389 MappingsManager .Immediate (HardcodedYarnToMojmap .createMappings())
8490 } else {
8591 null
8692 }
93+
94+ mappingNamespacesField = mappingDetection.namespaces
8795 }
8896
89- private fun detectYarn (): Boolean {
90- val gradleData = GradleUtil .findGradleModuleData(facet.module) ? : return false
91- val loomData =
92- gradleData.children.find { it.key == FabricLoomData . KEY }?.data as ? FabricLoomData ? : return false
93- val mappingsFile = loomData.tinyMappings ? : return false
97+ private fun detectMappings (): MappingDetectionResult {
98+ val gradleData = GradleUtil .findGradleModuleData(facet.module) ? : return MappingDetectionResult . DEFAULT
99+ val loomData = gradleData.children.find { it.key == FabricLoomData . KEY }?.data as ? FabricLoomData
100+ ? : return MappingDetectionResult . DEFAULT
101+ val mappingsFile = loomData.tinyMappings ? : return MappingDetectionResult . DEFAULT
94102
95- var yarnDetected = false
96- val visitor = object : MappingVisitor {
97- private var namedIndex = - 1
103+ val result = MappingDetectionResult ()
98104
99- override fun visitNamespaces (srcNamespace : String? , dstNamespaces : List <String >) {
100- namedIndex = dstNamespaces.indexOf(" named" )
101- }
105+ try {
106+ MappingReader .read(mappingsFile.toPath(), result)
107+ } catch (_: IOException ) {
108+ return MappingDetectionResult .DEFAULT
109+ }
102110
103- override fun visitContent () = namedIndex >= 0
111+ return result
112+ }
104113
105- override fun visitClass (srcName : String ) = true
114+ override fun dispose () {
115+ super .dispose()
116+ fabricJson = null
117+ }
106118
107- override fun visitField (srcName : String? , srcDesc : String? ) = false
119+ private class MappingDetectionResult : MappingVisitor {
120+ var yarnDetected = false
121+ var namespaces = emptyList<String >()
122+ private var namedIndex = - 1
108123
109- override fun visitMethod (srcName : String? , srcDesc : String? ) = false
124+ override fun visitNamespaces (srcNamespace : String? , dstNamespaces : List <String >) {
125+ namedIndex = dstNamespaces.indexOf(" named" )
126+ namespaces = listOfNotNull(srcNamespace) + dstNamespaces
127+ }
110128
111- override fun visitMethodArg ( argPosition : Int , lvIndex : Int , srcName : String? ) = false
129+ override fun visitContent () = namedIndex >= 0
112130
113- override fun visitMethodVar ( lvtRowIndex : Int , lvIndex : Int , startOpIdx : Int , srcName : String? ) = false
131+ override fun visitClass ( srcName : String ) = true
114132
115- override fun visitDstName (targetKind : MappedElementKind ? , namespace : Int , name : String ) {
116- if (namespace == namedIndex && name == " net/minecraft/client/MinecraftClient" ) {
117- yarnDetected = true
118- }
119- }
133+ override fun visitField (srcName : String? , srcDesc : String? ) = false
134+
135+ override fun visitMethod (srcName : String? , srcDesc : String? ) = false
136+
137+ override fun visitMethodArg (argPosition : Int , lvIndex : Int , srcName : String? ) = false
138+
139+ override fun visitMethodVar (lvtRowIndex : Int , lvIndex : Int , startOpIdx : Int , srcName : String? ) = false
120140
121- override fun visitComment (targetKind : MappedElementKind ? , comment : String? ) {
141+ override fun visitDstName (targetKind : MappedElementKind ? , namespace : Int , name : String ) {
142+ if (namespace == namedIndex && name == " net/minecraft/client/MinecraftClient" ) {
143+ yarnDetected = true
122144 }
123145 }
124146
125- try {
126- MappingReader .read(mappingsFile.toPath(), visitor)
127- } catch (e: IOException ) {
128- return false
147+ override fun visitComment (targetKind : MappedElementKind ? , comment : String? ) {
129148 }
130149
131- return yarnDetected
132- }
133-
134- override fun dispose () {
135- super .dispose()
136- fabricJson = null
150+ companion object {
151+ val DEFAULT = MappingDetectionResult ().apply {
152+ namespaces = listOf (" official" )
153+ }
154+ }
137155 }
138156}
0 commit comments