Skip to content

Commit

Permalink
Merge branch '2022.3' into 2023.1
Browse files Browse the repository at this point in the history
  • Loading branch information
DenWav committed Nov 17, 2023
2 parents b29af86 + 117cc58 commit cfbaebd
Show file tree
Hide file tree
Showing 45 changed files with 460 additions and 228 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import org.jlleitschuh.gradle.ktlint.tasks.BaseKtLintCheckTask
import org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask

plugins {
kotlin("jvm") version "1.9.0"
kotlin("jvm") version "1.9.20"
java
mcdev
groovy
idea
id("org.jetbrains.intellij") version "1.15.0"
id("org.jetbrains.intellij") version "1.16.0"
id("org.cadixdev.licenser")
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ kotlin.code.style=official
ideaVersion = 2023.1
ideaVersionName = 2023.1

coreVersion = 1.6.10
coreVersion = 1.6.11
downloadIdeaSources = true

pluginTomlVersion = 231.8109.1
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
17 changes: 9 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -144,15 +145,15 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -201,11 +202,11 @@ fi
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Minecraft Development for IntelliJ
</tr>
</table>

Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.10-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
Info and Documentation [![Current Release](https://img.shields.io/badge/release-1.6.11-orange.svg?style=flat-square)](https://plugins.jetbrains.com/plugin/8327)
----------------------

<a href="https://discord.gg/j6UNcfr"><img src="https://i.imgur.com/JXu9C1G.png" height="48px"></img></a>
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/creator/PlatformVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.demonwav.mcdev.update.PluginUtil
import com.demonwav.mcdev.util.fromJson
import com.demonwav.mcdev.util.mapFirstNotNull
import com.demonwav.mcdev.util.withSuppressed
import com.github.kittinunf.fuel.core.FuelError
import com.github.kittinunf.fuel.core.FuelManager
import com.github.kittinunf.fuel.core.requests.suspendable
import com.github.kittinunf.fuel.coroutines.awaitString
Expand Down Expand Up @@ -77,11 +76,11 @@ suspend fun <T : Any> getVersionJson(path: String, type: KClass<T>): T {
}

suspend fun getText(path: String): String {
var thrown: FuelError? = null
var thrown: Exception? = null
return URLS.mapFirstNotNull { url ->
try {
doCall(url + path)
} catch (e: FuelError) {
} catch (e: Exception) {
PLATFORM_VERSION_LOGGER.warn("Failed to reach URL $url$path")
thrown = withSuppressed(thrown, e)
null
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/facet/MinecraftFacet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class MinecraftFacet(
}

newlyEnabled.forEach(AbstractModule::init)
modules.forEach(AbstractModule::refresh)

ProjectView.getInstance(module.project).refresh()
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/insight/ColorUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,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
1 change: 1 addition & 0 deletions src/main/kotlin/platform/AbstractModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ abstract class AbstractModule(protected val facet: MinecraftFacet) {

open fun init() {}
open fun dispose() {}
open fun refresh() {}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import com.demonwav.mcdev.util.extendsOrImplements
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.util.createSmartPointer
import com.siyeh.ig.BaseInspection
import com.siyeh.ig.BaseInspectionVisitor
import com.siyeh.ig.InspectionGadgetsFix
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer

class BukkitListenerImplementedInspection : BaseInspection() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import com.demonwav.mcdev.util.extendsOrImplements
import com.intellij.codeInspection.ProblemDescriptor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiClass
import com.intellij.psi.util.createSmartPointer
import com.siyeh.ig.BaseInspection
import com.siyeh.ig.BaseInspectionVisitor
import com.siyeh.ig.InspectionGadgetsFix
import org.jetbrains.annotations.Nls
import org.jetbrains.kotlin.psi.psiUtil.createSmartPointer

class BungeeCordListenerImplementedInspection : BaseInspection() {

Expand Down
68 changes: 67 additions & 1 deletion src/main/kotlin/platform/fabric/FabricModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,36 @@ import com.demonwav.mcdev.platform.AbstractModule
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.fabric.reference.EntryPointReference
import com.demonwav.mcdev.platform.fabric.util.FabricConstants
import com.demonwav.mcdev.platform.mcp.fabricloom.FabricLoomData
import com.demonwav.mcdev.platform.mcp.mappings.HardcodedYarnToMojmap
import com.demonwav.mcdev.platform.mcp.mappings.HasCustomNamedMappings
import com.demonwav.mcdev.platform.mcp.mappings.MappingsManager
import com.demonwav.mcdev.util.SourceType
import com.demonwav.mcdev.util.nullable
import com.demonwav.mcdev.util.runCatchingKtIdeaExceptions
import com.intellij.psi.PsiClass
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiMethod
import com.intellij.psi.search.searches.ReferencesSearch
import java.io.IOException
import net.fabricmc.mappingio.MappedElementKind
import net.fabricmc.mappingio.MappingReader
import net.fabricmc.mappingio.MappingVisitor
import org.jetbrains.plugins.gradle.util.GradleUtil
import org.jetbrains.uast.UClass
import org.jetbrains.uast.UIdentifier
import org.jetbrains.uast.UMethod
import org.jetbrains.uast.toUElementOfType

class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(facet) {
class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(facet), HasCustomNamedMappings {

var fabricJson by nullable { facet.findFile(FabricConstants.FABRIC_MOD_JSON, SourceType.RESOURCE) }
private set

private var namedToMojangManagerField: MappingsManager? = null
override val namedToMojangManager: MappingsManager?
get() = namedToMojangManagerField

override val moduleType = FabricModuleType
override val type = PlatformType.FABRIC
override val icon = PlatformAssets.FABRIC_ICON
Expand All @@ -65,6 +78,59 @@ class FabricModule internal constructor(facet: MinecraftFacet) : AbstractModule(
return ReferencesSearch.search(psiParent).anyMatch { EntryPointReference.isEntryPointReference(it) }
}

override fun refresh() {
namedToMojangManagerField = if (detectYarn()) {
MappingsManager.Immediate(HardcodedYarnToMojmap.createMappings())
} else {
null
}
}

private fun detectYarn(): Boolean {
val gradleData = GradleUtil.findGradleModuleData(facet.module) ?: return false
val loomData =
gradleData.children.find { it.key == FabricLoomData.KEY }?.data as? FabricLoomData ?: return false
val mappingsFile = loomData.tinyMappings ?: return false

var yarnDetected = false
val visitor = object : MappingVisitor {
private var namedIndex = -1

override fun visitNamespaces(srcNamespace: String?, dstNamespaces: List<String>) {
namedIndex = dstNamespaces.indexOf("named")
}

override fun visitContent() = namedIndex >= 0

override fun visitClass(srcName: String) = true

override fun visitField(srcName: String?, srcDesc: String?) = false

override fun visitMethod(srcName: String?, srcDesc: String?) = false

override fun visitMethodArg(argPosition: Int, lvIndex: Int, srcName: String?) = false

override fun visitMethodVar(lvtRowIndex: Int, lvIndex: Int, startOpIdx: Int, srcName: String?) = false

override fun visitDstName(targetKind: MappedElementKind?, namespace: Int, name: String) {
if (namespace == namedIndex && name == "net/minecraft/client/MinecraftClient") {
yarnDetected = true
}
}

override fun visitComment(targetKind: MappedElementKind?, comment: String?) {
}
}

try {
MappingReader.read(mappingsFile.toPath(), visitor)
} catch (e: IOException) {
return false
}

return yarnDetected
}

override fun dispose() {
super.dispose()
fabricJson = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ object ReflectedFieldReference : PsiReferenceProvider() {
?: return@withInsertHandler

val srgManager = literal.findModule()?.let { MinecraftFacet.getInstance(it) }
?.getModuleOfType(McpModuleType)?.srgManager
val srgMap = srgManager?.srgMapNow
val srgField = srgMap?.getSrgField(field.simpleQualifiedMemberReference)
?.getModuleOfType(McpModuleType)?.mappingsManager
val srgMap = srgManager?.mappingsNow
val srgField = srgMap?.getIntermediaryField(field.simpleQualifiedMemberReference)
?: return@withInsertHandler

context.setLaterRunnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ abstract class ReflectedMemberReferenceBasePoly(element: PsiLiteral) : PsiRefere

val name = memberName
val srgManager = element.findModule()?.let { MinecraftFacet.getInstance(it) }
?.getModuleOfType(McpModuleType)?.srgManager
val srgMap = srgManager?.srgMapNow
val mcpName = srgMap?.mapMcpToSrgName(name) ?: name
?.getModuleOfType(McpModuleType)?.mappingsManager
val srgMap = srgManager?.mappingsNow
val mcpName = srgMap?.mapIntermediaryToMapped(name) ?: name

return typeClass.allFields.asSequence()
.filter { it.name == mcpName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ object ReflectedMethodReference : PsiReferenceProvider() {
?: return@withInsertHandler
val params = literal.parent as? PsiExpressionList ?: return@withInsertHandler
val srgManager = literal.findModule()?.let { MinecraftFacet.getInstance(it) }
?.getModuleOfType(McpModuleType)?.srgManager
val srgMap = srgManager?.srgMapNow
?.getModuleOfType(McpModuleType)?.mappingsManager
val srgMap = srgManager?.mappingsNow

val signature = method.getSignature(PsiSubstitutor.EMPTY)
val returnType = method.returnType?.let { TypeConversionUtil.erasure(it).canonicalText }
Expand All @@ -84,7 +84,7 @@ object ReflectedMethodReference : PsiReferenceProvider() {
.map { it.canonicalText }

val memberRef = method.qualifiedMemberReference
val srgMethod = srgMap?.getSrgMethod(memberRef) ?: memberRef
val srgMethod = srgMap?.getIntermediaryMethod(memberRef) ?: memberRef

context.setLaterRunnable {
// Commit changes made by code completion
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/platform/mcp/McpModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.demonwav.mcdev.platform.mcp
import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.platform.AbstractModule
import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.mcp.srg.SrgManager
import com.demonwav.mcdev.platform.mcp.mappings.MappingsManager
import com.demonwav.mcdev.platform.mcp.util.McpConstants
import com.demonwav.mcdev.translations.TranslationFileListener
import com.demonwav.mcdev.util.runWriteTaskLater
Expand All @@ -43,7 +43,7 @@ class McpModule(facet: MinecraftFacet) : AbstractModule(facet) {
private val settings: McpModuleSettings = McpModuleSettings.getInstance(module)
val accessTransformers = mutableSetOf<VirtualFile>()

var srgManager: SrgManager? = null
var mappingsManager: MappingsManager? = null
private set

override fun init() {
Expand All @@ -61,8 +61,8 @@ class McpModule(facet: MinecraftFacet) : AbstractModule(facet) {
val file = settings.mappingFile ?: return
val srgType = settings.srgType ?: return

srgManager = SrgManager.getInstance(file, srgType)
srgManager?.parse()
mappingsManager = MappingsManager.getInstance(file, srgType)
mappingsManager?.parse()
}

override val moduleType = McpModuleType
Expand All @@ -78,8 +78,8 @@ class McpModule(facet: MinecraftFacet) : AbstractModule(facet) {
val mappingFile = data.mappingFile ?: return
val srgType = data.srgType ?: return

srgManager = SrgManager.getInstance(mappingFile, srgType)
srgManager?.parse()
mappingsManager = MappingsManager.getInstance(mappingFile, srgType)
mappingsManager?.parse()
}

fun addAccessTransformerFile(file: VirtualFile) {
Expand All @@ -91,6 +91,6 @@ class McpModule(facet: MinecraftFacet) : AbstractModule(facet) {

connection.disconnect()
accessTransformers.clear()
srgManager = null
mappingsManager = null
}
}
Loading

0 comments on commit cfbaebd

Please sign in to comment.