Skip to content

Commit

Permalink
RFG Compat patches
Browse files Browse the repository at this point in the history
  • Loading branch information
eigenraven committed Mar 29, 2023
1 parent dae0cec commit 32de983
Show file tree
Hide file tree
Showing 16 changed files with 288 additions and 35 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[*.{kt,kts}]
max_line_length=120
indent_size = 4
ij_kotlin_imports_layout=*
5 changes: 1 addition & 4 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Setup publish token
env:
JETBRAINS_TOKEN: ${{ secrets.JETBRAINS_TOKEN }}
shell: bash
run: |
mkdir -p ~/.gradle/
echo "GRADLE_USER_HOME=$HOME/.gradle" >> "$GITHUB_ENV"
echo "mcdev.deploy.token=${JETBRAINS_TOKEN}" > ~/.gradle/gradle.properties
- name: Publish plugin
run: ./gradlew clean publishPlugin --no-daemon --stacktrace
run: ./gradlew clean assemble buildPlugin --no-daemon --stacktrace
- name: Get tag name
id: get_tag
shell: bash
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ kotlin.code.style=official
ideaVersion = 2023.1
ideaVersionName = 2023.1

coreVersion = 1.6.3
downloadIdeaSources = true
coreVersion = 1.6.5
downloadIdeaSources = false

pluginTomlVersion = 231.8109.1

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2023 minecraft-dev
*
* MIT License
*/

package com.demonwav.mcdev.platform.mcp.gradle.tooling

import org.gradle.api.Project
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder
import org.jetbrains.plugins.gradle.tooling.ModelBuilderService

