Skip to content

Commit

Permalink
More yarn mappings stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer committed Sep 27, 2023
1 parent 2cc2f48 commit 51143cc
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/insight/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private fun <T> findColorFromExpression(
val facet = MinecraftFacet.getInstance(module) ?: return null
val resolvedName = expression.resolvedName ?: return null
for (abstractModuleType in facet.types) {
val map = abstractModuleType.classToColorMappings
val map = abstractModuleType.classToColorMappings(module)
for (entry in map.entries) {
// This is such a hack
// Okay, type will be the fully-qualified class, but it will exclude the actual enum
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/platform/AbstractModuleType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.demonwav.mcdev.insight.generation.ui.EventGenerationPanel
import com.demonwav.mcdev.util.findContainingClass
import com.intellij.codeInspection.ex.EntryPointsManager
import com.intellij.codeInspection.ex.EntryPointsManagerBase
import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
Expand All @@ -51,8 +52,7 @@ abstract class AbstractModuleType<out T : AbstractModule>(val groupId: String, v

abstract val listenerAnnotations: List<String>

val classToColorMappings: Map<String, Color>
get() = this.colorMap
open fun classToColorMappings(module: Module): Map<String, Color> = this.colorMap

abstract fun generateModule(facet: MinecraftFacet): T

Expand Down
17 changes: 13 additions & 4 deletions src/main/kotlin/platform/mcp/McpModuleType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ package com.demonwav.mcdev.platform.mcp
import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.platform.AbstractModuleType
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.mcp.mappings.getMappedClass
import com.demonwav.mcdev.platform.mcp.mappings.getMappedField
import com.demonwav.mcdev.platform.mcp.util.McpConstants
import com.demonwav.mcdev.util.CommonColors
import com.demonwav.mcdev.util.SemanticVersion
import com.intellij.openapi.module.Module
import java.awt.Color
import javax.swing.Icon

object McpModuleType : AbstractModuleType<McpModule>("", "") {

private const val ID = "MCP_MODULE_TYPE"

init {
CommonColors.applyStandardColors(colorMap, McpConstants.TEXT_FORMATTING)
CommonColors.applyStandardColors(colorMap, McpConstants.CHAT_FORMATTING)
}

override fun classToColorMappings(module: Module): Map<String, Color> {
return colorMap.mapKeys { key ->
val parts = key.key.split('.')
val className = parts.dropLast(1).joinToString(".")
val fieldName = parts.last()
"${module.getMappedClass(className)}.${module.getMappedField(className, fieldName)}"
}
}

override val platformType = PlatformType.MCP
override val icon: Icon? = null
override val id = ID
Expand All @@ -45,6 +56,4 @@ object McpModuleType : AbstractModuleType<McpModule>("", "") {
override val hasIcon = false

override fun generateModule(facet: MinecraftFacet) = McpModule(facet)

val MC_1_12_2 = SemanticVersion.release(1, 12, 2)
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import com.google.common.collect.ImmutableBiMap
object HardcodedYarnToMojmap {
fun createMappings() = Mappings(
ImmutableBiMap.ofEntries(
"net.minecraft.item.ItemStack" mapTo "net.minecraft.world.item.ItemStack"
"net.minecraft.item.ItemStack" mapTo "net.minecraft.world.item.ItemStack",
"net.minecraft.util.Formatting" mapTo "net.minecraft.ChatFormatting",
),
ImmutableBiMap.ofEntries(),
ImmutableBiMap.ofEntries(),
Expand Down
7 changes: 0 additions & 7 deletions src/main/kotlin/platform/mcp/util/McpConstants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ package com.demonwav.mcdev.platform.mcp.util

object McpConstants {

const val TEXT_FORMATTING = "net.minecraft.util.text.TextFormatting"
const val CHAT_FORMATTING = "net.minecraft.ChatFormatting"
const val ENTITY = "net.minecraft.entity.Entity"
const val ENTITY_FX = "net.minecraft.client.particle.EntityFX"
const val WORLD = "net.minecraft.world.World"
const val ITEM_STACK = "net.minecraft.item.ItemStack"
const val BLOCK = "net.minecraft.block.Block"
const val ITEM = "net.minecraft.item.Item"
const val MINECRAFT_SERVER = "net.minecraft.server.MinecraftServer"
const val PNG_MCMETA = "*.png.mcmeta"
}

0 comments on commit 51143cc

Please sign in to comment.