From fbbb2a2162bdf2a56241a81d8b2b317c11063232 Mon Sep 17 00:00:00 2001 From: RedNesto Date: Sun, 7 Jul 2024 17:52:45 +0200 Subject: [PATCH] Provide Minecraft version in Loom-based projects --- .../FabricLoomModelBuilderImpl.groovy | 3 ++- .../fabricloom/FabricLoomModelImpl.groovy | 1 + .../tooling/fabricloom/FabricLoomModel.java | 2 ++ .../FabricLoomProjectResolverExtension.kt | 20 +++++++++++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelBuilderImpl.groovy b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelBuilderImpl.groovy index 9cfd8f225..c751e8998 100644 --- a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelBuilderImpl.groovy +++ b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelBuilderImpl.groovy @@ -50,6 +50,7 @@ class FabricLoomModelBuilderImpl implements ModelBuilderService { } FabricLoomModel build(Project project, Object loomExtension) { + def minecraftVersion = loomExtension.minecraftProvider.minecraftVersion() def tinyMappings = loomExtension.mappingsFile def splitMinecraftJar = loomExtension.areEnvironmentSourceSetsSplit() @@ -70,7 +71,7 @@ class FabricLoomModelBuilderImpl implements ModelBuilderService { } //noinspection GroovyAssignabilityCheck - return new FabricLoomModelImpl(tinyMappings, decompilers, splitMinecraftJar, modSourceSets) + return new FabricLoomModelImpl(minecraftVersion, tinyMappings, decompilers, splitMinecraftJar, modSourceSets) } List getDecompilers(Object loomExtension, boolean client) { diff --git a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelImpl.groovy b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelImpl.groovy index 1a04fab1e..d54149dbf 100644 --- a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelImpl.groovy +++ b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModelImpl.groovy @@ -24,6 +24,7 @@ import groovy.transform.Immutable @Immutable(knownImmutableClasses = [File]) class FabricLoomModelImpl implements FabricLoomModel, Serializable { + String minecraftVersion File tinyMappings Map> decompilers boolean splitMinecraftJar diff --git a/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModel.java b/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModel.java index 6198402bf..e984864a2 100644 --- a/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModel.java +++ b/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/fabricloom/FabricLoomModel.java @@ -26,6 +26,8 @@ public interface FabricLoomModel { + String getMinecraftVersion(); + File getTinyMappings(); Map> getDecompilers(); diff --git a/src/main/kotlin/platform/mcp/fabricloom/FabricLoomProjectResolverExtension.kt b/src/main/kotlin/platform/mcp/fabricloom/FabricLoomProjectResolverExtension.kt index 82ec68855..b89478dcc 100644 --- a/src/main/kotlin/platform/mcp/fabricloom/FabricLoomProjectResolverExtension.kt +++ b/src/main/kotlin/platform/mcp/fabricloom/FabricLoomProjectResolverExtension.kt @@ -20,10 +20,13 @@ package com.demonwav.mcdev.platform.mcp.fabricloom +import com.demonwav.mcdev.platform.mcp.McpModuleSettings +import com.demonwav.mcdev.platform.mcp.gradle.McpModelData import com.demonwav.mcdev.platform.mcp.gradle.tooling.fabricloom.FabricLoomModel 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.AbstractProjectResolverExtension class FabricLoomProjectResolverExtension : AbstractProjectResolverExtension() { @@ -50,6 +53,23 @@ class FabricLoomProjectResolverExtension : AbstractProjectResolverExtension() { loomData.modSourceSets ) ideModule.createChild(FabricLoomData.KEY, data) + + val mcpData = McpModelData( + ideModule.data, + McpModuleSettings.State( + minecraftVersion = loomData.minecraftVersion, + ), + null, + null + ) + ideModule.createChild(McpModelData.KEY, mcpData) + + for (child in ideModule.children) { + val childData = child.data + if (childData is GradleSourceSetData) { + child.createChild(McpModelData.KEY, mcpData.copy(module = childData)) + } + } } super.populateModuleExtraModels(gradleModule, ideModule)