final class McpModelRFGBuilderImpl implements ModelBuilderService {

@Override
boolean canBuild(String modelName) {
return McpModelRFG.name == modelName
}

@Override
Object buildAll(String modelName, Project project) {
System.err.println("Attempting build of " + modelName + " in " + project)
def extension = project.extensions.findByName('minecraft')
if (extension == null) {
return null
}

def mcpTasksObj = project.extensions.findByName('mcpTasks')
if (mcpTasksObj == null) {
return null
}

if (project.tasks.findByName("generateForgeSrgMappings") == null) {
return null
}

def mappingFiles = project.tasks.generateForgeSrgMappings.outputs.files.files.collect { it.absolutePath }
def atFiles = mcpTasksObj.deobfuscationATs.files.collect {it}
System.err.println("Done build of " + modelName + " in " + project)
try {
def implObj = new McpModelRFGImpl(extension.mcVersion.get(), extension.mcpMappingChannel.get() + "-" + extension.mcpMappingVersion.get(), mappingFiles.toSet(), atFiles)
System.err.println("Impl: " + implObj)
return implObj
} catch (Throwable t) {
System.err.println(t.message)
t.printStackTrace()
throw t
}
}

@Override
ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) {
return ErrorMessageBuilder.create(
project, e, "MinecraftDev import errors"
).withDescription("Unable to build MinecraftDev MCP project configuration")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2023 minecraft-dev
*
* MIT License
*/

package com.demonwav.mcdev.platform.mcp.gradle.tooling

import groovy.transform.CompileStatic

@CompileStatic
final class McpModelRFGImpl implements McpModelRFG, Serializable {

final String minecraftVersion
final String mcpVersion
final Set<String> mappingFiles
final List<File> accessTransformers

McpModelRFGImpl(String minecraftVersion, String mcpVersion, Set<String> mappingFiles, List<File> accessTransformers) {
this.minecraftVersion = minecraftVersion
this.mcpVersion = mcpVersion
this.mappingFiles = mappingFiles
this.accessTransformers = accessTransformers
}

@Override
public String toString() {
return "McpModelRFGImpl{" +
"minecraftVersion='" + minecraftVersion + '\'' +
", mcpVersion='" + mcpVersion + '\'' +
", mappingFiles=" + mappingFiles +
", accessTransformers=" + accessTransformers +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2023 minecraft-dev
*
* MIT License
*/

package com.demonwav.mcdev.platform.mcp.gradle.tooling;

import java.io.File;
import java.util.List;
import java.util.Set;

public interface McpModelRFG extends McpModel {
String getMinecraftVersion();
Set<String> getMappingFiles();
List<File> getAccessTransformers();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ com.demonwav.mcdev.platform.mcp.gradle.tooling.fabricloom.FabricLoomModelBuilder
com.demonwav.mcdev.platform.mcp.gradle.tooling.vanillagradle.VanillaGradleModelBuilderImpl
com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelFG2BuilderImpl
com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelFG3BuilderImpl
com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelRFGBuilderImpl
10 changes: 10 additions & 0 deletions src/main/kotlin/facet/MinecraftFacetDetector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import com.demonwav.mcdev.platform.PlatformType
import com.demonwav.mcdev.platform.architectury.framework.ARCHITECTURY_LIBRARY_KIND
import com.demonwav.mcdev.platform.architectury.framework.ArchitecturyGradleData
import com.demonwav.mcdev.platform.fabric.framework.FABRIC_LIBRARY_KIND
import com.demonwav.mcdev.platform.forge.framework.FORGE_LIBRARY_KIND
import com.demonwav.mcdev.platform.mcp.framework.MCP_LIBRARY_KIND
import com.demonwav.mcdev.platform.mcp.gradle.tooling.archloom.ArchitecturyModel
import com.demonwav.mcdev.platform.sponge.framework.SPONGE_LIBRARY_KIND
import com.demonwav.mcdev.util.ifEmpty
Expand Down Expand Up @@ -176,6 +178,14 @@ class MinecraftFacetDetector : StartupActivity {

platformKinds.add(SPONGE_LIBRARY_KIND)
}
// RFG Patch: fix auto-detection of the Forge/MCP facets on RFG projects
if (m.name.endsWith(".patchedMc", ignoreCase = false)) {
// RetroFuturaGradle decompiled MC sources
platformKinds.add(FORGE_LIBRARY_KIND)
platformKinds.add(MCP_LIBRARY_KIND)
libraryVersions[FORGE_LIBRARY_KIND] = "1.0"
libraryVersions[MCP_LIBRARY_KIND] = "1.0"
}
return@forEach true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class UngrabMouseDebugSessionListener(private val process: DebugProcessImpl) : X
val virtualMachine = debugProcess.virtualMachineProxy as? VirtualMachineProxyImpl ?: return
val evaluationContext = EvaluationContextImpl(suspendContextImpl, frameProxy)

// RFG Patch: Fix mouse ungrabbing with lwjgl3ify
val mouseClass = virtualMachine.classesByName("org.lwjgl.input.Mouse")?.singleOrNull() as? ClassType
?: virtualMachine.classesByName("org.lwjglx.input.Mouse")?.singleOrNull() as? ClassType
// LWJGL 3 does not have the Mouse class, Minecraft uses its own MouseHelper instead
if (mouseClass != null) {
ungrab2(mouseClass, virtualMachine, debugProcess, evaluationContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ package com.demonwav.mcdev.platform.mcp.gradle

import com.demonwav.mcdev.platform.mcp.gradle.datahandler.McpModelFG2Handler
import com.demonwav.mcdev.platform.mcp.gradle.datahandler.McpModelFG3Handler
import com.demonwav.mcdev.platform.mcp.gradle.datahandler.McpModelRFGHandler
import com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelFG2
import com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelFG3
import com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelRFG
import com.demonwav.mcdev.util.runGradleTask
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.ModuleData
Expand All @@ -26,7 +28,7 @@ class McpProjectResolverExtension : AbstractProjectResolverExtension() {

// Register our custom Gradle tooling API model in IntelliJ's project resolver
override fun getExtraProjectModelClasses(): Set<Class<out Any>> =
setOf(McpModelFG2::class.java, McpModelFG3::class.java)
setOf(McpModelFG2::class.java, McpModelFG3::class.java, McpModelRFG::class.java)

override fun getToolingExtensionsClasses() = extraProjectModelClasses

Expand Down Expand Up @@ -79,6 +81,6 @@ class McpProjectResolverExtension : AbstractProjectResolverExtension() {
}

companion object {
private val handlers = listOf(McpModelFG2Handler, McpModelFG3Handler)
private val handlers = listOf(McpModelFG2Handler, McpModelFG3Handler, McpModelRFGHandler)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Minecraft Dev for IntelliJ
*
* https://minecraftdev.org
*
* Copyright (c) 2023 minecraft-dev
*
* MIT License
*/

package com.demonwav.mcdev.platform.mcp.gradle.datahandler

import com.demonwav.mcdev.platform.mcp.McpModuleSettings
import com.demonwav.mcdev.platform.mcp.gradle.McpModelData
import com.demonwav.mcdev.platform.mcp.gradle.tooling.McpModelRFG
import com.demonwav.mcdev.platform.mcp.srg.SrgType
import com.intellij.openapi.externalSystem.model.DataNode
import com.intellij.openapi.externalSystem.model.project.ModuleData
import org.gradle.tooling.model.idea.IdeaModule
import org.jetbrains.plugins.gradle.model.data.GradleSourceSetData
import org.jetbrains.plugins.gradle.service.project.ProjectResolverContext

object McpModelRFGHandler : McpModelDataHandler {

override fun build(
gradleModule: IdeaModule,
node: DataNode<ModuleData>,
resolverCtx: ProjectResolverContext
) {
val data = resolverCtx.getExtraProject(gradleModule, McpModelRFG::class.java) ?: return

val state = McpModuleSettings.State(
data.minecraftVersion,
data.mcpVersion,
data.mappingFiles.find { it.endsWith("mcp-srg.srg") },
SrgType.SRG,
data.minecraftVersion
)

val modelData = McpModelData(
node.data,
state,
"generateForgeSrgMappings",
data.accessTransformers
)

node.createChild(
McpModelData.KEY,
McpModelData(
node.data,
McpModuleSettings.State(
data.minecraftVersion,
data.mcpVersion,
data.mappingFiles.find { it.endsWith("mcp-srg.srg") },
SrgType.SRG
),
"generateForgeSrgMappings",
data.accessTransformers
)
)

for (child in node.children) {
val childData = child.data
if (childData is GradleSourceSetData) {
child.createChild(McpModelData.KEY, modelData.copy(module = childData))
}
}
}
}
19 changes: 17 additions & 2 deletions src/main/kotlin/platform/mixin/util/AsmUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import com.intellij.ide.highlighter.JavaFileType
import com.intellij.openapi.module.Module
import com.intellij.openapi.progress.ProcessCanceledException
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessModuleDir
import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.util.RecursionManager
import com.intellij.psi.JavaPsiFacade
Expand Down Expand Up @@ -168,7 +169,18 @@ fun findClassNodeByPsiClass(psiClass: PsiClass, module: Module? = psiClass.findM
// find compiler output
if (module == null) return null
val fqn = psiClass.fullQualifiedName ?: return null
var parentDir = CompilerModuleExtension.getInstance(module)?.compilerOutputPath ?: return null
// RFG Patch: navigate to Minecraft sources if it's a source module and not a library
val cme = CompilerModuleExtension.getInstance(module) ?: return null
var parentDir = if (module.name.endsWith("patchedMc")) {
// Guess module dir -> MOD/build/rfg/minecraft-src/java
module.guessModuleDir()
?.parent?.parent?.parent
?.findFileByRelativePath("classes")
?.findFileByRelativePath("java")
?.findFileByRelativePath("patchedMc") ?: return null
} else {
cme.compilerOutputPath ?: return null
}
val packageName = fqn.substringBeforeLast('.', "")
if (packageName.isNotEmpty()) {
for (dir in packageName.split('.')) {
Expand Down Expand Up @@ -335,7 +347,10 @@ fun ClassNode.findSourceClass(project: Project, scope: GlobalSearchScope, canDec
val stubFile = stubClass.containingFile ?: return@findQualifiedClass null
val classFile = stubFile.virtualFile
if (classFile != null) {
val sourceFile = JavaEditorFileSwapper.findSourceFile(project, classFile)
// RFG patch: Minecraft is a SourceSet and not a library
val sourceFile = if (classFile.extension == "java")
classFile else
JavaEditorFileSwapper.findSourceFile(project, classFile)
if (sourceFile != null) {
val sourceClass = (PsiManager.getInstance(project).findFile(sourceFile) as? PsiJavaFile)
?.classes?.firstOrNull()
Expand Down
26 changes: 22 additions & 4 deletions src/main/kotlin/util/ModuleDebugRunConfigurationExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package com.demonwav.mcdev.util

import com.demonwav.mcdev.facet.MinecraftFacet
import com.demonwav.mcdev.platform.mcp.McpModuleType
import com.intellij.execution.RunConfigurationExtension
import com.intellij.execution.configurations.DebuggingRunnerData
import com.intellij.execution.configurations.JavaParameters
Expand All @@ -19,12 +21,15 @@ import com.intellij.execution.configurations.RunnerSettings
import com.intellij.execution.process.ProcessHandler
import com.intellij.openapi.module.Module
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.modules
import org.jdom.Element
import org.jetbrains.plugins.gradle.service.execution.GradleRunConfiguration

// RFG Patches: Support gradle run configurations in RFG projects, not just IJ native ones
abstract class ModuleDebugRunConfigurationExtension : RunConfigurationExtension() {

override fun isApplicableFor(configuration: RunConfigurationBase<*>): Boolean {
return configuration is ModuleBasedConfiguration<*, *>
return configuration is ModuleBasedConfiguration<*, *> || configuration is GradleRunConfiguration
}

override fun <T : RunConfigurationBase<*>> updateJavaParameters(
Expand All @@ -46,9 +51,22 @@ abstract class ModuleDebugRunConfigurationExtension : RunConfigurationExtension(
return
}

val config = configuration as ModuleBasedConfiguration<*, *>
val module = config.configurationModule.module ?: return
attachToProcess(handler, module)
when (configuration) {
is ModuleBasedConfiguration<*, *> -> {
val module = configuration.configurationModule.module ?: return
attachToProcess(handler, module)
}

is GradleRunConfiguration -> {
if (configuration.project.modules.isEmpty()) {
return
}
val module = configuration.project.modules.find { module ->
MinecraftFacet.getInstance(module)?.isOfType(McpModuleType) == true
} ?: return
attachToProcess(handler, module)
}
}
}

override fun readExternal(runConfiguration: RunConfigurationBase<*>, element: Element) {}
Expand Down
Loading

0 comments on commit 32de983

Please sign in to comment.