Skip to content

Commit

Permalink
Provide Minecraft version in Loom-based projects
Browse files Browse the repository at this point in the history
  • Loading branch information
RedNesto committed Jul 7, 2024
1 parent 336924b commit fbbb2a2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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<FabricLoomModelImpl.DecompilerModelImpl> getDecompilers(Object loomExtension, boolean client) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import groovy.transform.Immutable

@Immutable(knownImmutableClasses = [File])
class FabricLoomModelImpl implements FabricLoomModel, Serializable {
String minecraftVersion
File tinyMappings
Map<String, List<DecompilerModel>> decompilers
boolean splitMinecraftJar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

public interface FabricLoomModel {

String getMinecraftVersion();

File getTinyMappings();

Map<String, List<DecompilerModel>> getDecompilers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit fbbb2a2

Please sign in to comment.