From 59b250f63ada924573694d7d413363b656f0c039 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 16:41:07 +0200 Subject: [PATCH 01/21] Initial work on quilt support --- .../QuiltLoomModelBuilderImpl.groovy | 84 +++++ .../quiltloom/QuiltLoomModelImpl.groovy | 27 ++ .../tooling/quiltloom/QuiltLoomModel.java | 33 ++ ...plugins.gradle.tooling.ModelBuilderService | 1 + src/main/kotlin/asset/PlatformAssets.kt | 3 + .../kotlin/facet/MinecraftFacetEditorTab.kt | 1 + .../kotlin/facet/MinecraftLibraryKinds.kt | 2 + src/main/kotlin/platform/PlatformType.kt | 4 + .../platform/mcp/quiltloom/QuiltLoomData.kt | 31 ++ .../mcp/quiltloom/QuiltLoomDataService.kt | 33 ++ .../QuiltLoomDecompileSourceProvider.kt | 106 ++++++ .../QuiltLoomProjectResolverExtension.kt | 41 +++ .../platform/mcp/quiltloom/TinyUnscrambler.kt | 178 +++++++++++ src/main/kotlin/platform/quilt/EntryPoint.kt | 67 ++++ .../platform/quilt/QuiltFileIconProvider.kt | 38 +++ src/main/kotlin/platform/quilt/QuiltModule.kt | 61 ++++ .../kotlin/platform/quilt/QuiltModuleType.kt | 32 ++ .../platform/quilt/creator/QuiltMcVersion.kt | 20 ++ .../platform/quilt/creator/asset-steps.kt | 301 ++++++++++++++++++ .../platform/quilt/creator/gradle-steps.kt | 86 +++++ .../kotlin/platform/quilt/creator/ui-steps.kt | 284 +++++++++++++++++ .../quilt/framework/QuiltLibraryKind.kt | 16 + .../framework/QuiltPresentationProvider.kt | 40 +++ .../UnresolvedReferenceInspection.kt | 62 ++++ .../reference/QuiltReferenceContributor.kt | 67 ++++ .../platform/quilt/util/QuiltConstants.kt | 19 ++ .../util/QuiltStandardLibrariesVersions.kt | 68 ++++ .../platform/quilt/util/QuiltVersions.kt | 79 +++++ src/main/kotlin/util/MinecraftTemplates.kt | 7 + src/main/resources/META-INF/plugin.xml | 27 +- .../resources/assets/icons/platform/Quilt.png | Bin 0 -> 442 bytes .../assets/icons/platform/Quilt@2x.png | Bin 0 -> 842 bytes .../j2ee/quilt/quilt_build.gradle.ft | 98 ++++++ .../j2ee/quilt/quilt_build.gradle.html | 15 + .../j2ee/quilt/quilt_gradle.properties.ft | 10 + .../j2ee/quilt/quilt_gradle.properties.html | 15 + .../j2ee/quilt/quilt_libs_versions.toml.ft | 28 ++ .../j2ee/quilt/quilt_libs_versions.toml.html | 5 + .../j2ee/quilt/quilt_mixins.json.ft | 13 + .../j2ee/quilt/quilt_mixins.json.html | 15 + .../j2ee/quilt/quilt_mod.json.ft | 39 +++ .../j2ee/quilt/quilt_mod.json.html | 15 + .../j2ee/quilt/quilt_settings.gradle.ft | 12 + .../j2ee/quilt/quilt_settings.gradle.html | 15 + 44 files changed, 2097 insertions(+), 1 deletion(-) create mode 100644 src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelBuilderImpl.groovy create mode 100644 src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelImpl.groovy create mode 100644 src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModel.java create mode 100644 src/main/kotlin/platform/mcp/quiltloom/QuiltLoomData.kt create mode 100644 src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDataService.kt create mode 100644 src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDecompileSourceProvider.kt create mode 100644 src/main/kotlin/platform/mcp/quiltloom/QuiltLoomProjectResolverExtension.kt create mode 100644 src/main/kotlin/platform/mcp/quiltloom/TinyUnscrambler.kt create mode 100644 src/main/kotlin/platform/quilt/EntryPoint.kt create mode 100644 src/main/kotlin/platform/quilt/QuiltFileIconProvider.kt create mode 100644 src/main/kotlin/platform/quilt/QuiltModule.kt create mode 100644 src/main/kotlin/platform/quilt/QuiltModuleType.kt create mode 100644 src/main/kotlin/platform/quilt/creator/QuiltMcVersion.kt create mode 100644 src/main/kotlin/platform/quilt/creator/asset-steps.kt create mode 100644 src/main/kotlin/platform/quilt/creator/gradle-steps.kt create mode 100644 src/main/kotlin/platform/quilt/creator/ui-steps.kt create mode 100644 src/main/kotlin/platform/quilt/framework/QuiltLibraryKind.kt create mode 100644 src/main/kotlin/platform/quilt/framework/QuiltPresentationProvider.kt create mode 100644 src/main/kotlin/platform/quilt/inspection/UnresolvedReferenceInspection.kt create mode 100644 src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt create mode 100644 src/main/kotlin/platform/quilt/util/QuiltConstants.kt create mode 100644 src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt create mode 100644 src/main/kotlin/platform/quilt/util/QuiltVersions.kt create mode 100644 src/main/resources/assets/icons/platform/Quilt.png create mode 100644 src/main/resources/assets/icons/platform/Quilt@2x.png create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.html create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.html create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.html create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.html create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft create mode 100644 src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.html diff --git a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelBuilderImpl.groovy b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelBuilderImpl.groovy new file mode 100644 index 000000000..4205af94d --- /dev/null +++ b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelBuilderImpl.groovy @@ -0,0 +1,84 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.gradle.tooling.quiltloom + +import org.gradle.api.Project +import org.jetbrains.annotations.NotNull +import org.jetbrains.plugins.gradle.tooling.ErrorMessageBuilder +import org.jetbrains.plugins.gradle.tooling.ModelBuilderService + +class QuiltLoomModelBuilderImpl implements ModelBuilderService { + + @Override + boolean canBuild(String modelName) { + return QuiltLoomModel.name == modelName + } + + @Override + Object buildAll(String modelName, Project project) { + if (!project.plugins.hasPlugin('quilt-loom')) { + return null + } + + def loomExtension = project.extensions.getByName('loom') + + try { + return build(project, loomExtension) + } catch (GroovyRuntimeException ignored) { + // Must be using an older loom version, fallback. + return buildLegacy(project, loomExtension) + } + } + + QuiltLoomModel build(Project project, Object loomExtension) { + def tinyMappings = loomExtension.mappingsFile + def splitMinecraftJar = loomExtension.areEnvironmentSourceSetsSplit() + + def decompilers = [:] + + if (splitMinecraftJar) { + decompilers << ["common": getDecompilers(loomExtension, false)] + decompilers << ["client": getDecompilers(loomExtension, true)] + } else { + decompilers << ["single": getDecompilers(loomExtension, false)] + } + + //noinspection GroovyAssignabilityCheck + return new QuiltLoomModelImpl(tinyMappings, decompilers, splitMinecraftJar) + } + + List getDecompilers(Object loomExtension, boolean client) { + loomExtension.decompilerOptions.collect { + def task = loomExtension.getDecompileTask(it, client) + def sourcesPath = task.outputJar.get().getAsFile().getAbsolutePath() + new QuiltLoomModelImpl.DecompilerModelImpl(name: it.name, taskName: task.name, sourcesPath: sourcesPath) + } + } + + QuiltLoomModel buildLegacy(Project project, Object loomExtension) { + def tinyMappings = loomExtension.mappingsProvider.tinyMappings.toFile().getAbsoluteFile() + def decompilers = loomExtension.decompilerOptions.collect { + def task = project.tasks.getByName('genSourcesWith' + it.name.capitalize()) + def sourcesPath = task.runtimeJar.get().getAsFile().getAbsolutePath().dropRight(4) + "-sources.jar" + new QuiltLoomModelImpl.DecompilerModelImpl(name: it.name, taskName: task.name, sourcesPath: sourcesPath) + } + + //noinspection GroovyAssignabilityCheck + return new QuiltLoomModelImpl(tinyMappings, ["single": decompilers], false) + } + + @Override + ErrorMessageBuilder getErrorMessageBuilder(@NotNull Project project, @NotNull Exception e) { + return ErrorMessageBuilder.create( + project, e, "MinecraftDev import errors" + ).withDescription("Unable to build MinecraftDev QuiltLoom project configuration") + } +} diff --git a/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelImpl.groovy b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelImpl.groovy new file mode 100644 index 000000000..6f572ba84 --- /dev/null +++ b/src/gradle-tooling-extension/groovy/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModelImpl.groovy @@ -0,0 +1,27 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.gradle.tooling.quiltloom + +import groovy.transform.Immutable + +@Immutable(knownImmutableClasses = [File]) +class QuiltLoomModelImpl implements QuiltLoomModel, Serializable { + File tinyMappings + Map> decompilers + boolean splitMinecraftJar + + @Immutable + static class DecompilerModelImpl implements DecompilerModel, Serializable { + String name + String taskName + String sourcesPath + } +} diff --git a/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModel.java b/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModel.java new file mode 100644 index 000000000..fbc8944bf --- /dev/null +++ b/src/gradle-tooling-extension/java/com/demonwav/mcdev/platform/mcp/gradle/tooling/quiltloom/QuiltLoomModel.java @@ -0,0 +1,33 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.gradle.tooling.quiltloom; + +import java.io.File; +import java.util.List; +import java.util.Map; + +public interface QuiltLoomModel { + + File getTinyMappings(); + + Map> getDecompilers(); + + boolean getSplitMinecraftJar(); + + interface DecompilerModel { + + String getName(); + + String getTaskName(); + + String getSourcesPath(); + } +} diff --git a/src/gradle-tooling-extension/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService b/src/gradle-tooling-extension/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService index 161ce7c47..2a2eecb33 100644 --- a/src/gradle-tooling-extension/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService +++ b/src/gradle-tooling-extension/resources/META-INF/services/org.jetbrains.plugins.gradle.tooling.ModelBuilderService @@ -1,5 +1,6 @@ com.demonwav.mcdev.platform.mcp.gradle.tooling.archloom.ArchitecturyModelBuilderImpl com.demonwav.mcdev.platform.mcp.gradle.tooling.fabricloom.FabricLoomModelBuilderImpl +com.demonwav.mcdev.platform.mcp.gradle.tooling.quiltloom.QuiltLoomModelBuilderImpl 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 diff --git a/src/main/kotlin/asset/PlatformAssets.kt b/src/main/kotlin/asset/PlatformAssets.kt index c85169541..3b701f7d7 100644 --- a/src/main/kotlin/asset/PlatformAssets.kt +++ b/src/main/kotlin/asset/PlatformAssets.kt @@ -31,6 +31,9 @@ object PlatformAssets : Assets() { val FABRIC_ICON = loadIcon("/assets/icons/platform/Fabric.png") val FABRIC_ICON_2X = loadIcon("/assets/icons/platform/Fabric@2x.png") + val QUILT_ICON = loadIcon("/assets/icons/platform/Quilt.png") + val QUILT_ICON_2X = loadIcon("/assets/icons/platform/Quilt@2x.png") + val ARCHITECTURY_ICON = loadIcon("/assets/icons/platform/Architectury.png") val ARCHITECTURY_ICON_2X = loadIcon("/assets/icons/platform/Architectury@2x.png") diff --git a/src/main/kotlin/facet/MinecraftFacetEditorTab.kt b/src/main/kotlin/facet/MinecraftFacetEditorTab.kt index a2f5956ed..5396fe105 100644 --- a/src/main/kotlin/facet/MinecraftFacetEditorTab.kt +++ b/src/main/kotlin/facet/MinecraftFacetEditorTab.kt @@ -320,6 +320,7 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura PlatformType.SPONGE, PlatformType.FORGE, PlatformType.FABRIC, + PlatformType.QUILT, PlatformType.ARCHITECTURY, PlatformType.MCP, PlatformType.MIXIN, diff --git a/src/main/kotlin/facet/MinecraftLibraryKinds.kt b/src/main/kotlin/facet/MinecraftLibraryKinds.kt index 74e4687e5..0675946e3 100644 --- a/src/main/kotlin/facet/MinecraftLibraryKinds.kt +++ b/src/main/kotlin/facet/MinecraftLibraryKinds.kt @@ -21,6 +21,7 @@ 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.mixin.framework.MIXIN_LIBRARY_KIND +import com.demonwav.mcdev.platform.quilt.framework.QUILT_LIBRARY_KIND import com.demonwav.mcdev.platform.sponge.framework.SPONGE_LIBRARY_KIND import com.demonwav.mcdev.platform.velocity.framework.VELOCITY_LIBRARY_KIND @@ -31,6 +32,7 @@ val MINECRAFT_LIBRARY_KINDS = setOf( SPONGE_LIBRARY_KIND, FORGE_LIBRARY_KIND, FABRIC_LIBRARY_KIND, + QUILT_LIBRARY_KIND, ARCHITECTURY_LIBRARY_KIND, MCP_LIBRARY_KIND, MIXIN_LIBRARY_KIND, diff --git a/src/main/kotlin/platform/PlatformType.kt b/src/main/kotlin/platform/PlatformType.kt index 6cc753a50..ae43de211 100644 --- a/src/main/kotlin/platform/PlatformType.kt +++ b/src/main/kotlin/platform/PlatformType.kt @@ -32,6 +32,8 @@ import com.demonwav.mcdev.platform.mcp.McpModuleType import com.demonwav.mcdev.platform.mcp.framework.MCP_LIBRARY_KIND import com.demonwav.mcdev.platform.mixin.MixinModuleType import com.demonwav.mcdev.platform.mixin.framework.MIXIN_LIBRARY_KIND +import com.demonwav.mcdev.platform.quilt.QuiltModuleType +import com.demonwav.mcdev.platform.quilt.framework.QUILT_LIBRARY_KIND import com.demonwav.mcdev.platform.sponge.SpongeModuleType import com.demonwav.mcdev.platform.sponge.framework.SPONGE_LIBRARY_KIND import com.demonwav.mcdev.platform.velocity.VelocityModuleType @@ -50,6 +52,7 @@ enum class PlatformType( ARCHITECTURY(ArchitecturyModuleType), FORGE(ForgeModuleType), FABRIC(FabricModuleType), + QUILT(QuiltModuleType), SPONGE(SpongeModuleType), BUNGEECORD(BungeeCordModuleType, "bungeecord_v2.json"), WATERFALL(WaterfallModuleType, "waterfall.json", BUNGEECORD), @@ -82,6 +85,7 @@ enum class PlatformType( ARCHITECTURY_LIBRARY_KIND -> ARCHITECTURY FORGE_LIBRARY_KIND -> FORGE FABRIC_LIBRARY_KIND -> FABRIC + QUILT_LIBRARY_KIND -> QUILT MCP_LIBRARY_KIND -> MCP MIXIN_LIBRARY_KIND -> MIXIN BUNGEECORD_LIBRARY_KIND -> BUNGEECORD diff --git a/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomData.kt b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomData.kt new file mode 100644 index 000000000..322673f44 --- /dev/null +++ b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomData.kt @@ -0,0 +1,31 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.quiltloom + +import com.intellij.openapi.externalSystem.model.Key +import com.intellij.openapi.externalSystem.model.ProjectKeys +import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData +import com.intellij.openapi.externalSystem.model.project.ModuleData +import java.io.File + +data class QuiltLoomData( + val module: ModuleData, + val tinyMappings: File?, + val decompileTasks: Map>, + val splitMinecraftJar: Boolean, +) : AbstractExternalEntityData(module.owner) { + + data class Decompiler(val name: String, val taskName: String, val sourcesPath: String) + + companion object { + val KEY = Key.create(QuiltLoomData::class.java, ProjectKeys.TASK.processingWeight + 1) + } +} diff --git a/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDataService.kt b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDataService.kt new file mode 100644 index 000000000..fa69576cd --- /dev/null +++ b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDataService.kt @@ -0,0 +1,33 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.quiltloom + +import com.intellij.openapi.externalSystem.model.DataNode +import com.intellij.openapi.externalSystem.model.Key +import com.intellij.openapi.externalSystem.model.project.ProjectData +import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider +import com.intellij.openapi.externalSystem.service.project.manage.AbstractProjectDataService +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project + +class QuiltLoomDataService : AbstractProjectDataService() { + + override fun getTargetDataKey(): Key = QuiltLoomData.KEY + + override fun importData( + toImport: Collection>, + projectData: ProjectData?, + project: Project, + modelsProvider: IdeModifiableModelsProvider, + ) { + // Dummy service to enable platform-side DataNodes cache + } +} diff --git a/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDecompileSourceProvider.kt b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDecompileSourceProvider.kt new file mode 100644 index 000000000..52f0d9a1d --- /dev/null +++ b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomDecompileSourceProvider.kt @@ -0,0 +1,106 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.quiltloom + +import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side +import com.demonwav.mcdev.platform.forge.inspections.sideonly.SideOnlyUtil +import com.demonwav.mcdev.util.findModule +import com.demonwav.mcdev.util.runGradleTaskWithCallback +import com.intellij.codeInsight.AttachSourcesProvider +import com.intellij.openapi.application.runWriteActionAndWait +import com.intellij.openapi.externalSystem.task.TaskCallback +import com.intellij.openapi.roots.LibraryOrderEntry +import com.intellij.openapi.roots.OrderRootType +import com.intellij.openapi.util.ActionCallback +import com.intellij.psi.PsiFile +import com.intellij.psi.PsiJavaFile +import java.nio.file.Paths +import org.jetbrains.plugins.gradle.util.GradleUtil + +class QuiltLoomDecompileSourceProvider : AttachSourcesProvider { + override fun getActions( + orderEntries: List, + psiFile: PsiFile, + ): Collection { + if (psiFile !is PsiJavaFile || !psiFile.packageName.startsWith("net.minecraft")) { + return emptyList() + } + + val module = psiFile.findModule() ?: return emptyList() + val loomData = GradleUtil.findGradleModuleData(module)?.children + ?.find { it.key == QuiltLoomData.KEY }?.data as? QuiltLoomData + ?: return emptyList() + + val env = if (!loomData.splitMinecraftJar) { + "single" + } else if (isClientClass(psiFile)) { + "client" + } else { + "common" + } + + val decompileTasks = loomData.decompileTasks[env] ?: return emptyList() + return decompileTasks.map(::DecompileAction) + } + + private fun isClientClass(psiFile: PsiJavaFile): Boolean { + return psiFile.classes.any { psiClass -> + return SideOnlyUtil.getSideForClass(psiClass).second == Side.CLIENT + } + } + + private class DecompileAction(val decompiler: QuiltLoomData.Decompiler) : + AttachSourcesProvider.AttachSourcesAction { + + override fun getName(): String = "Decompile with ${decompiler.name}" + + override fun getBusyText(): String = "Decompiling Minecraft..." + + override fun perform(orderEntriesContainingFile: List): ActionCallback { + val project = orderEntriesContainingFile.firstOrNull()?.ownerModule?.project + ?: return ActionCallback.REJECTED + val projectPath = project.basePath ?: return ActionCallback.REJECTED + + val callback = ActionCallback() + val taskCallback = object : TaskCallback { + override fun onSuccess() { + attachSources(orderEntriesContainingFile, decompiler.sourcesPath) + callback.setDone() + } + + override fun onFailure() = callback.setRejected() + } + runGradleTaskWithCallback( + project, + Paths.get(projectPath), + { settings -> settings.taskNames = listOf(decompiler.taskName) }, + taskCallback, + ) + return callback + } + + private fun attachSources(libraryEntries: List, sourcePath: String): ActionCallback? { + // Distinct because for some reason the same library is in there twice + for (libraryEntry in libraryEntries.distinctBy { it.libraryName }) { + val library = libraryEntry.library + if (library != null) { + runWriteActionAndWait { + val model = library.modifiableModel + model.addRoot("jar://$sourcePath!/", OrderRootType.SOURCES) + model.commit() + } + } + } + + return ActionCallback.DONE + } + } +} diff --git a/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomProjectResolverExtension.kt b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomProjectResolverExtension.kt new file mode 100644 index 000000000..c93dc9aaf --- /dev/null +++ b/src/main/kotlin/platform/mcp/quiltloom/QuiltLoomProjectResolverExtension.kt @@ -0,0 +1,41 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.quiltloom + +import com.demonwav.mcdev.platform.mcp.gradle.tooling.quiltloom.QuiltLoomModel +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.service.project.AbstractProjectResolverExtension + +class QuiltLoomProjectResolverExtension : AbstractProjectResolverExtension() { + + override fun getExtraProjectModelClasses(): Set> = + setOf(QuiltLoomModel::class.java) + + override fun getToolingExtensionsClasses() = extraProjectModelClasses + + override fun populateModuleExtraModels(gradleModule: IdeaModule, ideModule: DataNode) { + val loomData = resolverCtx.getExtraProject(gradleModule, QuiltLoomModel::class.java) + if (loomData != null) { + val decompilers = loomData.decompilers.mapValues { (_, decompilers) -> + decompilers.mapTo(mutableSetOf()) { decompiler -> + QuiltLoomData.Decompiler(decompiler.name, decompiler.taskName, decompiler.sourcesPath) + } + } + + val data = QuiltLoomData(ideModule.data, loomData.tinyMappings, decompilers, loomData.splitMinecraftJar) + ideModule.createChild(QuiltLoomData.KEY, data) + } + + super.populateModuleExtraModels(gradleModule, ideModule) + } +} diff --git a/src/main/kotlin/platform/mcp/quiltloom/TinyUnscrambler.kt b/src/main/kotlin/platform/mcp/quiltloom/TinyUnscrambler.kt new file mode 100644 index 000000000..be05c01bb --- /dev/null +++ b/src/main/kotlin/platform/mcp/quiltloom/TinyUnscrambler.kt @@ -0,0 +1,178 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.mcp.quiltloom + +import com.demonwav.mcdev.facet.MinecraftFacet +import com.demonwav.mcdev.platform.quilt.QuiltModuleType +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.project.ProjectManager +import com.intellij.openapi.ui.ComboBox +import com.intellij.ui.SimpleListCellRenderer +import com.intellij.ui.components.JBLabel +import com.intellij.uiDesigner.core.GridConstraints +import com.intellij.uiDesigner.core.GridLayoutManager +import com.intellij.unscramble.UnscrambleSupport +import java.awt.Dimension +import java.nio.file.Path +import java.nio.file.Paths +import javax.swing.JPanel +import net.fabricmc.mappingio.MappedElementKind +import net.fabricmc.mappingio.MappingReader +import net.fabricmc.mappingio.MappingVisitor +import org.jdesktop.swingx.combobox.MapComboBoxModel +import org.jetbrains.plugins.gradle.util.GradleUtil + +class TinyUnscrambler : UnscrambleSupport { + + private val symbolPattern = Regex("(([\\w$]+\\.)*(class_\\d+\\$?)+)|((?:field|method)_\\d+)") + + override fun getPresentableName() = "Remap Tiny names" + + class SettingsComponent(mappings: Map) : JPanel(GridLayoutManager(1, 2)) { + + val mappingsBoxModel = MapComboBoxModel(mappings) + val mappingsBox = ComboBox(mappingsBoxModel) + + init { + mappingsBox.renderer = SimpleListCellRenderer.create { label, value, _ -> + val path = mappingsBoxModel.getValue(value) + label.text = "[$value] $path" + } + add( + JBLabel("Mappings: "), + GridConstraints( + 0, + 0, + 1, + 1, + GridConstraints.ANCHOR_WEST, + GridConstraints.FILL_NONE, + GridConstraints.SIZEPOLICY_FIXED, + GridConstraints.SIZEPOLICY_FIXED, + Dimension(-1, -1), + Dimension(-1, -1), + Dimension(-1, -1), + ), + ) + add( + mappingsBox, + GridConstraints( + 0, + 1, + 1, + 1, + GridConstraints.ANCHOR_WEST, + GridConstraints.FILL_HORIZONTAL, + GridConstraints.SIZEPOLICY_WANT_GROW, + GridConstraints.SIZEPOLICY_FIXED, + Dimension(-1, -1), + Dimension(-1, -1), + Dimension(-1, -1), + ), + ) + } + } + + override fun createSettingsComponent(): SettingsComponent { + val mappings = mutableMapOf() + for (project in ProjectManager.getInstance().openProjects) { + ModuleManager.getInstance(project).modules + .filter { MinecraftFacet.getInstance(it, QuiltModuleType) != null } + .associateTo(mappings) { module -> + val loomData = GradleUtil.findGradleModuleData(module)?.children + ?.find { it.key == QuiltLoomData.KEY }?.data as? QuiltLoomData + ?: return@associateTo module.name to null + module.name to loomData.tinyMappings?.toPath() + } + } + + @Suppress("UNCHECKED_CAST") + return SettingsComponent(mappings.filterValues { it != null } as Map) + } + + override fun unscramble(project: Project, text: String, logName: String, settings: SettingsComponent?): String? { + val mappingsFile = logName.takeIf(String::isNotBlank)?.let(Paths::get) + ?: settings?.mappingsBoxModel?.let { mappings -> mappings.selectedItem?.let(mappings::getValue) } + ?: return null + + val interToNamed = mutableMapOf() + val visitor = object : MappingVisitor { + var interNsIndex = -1 + var namedNsIndex = -1 + + lateinit var src: String + var inter: String? = null + var named: String? = null + + override fun visitNamespaces(srcNamespace: String, dstNamespaces: MutableList) { + namedNsIndex = dstNamespaces.indexOf("named") + interNsIndex = dstNamespaces.indexOf("intermediary") + } + + override fun visitContent(): Boolean { + return interNsIndex >= 0 && namedNsIndex >= 0 + } + + override fun visitClass(srcName: String): Boolean { + src = srcName.replace('/', '.') + return true + } + + override fun visitField(srcName: String, srcDesc: String): Boolean { + src = srcName + return true + } + + override fun visitMethod(srcName: String, srcDesc: String): Boolean { + src = srcName + return true + } + + override fun visitMethodArg(argPosition: Int, lvIndex: Int, srcName: String): Boolean { + return false + } + + override fun visitMethodVar(lvtRowIndex: Int, lvIndex: Int, startOpIdx: Int, srcName: String): Boolean { + return false + } + + override fun visitDstName(targetKind: MappedElementKind, namespace: Int, name: String) { + when (namespace) { + interNsIndex -> inter = name + namedNsIndex -> named = name + else -> return + } + + if (inter != null && named != null) { + interToNamed[inter!!] = named!! + if (targetKind == MappedElementKind.CLASS) { + // Remap dot-separated qualified classes and simple class names too + interToNamed[inter!!.replace('/', '.')] = named!!.replace('/', '.') + interToNamed[inter!!.substringAfterLast('/')] = named!!.substringAfterLast('/') + } + } + } + + override fun visitComment(targetKind: MappedElementKind, comment: String) { + } + + override fun visitElementContent(targetKind: MappedElementKind?): Boolean { + return targetKind != MappedElementKind.METHOD + } + } + + MappingReader.read(mappingsFile, visitor) + return symbolPattern.replace(text) { + interToNamed[it.value] ?: it.value + } + } +} diff --git a/src/main/kotlin/platform/quilt/EntryPoint.kt b/src/main/kotlin/platform/quilt/EntryPoint.kt new file mode 100644 index 000000000..cf416c5f3 --- /dev/null +++ b/src/main/kotlin/platform/quilt/EntryPoint.kt @@ -0,0 +1,67 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt + +import com.demonwav.mcdev.creator.isValidClassName +import com.intellij.openapi.project.Project +import com.intellij.psi.CommonClassNames +import com.intellij.psi.JavaPsiFacade +import com.intellij.psi.PsiMethod +import com.intellij.psi.PsiModifier +import com.intellij.psi.search.GlobalSearchScope + +data class EntryPoint( + val category: String, + val type: Type, + val className: String, + val interfaceName: String, + val methodName: String? = null, +) { + private val dumbReference = when (type) { + Type.CLASS -> className + Type.METHOD -> "$className::$methodName" + } + + val valid by lazy { category.isNotBlank() && isValidClassName(className) && isValidClassName(interfaceName) } + + fun computeReference(project: Project): String { + if (type != Type.METHOD || methodName != null) { + return dumbReference + } + return "$className::${findFunctionalMethod(project)?.name}" + } + + fun findFunctionalMethod(project: Project): PsiMethod? { + val classFinder = JavaPsiFacade.getInstance(project) + val clazz = classFinder.findClass(className, GlobalSearchScope.projectScope(project)) ?: return null + val interfaceClass = classFinder.findClass(interfaceName, clazz.resolveScope) ?: return null + if (!interfaceClass.isInterface) { + return null + } + val candidates = interfaceClass.allMethods + .filter { + !it.hasModifierProperty(PsiModifier.STATIC) && + !it.hasModifierProperty(PsiModifier.DEFAULT) && + it.containingClass?.qualifiedName != CommonClassNames.JAVA_LANG_OBJECT + } + return if (candidates.size == 1) { + candidates[0] + } else { + null + } + } + + override fun toString() = "$category -> $dumbReference implements $interfaceName" + + enum class Type { + CLASS, METHOD + } +} diff --git a/src/main/kotlin/platform/quilt/QuiltFileIconProvider.kt b/src/main/kotlin/platform/quilt/QuiltFileIconProvider.kt new file mode 100644 index 000000000..814501bd4 --- /dev/null +++ b/src/main/kotlin/platform/quilt/QuiltFileIconProvider.kt @@ -0,0 +1,38 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt + +import com.demonwav.mcdev.MinecraftSettings +import com.demonwav.mcdev.facet.MinecraftFacet +import com.intellij.ide.FileIconProvider +import com.intellij.openapi.module.ModuleUtilCore +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import javax.swing.Icon + +class QuiltFileIconProvider : FileIconProvider { + override fun getIcon(file: VirtualFile, flags: Int, project: Project?): Icon? { + project ?: return null + + if (!MinecraftSettings.instance.isShowProjectPlatformIcons) { + return null + } + + val module = ModuleUtilCore.findModuleForFile(file, project) ?: return null + val quiltModule = MinecraftFacet.getInstance(module, QuiltModuleType) ?: return null + + if (file == quiltModule.quiltJson) { + return quiltModule.icon + } + + return null + } +} diff --git a/src/main/kotlin/platform/quilt/QuiltModule.kt b/src/main/kotlin/platform/quilt/QuiltModule.kt new file mode 100644 index 000000000..a0c9b1c58 --- /dev/null +++ b/src/main/kotlin/platform/quilt/QuiltModule.kt @@ -0,0 +1,61 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt + +import com.demonwav.mcdev.asset.PlatformAssets +import com.demonwav.mcdev.facet.MinecraftFacet +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.quilt.util.QuiltConstants +import com.demonwav.mcdev.util.SourceType +import com.demonwav.mcdev.util.nullable +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiMethod +import com.intellij.psi.search.searches.ReferencesSearch +import org.jetbrains.uast.UClass +import org.jetbrains.uast.UIdentifier +import org.jetbrains.uast.UMethod +import org.jetbrains.uast.toUElementOfType + +class QuiltModule internal constructor(facet: MinecraftFacet) : AbstractModule(facet) { + + var quiltJson by nullable { facet.findFile(QuiltConstants.QUILT_MOD_JSON, SourceType.RESOURCE) } + private set + + override val moduleType = QuiltModuleType + override val type = PlatformType.QUILT + override val icon = PlatformAssets.QUILT_ICON + + override fun isEventClassValid(eventClass: PsiClass, method: PsiMethod?) = true + + override fun writeErrorMessageForEventParameter(eventClass: PsiClass, method: PsiMethod) = "" + + override fun shouldShowPluginIcon(element: PsiElement?): Boolean { + val identifier = element?.toUElementOfType() + ?: return false + + val parent = identifier.uastParent + if (parent !is UClass && parent !is UMethod) { + return false + } + + val psiParent = parent.sourcePsi + ?: return false + return ReferencesSearch.search(psiParent).anyMatch { EntryPointReference.isEntryPointReference(it) } + } + + override fun dispose() { + super.dispose() + quiltJson = null + } +} diff --git a/src/main/kotlin/platform/quilt/QuiltModuleType.kt b/src/main/kotlin/platform/quilt/QuiltModuleType.kt new file mode 100644 index 000000000..4fae0a059 --- /dev/null +++ b/src/main/kotlin/platform/quilt/QuiltModuleType.kt @@ -0,0 +1,32 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt + +import com.demonwav.mcdev.asset.PlatformAssets +import com.demonwav.mcdev.facet.MinecraftFacet +import com.demonwav.mcdev.platform.AbstractModuleType +import com.demonwav.mcdev.platform.PlatformType + +object QuiltModuleType : AbstractModuleType("", "") { + + private const val ID = "QUILT_MODULE_TYPE" + + val IGNORED_ANNOTATIONS = emptyList() + val LISTENER_ANNOTATIONS = emptyList() + + override val platformType = PlatformType.QUILT + override val icon = PlatformAssets.QUILT_ICON + override val id = ID + override val ignoredAnnotations = IGNORED_ANNOTATIONS + override val listenerAnnotations = LISTENER_ANNOTATIONS + + override fun generateModule(facet: MinecraftFacet) = QuiltModule(facet) +} diff --git a/src/main/kotlin/platform/quilt/creator/QuiltMcVersion.kt b/src/main/kotlin/platform/quilt/creator/QuiltMcVersion.kt new file mode 100644 index 000000000..ecec6f853 --- /dev/null +++ b/src/main/kotlin/platform/quilt/creator/QuiltMcVersion.kt @@ -0,0 +1,20 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.creator + +class QuiltMcVersion( + private val ordinal: Int, + val version: String, + val stable: Boolean, +) : Comparable { + override fun toString() = version + override fun compareTo(other: QuiltMcVersion) = ordinal.compareTo(other.ordinal) +} diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt new file mode 100644 index 000000000..0c6d83df0 --- /dev/null +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -0,0 +1,301 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.creator + +import com.demonwav.mcdev.asset.MCDevBundle +import com.demonwav.mcdev.creator.JdkProjectSetupFinalizer +import com.demonwav.mcdev.creator.addLicense +import com.demonwav.mcdev.creator.addTemplates +import com.demonwav.mcdev.creator.buildsystem.AbstractBuildSystemStep +import com.demonwav.mcdev.creator.buildsystem.AbstractRunBuildSystemStep +import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep +import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport +import com.demonwav.mcdev.creator.findStep +import com.demonwav.mcdev.creator.step.* +import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side +import com.demonwav.mcdev.platform.quilt.EntryPoint +import com.demonwav.mcdev.platform.quilt.util.QuiltConstants +import com.demonwav.mcdev.util.MinecraftTemplates.Companion.QUILT_MIXINS_JSON_TEMPLATE +import com.demonwav.mcdev.util.MinecraftTemplates.Companion.QUILT_MOD_JSON_TEMPLATE +import com.demonwav.mcdev.util.addImplements +import com.demonwav.mcdev.util.addMethod +import com.demonwav.mcdev.util.invokeLater +import com.demonwav.mcdev.util.runWriteAction +import com.demonwav.mcdev.util.runWriteTaskInSmartMode +import com.demonwav.mcdev.util.toJavaClassName +import com.demonwav.mcdev.util.toPackageName +import com.intellij.codeInsight.actions.ReformatCodeProcessor +import com.intellij.codeInsight.generation.OverrideImplementUtil +import com.intellij.ide.starters.local.GeneratorEmptyDirectory +import com.intellij.ide.util.EditorHelper +import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.json.psi.JsonArray +import com.intellij.json.psi.JsonElementGenerator +import com.intellij.json.psi.JsonFile +import com.intellij.json.psi.JsonObject +import com.intellij.openapi.project.Project +import com.intellij.openapi.ui.Messages +import com.intellij.openapi.util.text.StringUtil +import com.intellij.openapi.vfs.VfsUtil +import com.intellij.psi.JavaDirectoryService +import com.intellij.psi.JavaPsiFacade +import com.intellij.psi.PsiClass +import com.intellij.psi.PsiManager +import com.intellij.psi.search.GlobalSearchScope +import com.intellij.util.IncorrectOperationException +import java.nio.file.Path +import java.util.concurrent.CountDownLatch + +class QuiltDumbModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAssetsStep(parent) { + override val description = "Adding Quilt project files (phase 1)" + + override fun setupAssets(project: Project) { + val buildSystemProps = findStep>() + val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false + val javaVersion = findStep().preferredJdk.ordinal + + if (useMixins) { + val packageName = + "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}.mixin" + assets.addTemplateProperties( + "PACKAGE_NAME" to packageName, + "JAVA_VERSION" to javaVersion, + ) + val mixinsJsonFile = "src/main/resources/${buildSystemProps.artifactId}.mixins.json" + assets.addTemplates(project, mixinsJsonFile to QUILT_MIXINS_JSON_TEMPLATE) + } + + assets.addLicense(project) + + assets.addAssets( + GeneratorEmptyDirectory("src/main/java"), + GeneratorEmptyDirectory("src/main/resources"), + ) + } +} + +class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAssetsStep(parent) { + override val description = "Adding Quilt project files (phase 2)" + + private lateinit var entryPoints: List + + override fun setupAssets(project: Project) { + val buildSystemProps = findStep>() + val modName = data.getUserData(AbstractModNameStep.KEY) ?: return + val description = data.getUserData(DescriptionStep.KEY) ?: "" + val envName = when (data.getUserData(QuiltEnvironmentStep.KEY) ?: Side.NONE) { + Side.CLIENT -> "client" + Side.SERVER -> "server" + else -> "*" + } + val loaderVersion = data.getUserData(QuiltVersionChainStep.LOADER_VERSION_KEY) ?: return + val mcVersion = data.getUserData(QuiltVersionChainStep.MC_VERSION_KEY) ?: return + val javaVersion = findStep().preferredJdk.ordinal + val license = data.getUserData(LicenseStep.KEY) ?: return + val apiVersion = data.getUserData(QuiltVersionChainStep.API_VERSION_KEY) + val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false + + val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}" + val mainClassName = "$packageName.${modName.toJavaClassName()}" + val clientClassName = "$packageName.client.${modName.toJavaClassName()}Client" + entryPoints = listOf( + EntryPoint("main", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), + EntryPoint("client", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), + ) // TODO: un-hardcode? + + assets.addTemplateProperties( + "ARTIFACT_ID" to buildSystemProps.artifactId, + "MOD_NAME" to StringUtil.escapeStringCharacters(modName), + "MOD_DESCRIPTION" to StringUtil.escapeStringCharacters(description), + "MOD_ENVIRONMENT" to envName, + "LOADER_VERSION" to loaderVersion, + "MC_VERSION" to mcVersion, + "JAVA_VERSION" to javaVersion, + "LICENSE" to license.id, + ) + + if (apiVersion != null) { + assets.addTemplateProperties("API_VERSION" to apiVersion) + } + + if (useMixins) { + assets.addTemplateProperties("MIXINS" to "true") + } + + assets.addTemplates(project, "src/main/resources/quilt.mod.json" to QUILT_MOD_JSON_TEMPLATE) + } + + private fun fixupQuiltModJson(project: Project) { + val authors = data.getUserData(QuiltAuthorsStep.KEY) ?: emptyList() + val website = data.getUserData(WebsiteStep.KEY) + val repo = data.getUserData(RepositoryStep.KEY) + val issues = data.getUserData(IssueTrackerStep.KEY) + + val quiltModJsonFile = + VfsUtil.findFile(Path.of(context.projectFileDirectory, "src", "main", "resources", "quilt.mod.json"), true) + ?: return + val jsonFile = PsiManager.getInstance(project).findFile(quiltModJsonFile) as? JsonFile ?: return + val json = jsonFile.topLevelValue as? JsonObject ?: return + val generator = JsonElementGenerator(project) + + jsonFile.runWriteAction { + ((json.findProperty("quilt_loader")?.value as? JsonObject) + ?.findProperty("metadata") as? JsonObject) + ?.findProperty("contributors") + ?.let { authorsObject -> + for (i in authors.indices) { + if (i != 0) { + authorsObject.addBefore(generator.createComma(), authorsObject.lastChild) + } + val key = StringUtil.escapeStringCharacters(authors[i].first) + val value = "\"" + StringUtil.escapeStringCharacters(authors[i].second) + "\"" + authorsObject.addBefore(generator.createProperty(key, value), authorsObject.lastChild) + } + } + + ((json.findProperty("quilt_loader")?.value as? JsonObject) + ?.findProperty("metadata") as? JsonObject) + ?.findProperty("contact") + ?.let { contactObject -> + val properties = mutableListOf>() + if (!website.isNullOrBlank()) { + properties += "homepage" to website + } + if (!repo.isNullOrBlank()) { + properties += "sources" to repo + } + if (!issues.isNullOrBlank()) { + properties += "issues" to issues + } + for (i in properties.indices) { + if (i != 0) { + contactObject.addBefore(generator.createComma(), contactObject.lastChild) + } + val key = StringUtil.escapeStringCharacters(properties[i].first) + val value = "\"" + StringUtil.escapeStringCharacters(properties[i].second) + "\"" + contactObject.addBefore(generator.createProperty(key, value), contactObject.lastChild) + } + } + + ((json.findProperty("quilt_loader")?.value as? JsonObject) + ?.findProperty("entrypoints")?.value as? JsonObject) + ?.let { entryPointsObject -> + val entryPointsByCategory = entryPoints + .groupBy { it.category } + .asSequence() + .sortedBy { it.key } + .toList() + for (i in entryPointsByCategory.indices) { + val entryPointCategory = entryPointsByCategory[i] + if (i != 0) { + entryPointsObject.addBefore(generator.createComma(), entryPointsObject.lastChild) + } + val values = generator.createValue("[]") + for (j in entryPointCategory.value.indices) { + if (j != 0) { + values.addBefore(generator.createComma(), values.lastChild) + } + val entryPointReference = entryPointCategory.value[j].computeReference(project) + val value = generator.createStringLiteral(entryPointReference) + values.addBefore(value, values.lastChild) + } + val key = StringUtil.escapeStringCharacters(entryPointCategory.key) + val prop = generator.createProperty(key, "[]") + prop.value?.replace(values) + entryPointsObject.addBefore(prop, entryPointsObject.lastChild) + } + } + + ReformatCodeProcessor(project, jsonFile, null, false).run() + } + } + + private fun createEntryPoints(project: Project) { + val root = VfsUtil.findFile(Path.of(context.projectFileDirectory), true) ?: return + val psiManager = PsiManager.getInstance(project) + + val generatedClasses = mutableSetOf() + + for (entryPoint in entryPoints) { + // find the class, and create it if it doesn't exist + val clazz = JavaPsiFacade.getInstance(project).findClass( + entryPoint.className, + GlobalSearchScope.projectScope(project), + ) ?: run { + val packageName = entryPoint.className.substringBeforeLast('.', missingDelimiterValue = "") + val className = entryPoint.className.substringAfterLast('.') + + val dir = VfsUtil.createDirectoryIfMissing(root, "src/main/java/${packageName.replace('.', '/')}") + val psiDir = psiManager.findDirectory(dir) ?: return@run null + try { + JavaDirectoryService.getInstance().createClass(psiDir, className) + } catch (e: IncorrectOperationException) { + invokeLater { + val message = MCDevBundle.message( + "intention.error.cannot.create.class.message", + className, + e.localizedMessage, + ) + Messages.showErrorDialog( + project, + message, + MCDevBundle.message("intention.error.cannot.create.class.title"), + ) + } + return + } + } ?: continue + + clazz.containingFile.runWriteAction { + clazz.addImplements(entryPoint.interfaceName) + + val methodsToImplement = OverrideImplementUtil.getMethodsToOverrideImplement(clazz, true) + val methods = OverrideImplementUtil.overrideOrImplementMethodCandidates(clazz, methodsToImplement, true) + for (method in methods) { + clazz.addMethod(method) + } + } + + generatedClasses += clazz + } + + for (clazz in generatedClasses) { + ReformatCodeProcessor(project, clazz.containingFile, null, false).run() + EditorHelper.openInEditor(clazz) + } + } + + override fun perform(project: Project) { + super.perform(project) + val latch = CountDownLatch(1) + assets.runWhenCreated(project) { + project.runWriteTaskInSmartMode { + try { + fixupQuiltModJson(project) + createEntryPoints(project) + } finally { + latch.countDown() + } + } + } + latch.await() + } +} + +class QuiltBuildSystemStep(parent: NewProjectWizardStep) : AbstractBuildSystemStep(parent) { + override val platformName = "Quilt" +} + +class QuiltPostBuildSystemStep( + parent: NewProjectWizardStep, +) : AbstractRunBuildSystemStep(parent, QuiltBuildSystemStep::class.java) { + override val step = BuildSystemSupport.POST_STEP +} diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt new file mode 100644 index 000000000..340c1c0ba --- /dev/null +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -0,0 +1,86 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.creator + +import com.demonwav.mcdev.creator.EmptyStep +import com.demonwav.mcdev.creator.JdkProjectSetupFinalizer +import com.demonwav.mcdev.creator.addGradleGitignore +import com.demonwav.mcdev.creator.addTemplates +import com.demonwav.mcdev.creator.buildsystem.* +import com.demonwav.mcdev.creator.findStep +import com.demonwav.mcdev.creator.gitEnabled +import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep +import com.demonwav.mcdev.util.MinecraftTemplates +import com.demonwav.mcdev.util.SemanticVersion +import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.project.Project + +class QuiltGradleSupport : BuildSystemSupport { + override val preferred = true + + override fun createStep(step: String, parent: NewProjectWizardStep): NewProjectWizardStep { + return when (step) { + BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent).nextStep(::GradleWrapperStep) + BuildSystemSupport.POST_STEP -> GradleImportStep(parent) + else -> EmptyStep(parent) + } + } +} + +class QuiltGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAssetsStep(parent) { + override val description = "Creating Gradle files" + + override fun setupAssets(project: Project) { + val buildSystemProps = findStep>() + val mcVersion = data.getUserData(QuiltVersionChainStep.MC_VERSION_KEY) ?: return + val quiltMappingsVersion = data.getUserData(QuiltVersionChainStep.QUILT_MAPPINGS_VERSION_KEY) ?: return + val loaderVersion = data.getUserData(QuiltVersionChainStep.LOADER_VERSION_KEY) ?: return + val loomVersion = "1.1-" // TODO + val javaVersion = findStep().preferredJdk.ordinal + val apiVersion = data.getUserData(QuiltVersionChainStep.API_VERSION_KEY) + val officialMappings = data.getUserData(QuiltVersionChainStep.OFFICIAL_MAPPINGS_KEY) ?: false + + assets.addTemplateProperties( + "GROUP_ID" to buildSystemProps.groupId, + "ARTIFACT_ID" to buildSystemProps.artifactId, + "VERSION" to buildSystemProps.version, + "MC_VERSION" to mcVersion, + "QUILT_MAPPINGS" to quiltMappingsVersion, + "LOADER_VERSION" to loaderVersion, + "LOOM_VERSION" to loomVersion, + "JAVA_VERSION" to javaVersion, + ) + + if (apiVersion != null) { + assets.addTemplateProperties("API_VERSION" to apiVersion) + } + + if (officialMappings) { + assets.addTemplateProperties("OFFICIAL_MAPPINGS" to "true") + } + + assets.addTemplates( + project, + "build.gradle" to MinecraftTemplates.QUILT_BUILD_GRADLE_TEMPLATE, + "gradle.properties" to MinecraftTemplates.QUILT_GRADLE_PROPERTIES_TEMPLATE, + "settings.gradle" to MinecraftTemplates.QUILT_SETTINGS_GRADLE_TEMPLATE, + "gradle/libs.versions.toml" to MinecraftTemplates.QUILT_LIBS_VERSIONS_TEMPLATE + ) + + assets.data.putUserData(GRADLE_VERSION_KEY, SemanticVersion.release(8,0,2)) + assets.addGradleWrapperProperties(project) + + if (gitEnabled) { + assets.addGradleGitignore(project) + } + } +} diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt new file mode 100644 index 000000000..59706b49b --- /dev/null +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -0,0 +1,284 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.creator + +import com.demonwav.mcdev.creator.platformtype.ModPlatformStep +import com.demonwav.mcdev.creator.step.* +import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep +import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side +import com.demonwav.mcdev.platform.quilt.util.QuiltStandardLibrariesVersions +import com.demonwav.mcdev.platform.quilt.util.QuiltVersions +import com.demonwav.mcdev.util.SemanticVersion +import com.demonwav.mcdev.util.asyncIO +import com.demonwav.mcdev.util.bindEnabled +import com.intellij.ide.users.LocalUserSettings +import com.intellij.ide.wizard.AbstractNewProjectWizardStep +import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.observable.util.bindBooleanStorage +import com.intellij.openapi.observable.util.bindStorage +import com.intellij.openapi.observable.util.not +import com.intellij.openapi.observable.util.transform +import com.intellij.openapi.project.Project +import com.intellij.openapi.util.Key +import com.intellij.ui.JBColor +import com.intellij.ui.dsl.builder.Cell +import com.intellij.ui.dsl.builder.EMPTY_LABEL +import com.intellij.ui.dsl.builder.Panel +import com.intellij.ui.dsl.builder.Row +import com.intellij.ui.dsl.builder.bindItem +import com.intellij.ui.dsl.builder.bindSelected +import com.intellij.ui.dsl.builder.bindText +import com.intellij.util.IncorrectOperationException +import kotlinx.coroutines.coroutineScope + +class QuiltPlatformStep( + parent: ModPlatformStep, +) : AbstractLatentStep>(parent) { + override val description = "download Quilt versions" + + override suspend fun computeData() = coroutineScope { + val quiltVersions = asyncIO { QuiltVersions.downloadData() } + val quiltedFabricApiVersions = asyncIO { QuiltStandardLibrariesVersions.downloadData() } + quiltVersions.await()?.let { a -> quiltedFabricApiVersions.await()?.let { b -> a to b } } + } + + override fun createStep(data: Pair): NewProjectWizardStep { + val (quiltVersions, apiVersions) = data + return QuiltVersionChainStep(this, quiltVersions, apiVersions) + .nextStep(::QuiltEnvironmentStep) + .nextStep(::UseMixinsStep) + .nextStep(::ModNameStep) + .nextStep(::LicenseStep) + .nextStep(::QuiltOptionalSettingsStep) + .nextStep(::QuiltBuildSystemStep) + .nextStep(::QuiltDumbModeFilesStep) + .nextStep(::QuiltPostBuildSystemStep) + .nextStep(::WaitForSmartModeStep) + .nextStep(::QuiltSmartModeFilesStep) + } + + class Factory : ModPlatformStep.Factory { + override val name = "Quilt" + override fun createStep(parent: ModPlatformStep) = QuiltPlatformStep(parent) + } +} + +class QuiltVersionChainStep( + parent: NewProjectWizardStep, + private val quiltVersions: QuiltVersions, + private val apiVersions: QuiltStandardLibrariesVersions, +) : AbstractMcVersionChainStep(parent, "Loader Version:", "Quilt Mappings Version:", "QFAPI/QSL Version:") { + companion object { + private const val LOADER_VERSION = 1 + private const val QUILT_MAPPINGS_VERSION = 2 + private const val QFAPI_VERSION = 3 + + val MC_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.mcVersion") + val LOADER_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.loaderVersion") + val QUILT_MAPPINGS_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.quiltVersion") + val API_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.qfapiVersion") + val OFFICIAL_MAPPINGS_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.officialMappings") + } + + private val showSnapshotsProperty = propertyGraph.property(false) + .bindBooleanStorage("${javaClass.name}.showSnapshots") + private var showSnapshots by showSnapshotsProperty + + private val useApiProperty = propertyGraph.property(true) + .bindBooleanStorage("${javaClass.name}.useApi") + private var useApi by useApiProperty + + private val useOfficialMappingsProperty = propertyGraph.property(false) + .bindBooleanStorage("${javaClass.name}.useOfficialMappings") + private var useOfficialMappings by useOfficialMappingsProperty + + init { + showSnapshotsProperty.afterChange { updateVersionBox() } + } + + private val mcVersions by lazy { + quiltVersions.game.mapIndexed { index, version -> + QuiltMcVersion(quiltVersions.game.size - 1 - index, version.version, version.stable) + } + } + + override fun createComboBox(row: Row, index: Int, items: List>): Cell { + return when (index) { + MINECRAFT_VERSION -> { + val comboBox = super.createComboBox(row, index, items) + row.checkBox("Show snapshots").bindSelected(showSnapshotsProperty) + comboBox + } + QUILT_MAPPINGS_VERSION -> { + val comboBox = super.createComboBox(row, index, items).bindEnabled(useOfficialMappingsProperty.not()) + row.checkBox("Use Official Mappings").bindSelected(useOfficialMappingsProperty) + row.label(EMPTY_LABEL).bindText( + getVersionProperty(MINECRAFT_VERSION).transform { mcVersion -> + mcVersion as QuiltMcVersion + val matched = quiltVersions.mappings.any { it.gameVersion == mcVersion.version } + if (matched) { + EMPTY_LABEL + } else { + "Unable to match Quilt Mappings versions to Minecraft version" + } + }, + ).bindEnabled(useOfficialMappingsProperty.not()).component.foreground = JBColor.YELLOW + comboBox + } + QFAPI_VERSION -> { + val comboBox = super.createComboBox(row, index, items).bindEnabled(useApiProperty) + row.checkBox("Use Quilted Fabric API").bindSelected(useApiProperty) + row.label(EMPTY_LABEL).bindText( + getVersionProperty(MINECRAFT_VERSION).transform { mcVersion -> + mcVersion as QuiltMcVersion + val matched = apiVersions.versions.any { mcVersion.version in it.gameVersions } + if (matched) { + EMPTY_LABEL + } else { + "Unable to match QFAPI/QSL versions to Minecraft version" + } + }, + ).bindEnabled(useApiProperty).component.foreground = JBColor.YELLOW + comboBox + } + else -> super.createComboBox(row, index, items) + } + } + + override fun getAvailableVersions(versionsAbove: List>): List> { + return when (versionsAbove.size) { + MINECRAFT_VERSION -> mcVersions + LOADER_VERSION -> quiltVersions.loader + QUILT_MAPPINGS_VERSION -> { + val mcVersion = versionsAbove[MINECRAFT_VERSION] as QuiltMcVersion + val filteredVersions = quiltVersions.mappings.mapNotNull { mapping -> + mapping.version.takeIf { mapping.gameVersion == mcVersion.version } + } + filteredVersions.ifEmpty { quiltVersions.mappings.map { it.version } } + } + QFAPI_VERSION -> { + val mcVersion = versionsAbove[MINECRAFT_VERSION] as QuiltMcVersion + val filteredVersions = apiVersions.versions.mapNotNull { api -> + api.version.takeIf { mcVersion.version in api.gameVersions } + } + filteredVersions.ifEmpty { apiVersions.versions.map { it.version } } + } + else -> throw IncorrectOperationException() + } + } + + override fun setupUI(builder: Panel) { + super.setupUI(builder) + if (!showSnapshots) { + updateVersionBox() + } + } + + private fun updateVersionBox() { + val versionBox = getVersionBox(MINECRAFT_VERSION) ?: return + val selectedItem = versionBox.selectedItem + versionBox.setSelectableItems(mcVersions.filter { gameVer -> showSnapshots || gameVer.stable }) + versionBox.selectedItem = selectedItem + } + + override fun setupProject(project: Project) { + super.setupProject(project) + data.putUserData(MC_VERSION_KEY, (getVersion(MINECRAFT_VERSION) as QuiltMcVersion).version) + data.putUserData(LOADER_VERSION_KEY, getVersion(LOADER_VERSION) as SemanticVersion) + data.putUserData(QUILT_MAPPINGS_VERSION_KEY, (getVersion(QUILT_MAPPINGS_VERSION) as QuiltVersions.QuiltMappingsVersion).name) + if (useApi) { + data.putUserData(API_VERSION_KEY, getVersion(QFAPI_VERSION) as SemanticVersion) + } + data.putUserData(OFFICIAL_MAPPINGS_KEY, useOfficialMappings) + } +} + +class QuiltEnvironmentStep(parent: NewProjectWizardStep) : AbstractNewProjectWizardStep(parent) { + private val environmentProperty = propertyGraph.property(Side.NONE) + init { + environmentProperty.transform(Side::name, Side::valueOf).bindStorage("${javaClass.name}.side") + } + private var environment by environmentProperty + + override fun setupUI(builder: Panel) { + with(builder) { + row("Environment:") { + comboBox(listOf("Both", "Client", "Server")) + .bindItem( + environmentProperty.transform({ + when (it) { + Side.CLIENT -> "Client" + Side.SERVER -> "Server" + else -> "Both" + } + }, { + when (it) { + "Client" -> Side.CLIENT + "Server" -> Side.SERVER + else -> Side.NONE + } + },), + ) + } + } + } + + override fun setupProject(project: Project) { + data.putUserData(KEY, environment) + } + + companion object { + val KEY = Key.create("${QuiltEnvironmentStep::class.java.name}.environment") + } +} + +class QuiltOptionalSettingsStep(parent: NewProjectWizardStep) : AbstractCollapsibleStep(parent) { + override val title = "Optional Settings" + + override fun createStep() = DescriptionStep(this) + .nextStep(::QuiltAuthorsStep) + .nextStep(::WebsiteStep) + .nextStep(::RepositoryStep) + .nextStep(::IssueTrackerStep) +} + +class QuiltAuthorsStep(parent: NewProjectWizardStep) : AbstractOptionalStringBasedOnProjectNameStep(parent) { + override val label = "Authors:" + override val bindToStorage = true + + init { + value = "${LocalUserSettings.userName}:Owner" + } + + override fun setupProject(project: Project) { + data.putUserData(KEY, parseAuthors(value)) + } + + companion object { + val KEY = Key.create>>("${QuiltAuthorsStep::class.java.name}.authors") + + private val braceRegex = Regex("[{}]") + private val commaRegex = Regex("\\s*,\\s*") + private val colonRegex = Regex("\\s*:\\s*") + + fun parseAuthors(string: String): List> { + return if (string.isNotBlank()) { + string.trim() + .replace(braceRegex, "") + .split(commaRegex) + .map { it.split(colonRegex) } + .map { it[0] to it[1] } + } else { + emptyList() + } + } + } +} diff --git a/src/main/kotlin/platform/quilt/framework/QuiltLibraryKind.kt b/src/main/kotlin/platform/quilt/framework/QuiltLibraryKind.kt new file mode 100644 index 000000000..6ae0df3ba --- /dev/null +++ b/src/main/kotlin/platform/quilt/framework/QuiltLibraryKind.kt @@ -0,0 +1,16 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.framework + +import com.demonwav.mcdev.util.libraryKind +import com.intellij.openapi.roots.libraries.LibraryKind + +val QUILT_LIBRARY_KIND: LibraryKind = libraryKind("quilt-library") diff --git a/src/main/kotlin/platform/quilt/framework/QuiltPresentationProvider.kt b/src/main/kotlin/platform/quilt/framework/QuiltPresentationProvider.kt new file mode 100644 index 000000000..2db3f0241 --- /dev/null +++ b/src/main/kotlin/platform/quilt/framework/QuiltPresentationProvider.kt @@ -0,0 +1,40 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.framework + +import com.demonwav.mcdev.asset.PlatformAssets +import com.demonwav.mcdev.util.localFile +import com.intellij.framework.library.LibraryVersionProperties +import com.intellij.openapi.roots.libraries.LibraryPresentationProvider +import com.intellij.openapi.vfs.VirtualFile +import java.util.jar.JarFile + +class QuiltPresentationProvider : LibraryPresentationProvider(QUILT_LIBRARY_KIND) { + + override fun getIcon(properties: LibraryVersionProperties?) = PlatformAssets.QUILT_ICON + + override fun detect(classesRoots: MutableList): LibraryVersionProperties? { + for (classesRoot in classesRoots) { + if (classesRoot.name.endsWith(".jar")) { + runCatching { + val jar = JarFile(classesRoot.localFile) + val isQuiltLib = jar.entries().asSequence().any { + it.name == "org/quiltmc/loader/api/QuiltLoader.class" + } + if (isQuiltLib) { + return LibraryVersionProperties() + } + } + } + } + return null + } +} diff --git a/src/main/kotlin/platform/quilt/inspection/UnresolvedReferenceInspection.kt b/src/main/kotlin/platform/quilt/inspection/UnresolvedReferenceInspection.kt new file mode 100644 index 000000000..75ec5a8cf --- /dev/null +++ b/src/main/kotlin/platform/quilt/inspection/UnresolvedReferenceInspection.kt @@ -0,0 +1,62 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.inspection + +import com.demonwav.mcdev.platform.quilt.util.QuiltConstants +import com.demonwav.mcdev.util.reference.InspectionReference +import com.intellij.codeInspection.InspectionManager +import com.intellij.codeInspection.LocalInspectionTool +import com.intellij.codeInspection.ProblemDescriptor +import com.intellij.codeInspection.ProblemHighlightType +import com.intellij.codeInspection.ProblemsHolder +import com.intellij.json.psi.JsonElementVisitor +import com.intellij.json.psi.JsonStringLiteral +import com.intellij.psi.PsiElementVisitor +import com.intellij.psi.PsiFile + +class UnresolvedReferenceInspection : LocalInspectionTool() { + + override fun getStaticDescription() = "Reports unresolved references in Quilt mod JSON files." + + override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor { + if (holder.file.name == QuiltConstants.QUILT_MOD_JSON) { + return Visitor(holder) + } + return PsiElementVisitor.EMPTY_VISITOR + } + + override fun processFile(file: PsiFile, manager: InspectionManager): List { + if (file.name == QuiltConstants.QUILT_MOD_JSON) { + return super.processFile(file, manager) + } + return emptyList() + } + + private class Visitor(private val holder: ProblemsHolder) : JsonElementVisitor() { + + override fun visitStringLiteral(literal: JsonStringLiteral) { + for (reference in literal.references) { + if (reference !is InspectionReference) { + continue + } + + if (reference.unresolved) { + holder.registerProblem( + literal, + "Cannot resolve ${reference.description}".format(reference.canonicalText), + ProblemHighlightType.LIKE_UNKNOWN_SYMBOL, + reference.rangeInElement, + ) + } + } + } + } +} diff --git a/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt new file mode 100644 index 000000000..54e806d99 --- /dev/null +++ b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt @@ -0,0 +1,67 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.reference + +import com.demonwav.mcdev.platform.fabric.reference.EntryPointReference +import com.demonwav.mcdev.platform.fabric.reference.LicenseReference +import com.demonwav.mcdev.platform.fabric.reference.ResourceFileReference +import com.demonwav.mcdev.platform.quilt.util.QuiltConstants +import com.demonwav.mcdev.util.isPropertyValue +import com.intellij.json.psi.* +import com.intellij.patterns.PatternCondition +import com.intellij.patterns.PlatformPatterns +import com.intellij.psi.PsiReferenceContributor +import com.intellij.psi.PsiReferenceRegistrar +import com.intellij.util.ProcessingContext +import org.jetbrains.kotlin.idea.completion.or + + +class QuiltReferenceContributor : PsiReferenceContributor() { + override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) { + val stringInModJson = PlatformPatterns.psiElement(JsonStringLiteral::class.java) + .inVirtualFile(PlatformPatterns.virtualFile().withName(QuiltConstants.QUILT_MOD_JSON)) + + val entryPointPattern = stringInModJson.withParent( + PlatformPatterns.psiElement(JsonArray::class.java) + .withSuperParent( + 2, + PlatformPatterns.psiElement(JsonObject::class.java).isPropertyValue("entrypoints"), + ), + ) or stringInModJson.withSuperParent(2, PlatformPatterns.psiElement(JsonObject::class.java).isPropertyValue("entrypoints")) + + registrar.registerReferenceProvider(entryPointPattern, EntryPointReference) + + val mixinConfigPattern = stringInModJson.withParent( + PlatformPatterns.psiElement(JsonArray::class.java).isPropertyValue("mixin"), + ) or stringInModJson.with( + object : PatternCondition("isPropertyValue") { + override fun accepts(t: JsonElement, context: ProcessingContext?): Boolean { + val parent = t.parent as? JsonProperty ?: return false + return parent.value == t && parent.name == "mixin" + } + } + ) + + registrar.registerReferenceProvider(mixinConfigPattern, ResourceFileReference("mixin config '%s'")) + + registrar.registerReferenceProvider( + stringInModJson.isPropertyValue("access_widener"), + ResourceFileReference("access widener '%s'"), + ) + + registrar.registerReferenceProvider( + stringInModJson.isPropertyValue("icon"), + ResourceFileReference("icon '%s'"), + ) + + registrar.registerReferenceProvider(stringInModJson.isPropertyValue("license"), LicenseReference) + } +} diff --git a/src/main/kotlin/platform/quilt/util/QuiltConstants.kt b/src/main/kotlin/platform/quilt/util/QuiltConstants.kt new file mode 100644 index 000000000..badb3c0ec --- /dev/null +++ b/src/main/kotlin/platform/quilt/util/QuiltConstants.kt @@ -0,0 +1,19 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.platform.quilt.util + +object QuiltConstants { + + const val QUILT_MOD_JSON = "quilt.mod.json" + + const val MOD_INITIALIZER = "org.quiltmc.qsl.base.api.entrypoint.ModInitializer" + const val CLIENT_MOD_INITIALIZER = "org.quiltmc.qsl.base.api.entrypoint.client.ClientModInitializer" +} diff --git a/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt new file mode 100644 index 000000000..745b482f5 --- /dev/null +++ b/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt @@ -0,0 +1,68 @@ +package com.demonwav.mcdev.platform.quilt.util + +import com.demonwav.mcdev.creator.selectProxy +import com.demonwav.mcdev.update.PluginUtil +import com.demonwav.mcdev.util.SemanticVersion +import com.github.kittinunf.fuel.core.FuelManager +import com.github.kittinunf.fuel.core.requests.suspendable +import com.google.gson.JsonParser +import com.google.gson.JsonSyntaxException +import com.intellij.openapi.diagnostic.logger +import java.io.IOException + +private val LOGGER = logger() + +class QuiltStandardLibrariesVersions(val versions: List) { + class Version(val gameVersions: List, val version: SemanticVersion) + + companion object { + suspend fun downloadData(): QuiltStandardLibrariesVersions? { + try { + val url = "https://api.modrinth.com/v2/project/qvIfYCYJ/version" + val manager = FuelManager() + manager.proxy = selectProxy(url) + + val response = manager.get(url) + .header("User-Agent", PluginUtil.useragent) + .suspendable() + .await() + + val versions = mutableListOf() + response.body().toStream().use { stream -> + val json = JsonParser.parseReader(stream.reader())?.asJsonArray ?: return null + versionLoop@ + for (ver in json) { + val version = ver?.asJsonObject ?: return null + val files = version["files"]?.asJsonArray ?: return null + for (file in files) { + val fileObj = file?.asJsonObject ?: return null + val filename = fileObj["filename"]?.asString ?: return null + if (!filename.startsWith("qfapi")) { + continue@versionLoop + } + } + val versionNumber = version["version_number"]?.asString?.let(SemanticVersion.Companion::tryParse) + ?: return null + val gameVersions = version["game_versions"]?.asJsonArray ?: return null + val gameVersionsList = mutableListOf() + for (gameVer in gameVersions) { + val gameVersion = gameVer?.asString ?: return null + gameVersionsList += gameVersion + } + versions += Version(gameVersionsList, versionNumber) + } + } + return QuiltStandardLibrariesVersions(versions) + } catch (e: IOException) { + LOGGER.error(e) + } catch (e: JsonSyntaxException) { + LOGGER.error(e) + } catch (e: IllegalStateException) { + LOGGER.error(e) + } catch (e: UnsupportedOperationException) { + LOGGER.error(e) + } + return null + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt new file mode 100644 index 000000000..5812c5ec0 --- /dev/null +++ b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt @@ -0,0 +1,79 @@ +package com.demonwav.mcdev.platform.quilt.util + +import com.demonwav.mcdev.creator.selectProxy +import com.demonwav.mcdev.update.PluginUtil +import com.demonwav.mcdev.util.SemanticVersion +import com.github.kittinunf.fuel.core.FuelManager +import com.github.kittinunf.fuel.core.requests.suspendable +import com.google.gson.JsonParser +import com.google.gson.JsonSyntaxException +import com.intellij.openapi.diagnostic.logger +import java.io.IOException + +private val LOGGER = logger() + +class QuiltVersions(val game: List, val mappings: List, val loader: List) { + class Game(val version: String, val stable: Boolean) + class Mappings(val gameVersion: String, val version: QuiltMappingsVersion) + + class QuiltMappingsVersion(val name: String, val build: Int) : Comparable { + override fun toString() = name + override fun compareTo(other: QuiltMappingsVersion) = build.compareTo(other.build) + } + + companion object { + suspend fun downloadData(): QuiltVersions? { + try { + val url = "https://meta.quiltmc.org/v3/versions" + val manager = FuelManager() + manager.proxy = selectProxy(url) + + val response = manager.get(url) + .header("User-Agent", PluginUtil.useragent) + .suspendable() + .await() + + val gameList = mutableListOf() + val mappingsList = mutableListOf() + val loaderList = mutableListOf() + response.body().toStream().use { stream -> + val json = JsonParser.parseReader(stream.reader())?.asJsonObject ?: return null + + val game = json["game"]?.asJsonArray ?: return null + for (version in game) { + val versionObj = version?.asJsonObject ?: return null + val gameVer = versionObj["version"]?.asString ?: return null + val stable = versionObj["stable"]?.asBoolean ?: return null + gameList += Game(gameVer, stable) + } + + val mappings = json["mappings"]?.asJsonArray ?: return null + for (mapping in mappings) { + val mappingObj = mapping?.asJsonObject ?: return null + val gameVersion = mappingObj["gameVersion"]?.asString ?: return null + val version = mappingObj["version"]?.asString ?: return null + val build = mappingObj["build"]?.asInt ?: return null + mappingsList += Mappings(gameVersion, QuiltMappingsVersion(version, build)) + } + + val loaders = json["loader"]?.asJsonArray ?: return null + for (loader in loaders) { + val loaderObj = loader?.asJsonObject ?: return null + val version = loaderObj["version"]?.asString?.let(SemanticVersion.Companion::tryParse) ?: return null + loaderList += version + } + } + return QuiltVersions(gameList, mappingsList, loaderList) + } catch (e: IOException) { + LOGGER.error(e) + } catch (e: JsonSyntaxException) { + LOGGER.error(e) + } catch (e: IllegalStateException) { + LOGGER.error(e) + } catch (e: UnsupportedOperationException) { + LOGGER.error(e) + } + return null + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/util/MinecraftTemplates.kt b/src/main/kotlin/util/MinecraftTemplates.kt index bc280a98e..b731a4cc8 100644 --- a/src/main/kotlin/util/MinecraftTemplates.kt +++ b/src/main/kotlin/util/MinecraftTemplates.kt @@ -205,6 +205,13 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory { const val FABRIC_MOD_JSON_TEMPLATE = "fabric_mod.json" const val FABRIC_SETTINGS_GRADLE_TEMPLATE = "fabric_settings.gradle" + const val QUILT_BUILD_GRADLE_TEMPLATE = "quilt_build.gradle" + const val QUILT_GRADLE_PROPERTIES_TEMPLATE = "quilt_gradle.properties" + const val QUILT_MIXINS_JSON_TEMPLATE = "quilt_mixins.json" + const val QUILT_MOD_JSON_TEMPLATE = "quilt_mod.json" + const val QUILT_SETTINGS_GRADLE_TEMPLATE = "quilt_settings.gradle" + const val QUILT_LIBS_VERSIONS_TEMPLATE = "quilt_libs_versions.toml" + const val ARCHITECTURY_BUILD_GRADLE_TEMPLATE = "architectury_build.gradle" const val ARCHITECTURY_GRADLE_PROPERTIES_TEMPLATE = "architectury_gradle.properties" const val ARCHITECTURY_SETTINGS_GRADLE_TEMPLATE = "architectury_settings.gradle" diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 3d2338caa..b3b037937 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -24,7 +24,7 @@ minecraft-dev messages.MinecraftDevelopment @@ -64,6 +64,7 @@ + @@ -84,6 +85,7 @@ + @@ -134,6 +136,7 @@ * Sponge * Forge * Fabric + * Quilt * MCP * Mixin * Velocity @@ -316,6 +319,13 @@ + + + + + + + @@ -325,6 +335,7 @@ + @@ -332,6 +343,7 @@ + @@ -359,6 +371,7 @@ + @@ -597,6 +610,17 @@ implementationClass="com.demonwav.mcdev.platform.fabric.inspection.UnresolvedReferenceInspection"/> + + + + + diff --git a/src/main/resources/assets/icons/platform/Quilt.png b/src/main/resources/assets/icons/platform/Quilt.png new file mode 100644 index 0000000000000000000000000000000000000000..25c5b0f607e47426f103f73762a3ac326a3292ca GIT binary patch literal 442 zcmV;r0Y(0aP)LletO*Q51&%SxCUd!o4sMa6@7c1uJ`PLeTgaR+c`1 z4`5|uWnp8X6PqCT0%k-o3}_KF1BnaD4B|DA$t-g2m=yyP{i}~V^Plsd%RPeUd58@s zHv#Meh$EPE06S$vQ-sN(1u~xnGJ&>5dRpxsg48`n>v#&VlOzI zy5U@{R3RRka4i!eEA=iwGdE(B*;w21Kb+(c^-@3>VC3~liD@@s-ZO@VIbIoF*>SkL~2QEci==9~_cDpJ kk_1018dUUerfg`+H{Ohil5;X9z5oCK07*qoM6N<$f?YbjUjP6A literal 0 HcmV?d00001 diff --git a/src/main/resources/assets/icons/platform/Quilt@2x.png b/src/main/resources/assets/icons/platform/Quilt@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..bf4269552aecf78e0260484fc25d23c2667eab59 GIT binary patch literal 842 zcmV-Q1GW5#P)r~Gynhs{7FPXR9J<@S4~e7K^T6vT?=bjTWf-(kRS;L5)nCoXHqYmBzo7t zFVLfj-uyUwF!g8?|A1(MTx^I(=mE3`8;ORbHbP=U?UIFdw`<@IDyeQ|)FY`%xA_273DBD-`kR5X(AS;Rd z{j(?B^X66t>avEO-2@Ch2iX{dZY)9BoySkS6bfh<0+w*h?e&&37@yNP*mHJ=tT>@i zE;LR`p$D3Ud^G{3&{R&_X#O7p&<-&4FQ+HKuLPe2!Vpkxr}9b_j*1LRLK-RIDCXpL zvYf~*y^NY!Mx~r-kAQM5giJM#f~nf$j`d6_76VcLftpD;qb}8odti17kBV9^wwfj<^cHDB-7t)W@ZO;Mx0j`5V U!kd|BJpcdz07*qoM6N<$g8Nf_vH$=8 literal 0 HcmV?d00001 diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft new file mode 100644 index 000000000..5f8de05c1 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft @@ -0,0 +1,98 @@ +plugins { + id 'maven-publish' + alias libs.plugins.quilt.loom +} + +archivesBaseName = project.archives_base_name +version = "${project.version}+${libs.versions.minecraft.get()}" +group = project.maven_group + +repositories { + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. +} + +// All the dependencies are declared at gradle/libs.version.toml and referenced with "libs." +// See https://docs.gradle.org/current/userguide/platforms.html for information on how version catalogs work. +dependencies { + minecraft libs.minecraft + +#if (${OFFICIAL_MAPPINGS}) + mappings loom.layered { + mappings variantOf(libs.quilt.mappings) { classifier 'intermediary-v2' } + officialMojangMappings() + } +#else + mappings variantOf(libs.quilt.mappings) { classifier 'intermediary-v2' } +#end + modImplementation libs.quilt.loader + +#if (${API_VERSION}) + // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. + // Quilted Fabric API will automatically pull in the correct QSL version. + modImplementation libs.quilted.fabric.api +#end +} + +processResources { + inputs.property 'version', version + inputs.property "minecraft_version", libs.versions.minecraft.get() + inputs.property "loader_version", libs.versions.quilt_loader.get() + filteringCharset "UTF-8" + + filesMatching('quilt.mod.json') { + expand "version": version, + "minecraft_version": libs.versions.minecraft.get(), + "loader_version": libs.versions.quilt_loader.get() + } +} + +def targetJavaVersion = ${JAVA_VERSION} +tasks.withType(JavaCompile).configureEach { + it.options.encoding = 'UTF-8' + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + it.options.release = targetJavaVersion + } +} + +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + // Still required by IDEs such as Eclipse and Visual Studio Code + sourceCompatibility = javaVersion + targetCompatibility = javaVersion + + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() + + // If this mod is going to be a library, then it should also generate Javadocs in order to aid with development. + // Uncomment this line to generate them. + // withJavadocJar() +} + +// If you plan to use a different file for the license, don't forget to change the file name here! +jar { + from('LICENSE') { + rename { "${it}_${archivesBaseName}" } + } +} + +// Configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } +} \ No newline at end of file diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.html new file mode 100644 index 000000000..e22b7be8d --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.html @@ -0,0 +1,15 @@ + + + + +

This is a built-in file template used to create a new build.gradle file for Quilt projects.

+ + diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.ft new file mode 100644 index 000000000..cd2b319fa --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.ft @@ -0,0 +1,10 @@ +# Gradle Properties +org.gradle.jvmargs = -Xmx1G +org.gradle.parallel = true + +# Mod Properties +version = ${VERSION} +maven_group = ${GROUP_ID} +archives_base_name = ${ARTIFACT_ID} + +# Dependencies are managed at gradle/libs.versions.toml \ No newline at end of file diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.html new file mode 100644 index 000000000..5f2ce34a6 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_gradle.properties.html @@ -0,0 +1,15 @@ + + + + +

This is a built-in file template used to create a new gradle.properties file for Quilt projects.

+ + diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft new file mode 100644 index 000000000..c5612614a --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft @@ -0,0 +1,28 @@ +[versions] +# The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html +minecraft = "${MC_VERSION}" +quilt_mappings = "${API_VERSION}" +quilt_loader = "${LOADER_VERSION}" + +#if (${API_VERSION}) +quilted_fabric_api = "${API_VERSION}" +#end + +[libraries] +minecraft = { module = "com.mojang:minecraft", version.ref = "minecraft" } +quilt_mappings = { module = "org.quiltmc:quilt-mappings", version.ref = "quilt_mappings" } +quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loader" } + +#if (${API_VERSION}) +quilted_fabric_api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "quilted_fabric_api" } +quilted_fabric_api_deprecated = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api-deprecated", version.ref = "quilted_fabric_api" } +#end + +# If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". +[bundles] +#if (${API_VERSION}) +quilted_fabric_api = ["quilted_fabric_api", "quilted_fabric_api_deprecated"] +#end + +[plugins] +quilt_loom = { id = "org.quiltmc.loom", version = "${LOOM_VERSION}" } \ No newline at end of file diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html new file mode 100644 index 000000000..ea0cb8786 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html @@ -0,0 +1,5 @@ + + +

This is a built-in file template used to create a new libs.versions.toml file for Quilt projects.

+ + diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.ft new file mode 100644 index 000000000..d248bba23 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.ft @@ -0,0 +1,13 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "${PACKAGE_NAME}", + "compatibilityLevel": "JAVA_${JAVA_VERSION}", + "mixins": [ + ], + "client": [ + ], + "injectors": { + "defaultRequire": 1 + } +} diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.html new file mode 100644 index 000000000..eddf4e479 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mixins.json.html @@ -0,0 +1,15 @@ + + + + +

This is a built-in file template used to create a new modid.mixins.json file for Quilt projects.

+ + diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft new file mode 100644 index 000000000..1e0ba82e9 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft @@ -0,0 +1,39 @@ +#set ( $d = "$" ) +{ + "schema_version": 1, + "quilt_loader": { + "group": "${GROUP_ID}", + "id": "${ARTIFACT_ID}", + "version": "${d}{version}", + "metadata": { + "name": "${MOD_NAME}", + "description": "${MOD_DESCRIPTION}", + "contributors": {}, + "contact": {}, + "icon": "assets/example_mod/icon.png" + }, + "intermediate_mappings": "net.fabricmc:intermediary", + "entrypoints": {}, + "depends": [ + { + "id": "quilt_loader", + "versions": ">=${d}{loader_version}" + }, +#if (${API_VERSION}) + { + "id": "quilted_fabric_api", + "versions": "*" + }, +#end + { + "id": "minecraft", + "versions": "${d}{minecraft_version}" + } + ] + }, +#if (${MIXINS}) + "mixin": [ + "${ARTIFACT_ID}.mixins.json" + ], +#end +} diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.html new file mode 100644 index 000000000..3cf162c30 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.html @@ -0,0 +1,15 @@ + + + + +

This is a built-in file template used to create a new quilt.mod.json for Quilt projects.

+ + diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft new file mode 100644 index 000000000..641fb2bb1 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft @@ -0,0 +1,12 @@ +pluginManagement { + maven { + name = 'Quilt' + url = 'https://maven.quiltmc.org/repository/release' + } + // Currently needed for Intermediary and other temporary dependencies + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() +} diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.html new file mode 100644 index 000000000..c3eaf7c10 --- /dev/null +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.html @@ -0,0 +1,15 @@ + + + + +

This is a built-in file template used to create a new settings.gradle file for Quilt projects.

+ + From fcdc9d673b9a180eb872bc1a983f9af27b5108f0 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 18:01:54 +0200 Subject: [PATCH 02/21] Gradle template fixes --- .../platform/quilt/creator/gradle-steps.kt | 2 +- .../j2ee/quilt/quilt_build.gradle.ft | 4 ++-- .../j2ee/quilt/quilt_libs_versions.toml.ft | 4 +++- .../j2ee/quilt/quilt_settings.gradle.ft | 20 ++++++++++--------- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt index 340c1c0ba..ea89f15da 100644 --- a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -44,7 +44,7 @@ class QuiltGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs val mcVersion = data.getUserData(QuiltVersionChainStep.MC_VERSION_KEY) ?: return val quiltMappingsVersion = data.getUserData(QuiltVersionChainStep.QUILT_MAPPINGS_VERSION_KEY) ?: return val loaderVersion = data.getUserData(QuiltVersionChainStep.LOADER_VERSION_KEY) ?: return - val loomVersion = "1.1-" // TODO + val loomVersion = "1.1.+" // TODO val javaVersion = findStep().preferredJdk.ordinal val apiVersion = data.getUserData(QuiltVersionChainStep.API_VERSION_KEY) val officialMappings = data.getUserData(QuiltVersionChainStep.OFFICIAL_MAPPINGS_KEY) ?: false diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft index 5f8de05c1..6365e3177 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft @@ -40,13 +40,13 @@ dependencies { processResources { inputs.property 'version', version inputs.property "minecraft_version", libs.versions.minecraft.get() - inputs.property "loader_version", libs.versions.quilt_loader.get() + inputs.property "loader_version", libs.versions.quilt.loader.get() filteringCharset "UTF-8" filesMatching('quilt.mod.json') { expand "version": version, "minecraft_version": libs.versions.minecraft.get(), - "loader_version": libs.versions.quilt_loader.get() + "loader_version": libs.versions.quilt.loader.get() } } diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft index c5612614a..36d4ae102 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft @@ -1,7 +1,9 @@ [versions] # The latest versions are available at https://lambdaurora.dev/tools/import_quilt.html minecraft = "${MC_VERSION}" -quilt_mappings = "${API_VERSION}" +#if (!${OFFICIAL_MAPPINGS}) +quilt_mappings = "${QUILT_MAPPINGS}" +#end quilt_loader = "${LOADER_VERSION}" #if (${API_VERSION}) diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft index 641fb2bb1..1ffcce318 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_settings.gradle.ft @@ -1,12 +1,14 @@ pluginManagement { - maven { - name = 'Quilt' - url = 'https://maven.quiltmc.org/repository/release' + repositories { + maven { + name = 'Quilt' + url = 'https://maven.quiltmc.org/repository/release' + } + // Currently needed for Intermediary and other temporary dependencies + maven { + name = 'Fabric' + url = 'https://maven.fabricmc.net/' + } + gradlePluginPortal() } - // Currently needed for Intermediary and other temporary dependencies - maven { - name = 'Fabric' - url = 'https://maven.fabricmc.net/' - } - gradlePluginPortal() } From a6ebe7b40f33e3aa58c9327fda794337095ca38e Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:09:57 +0200 Subject: [PATCH 03/21] Properly add Quilt to Facet editor --- .../kotlin/facet/MinecraftFacetEditorTab.form | 115 +++++++++++------- .../kotlin/facet/MinecraftFacetEditorTab.kt | 30 ++++- 2 files changed, 100 insertions(+), 45 deletions(-) diff --git a/src/main/kotlin/facet/MinecraftFacetEditorTab.form b/src/main/kotlin/facet/MinecraftFacetEditorTab.form index 9fee0bde1..4cc9e4fc6 100644 --- a/src/main/kotlin/facet/MinecraftFacetEditorTab.form +++ b/src/main/kotlin/facet/MinecraftFacetEditorTab.form @@ -1,9 +1,9 @@
- + - + @@ -68,7 +68,7 @@ - + @@ -77,7 +77,7 @@ - + @@ -86,7 +86,7 @@ - + @@ -95,7 +95,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -152,7 +152,7 @@ - + @@ -160,7 +160,7 @@ - + @@ -168,7 +168,7 @@ - + @@ -240,7 +240,7 @@ - + @@ -249,7 +249,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -269,7 +269,7 @@ - + @@ -324,7 +324,7 @@ - + @@ -333,7 +333,7 @@ - + @@ -342,7 +342,7 @@ - + @@ -351,7 +351,7 @@ - + @@ -360,7 +360,7 @@ - + @@ -368,7 +368,7 @@ - + @@ -376,7 +376,7 @@ - + @@ -385,7 +385,7 @@ - + @@ -394,7 +394,7 @@ - + @@ -403,7 +403,7 @@ - + @@ -412,7 +412,7 @@ - + @@ -421,7 +421,7 @@ - + @@ -463,7 +463,7 @@ - + @@ -472,12 +472,12 @@ - + - + @@ -485,40 +485,65 @@ - + - + - + - + - + - + + + + + + + + + - - + - + - + - + + + + + + + + + + + + + + + + + + + @@ -526,7 +551,7 @@ - + @@ -534,6 +559,14 @@ + + + + + + + + diff --git a/src/main/kotlin/facet/MinecraftFacetEditorTab.kt b/src/main/kotlin/facet/MinecraftFacetEditorTab.kt index 5396fe105..05cd983a6 100644 --- a/src/main/kotlin/facet/MinecraftFacetEditorTab.kt +++ b/src/main/kotlin/facet/MinecraftFacetEditorTab.kt @@ -35,6 +35,8 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura private lateinit var forgeAutoCheckBox: JCheckBox private lateinit var fabricEnabledCheckBox: JCheckBox private lateinit var fabricAutoCheckBox: JCheckBox + private lateinit var quiltEnabledCheckBox: JCheckBox + private lateinit var quiltAutoCheckBox: JCheckBox private lateinit var architecturyEnabledCheckBox: JCheckBox private lateinit var architecturyAutoCheckBox: JCheckBox private lateinit var liteloaderEnabledCheckBox: JCheckBox @@ -64,6 +66,7 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura spongeEnabledCheckBox, forgeEnabledCheckBox, fabricEnabledCheckBox, + quiltEnabledCheckBox, architecturyEnabledCheckBox, liteloaderEnabledCheckBox, mcpEnabledCheckBox, @@ -83,6 +86,7 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura spongeAutoCheckBox, forgeAutoCheckBox, fabricAutoCheckBox, + quiltAutoCheckBox, architecturyAutoCheckBox, liteloaderAutoCheckBox, mcpAutoCheckBox, @@ -154,31 +158,47 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura also(fabricEnabledCheckBox, mixinEnabledCheckBox, mcpEnabledCheckBox) unique(fabricEnabledCheckBox, architecturyEnabledCheckBox) } + quiltEnabledCheckBox.addActionListener { + also(quiltEnabledCheckBox, fabricEnabledCheckBox, mixinEnabledCheckBox, mcpEnabledCheckBox) + unique(quiltEnabledCheckBox, architecturyEnabledCheckBox) + } architecturyEnabledCheckBox.addActionListener { unique( architecturyEnabledCheckBox, fabricEnabledCheckBox, + quiltEnabledCheckBox, forgeEnabledCheckBox, ) } forgeAutoCheckBox.addActionListener { - all(forgeAutoCheckBox, fabricAutoCheckBox, architecturyAutoCheckBox)( + all(forgeAutoCheckBox, fabricAutoCheckBox, quiltAutoCheckBox, architecturyAutoCheckBox)( FABRIC, + QUILT, ARCHITECTURY, ) } fabricAutoCheckBox.addActionListener { - all(fabricAutoCheckBox, forgeAutoCheckBox, architecturyAutoCheckBox)( + all(fabricAutoCheckBox, quiltAutoCheckBox, forgeAutoCheckBox, architecturyAutoCheckBox)( FORGE, + QUILT, + ARCHITECTURY, + ) + } + + quiltAutoCheckBox.addActionListener { + all(quiltAutoCheckBox, fabricAutoCheckBox, forgeAutoCheckBox, architecturyAutoCheckBox)( + FORGE, + FABRIC, ARCHITECTURY, ) } architecturyAutoCheckBox.addActionListener { - all(architecturyAutoCheckBox, forgeAutoCheckBox, fabricAutoCheckBox)( + all(architecturyAutoCheckBox, forgeAutoCheckBox, fabricAutoCheckBox, quiltAutoCheckBox)( FORGE, + QUILT, FABRIC, ) } @@ -305,7 +325,8 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura private const val SPONGE = PAPER + 1 private const val FORGE = SPONGE + 1 private const val FABRIC = FORGE + 1 - private const val ARCHITECTURY = FABRIC + 1 + private const val QUILT = FABRIC + 1 + private const val ARCHITECTURY = QUILT + 1 private const val MCP = ARCHITECTURY + 1 private const val MIXIN = MCP + 1 private const val BUNGEECORD = MIXIN + 1 @@ -337,6 +358,7 @@ class MinecraftFacetEditorTab(private val configuration: MinecraftFacetConfigura SPONGE, FORGE, FABRIC, + QUILT, ARCHITECTURY, MCP, MIXIN, From f52bf80079555abc4ac817f795dcae81a108d833 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:10:11 +0200 Subject: [PATCH 04/21] Add Templates to template editor --- src/main/kotlin/util/MinecraftTemplates.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/util/MinecraftTemplates.kt b/src/main/kotlin/util/MinecraftTemplates.kt index b731a4cc8..823cca2ab 100644 --- a/src/main/kotlin/util/MinecraftTemplates.kt +++ b/src/main/kotlin/util/MinecraftTemplates.kt @@ -89,6 +89,18 @@ class MinecraftTemplates : FileTemplateGroupDescriptorFactory { fabricGroup.addTemplate(FileTemplateDescriptor(FABRIC_SETTINGS_GRADLE_TEMPLATE, PlatformAssets.FABRIC_ICON)) } + FileTemplateGroupDescriptor("Quilt", PlatformAssets.QUILT_ICON).let { quiltGroup -> + group.addTemplate(quiltGroup) + quiltGroup.addTemplate(FileTemplateDescriptor(QUILT_LIBS_VERSIONS_TEMPLATE, PlatformAssets.QUILT_ICON)) + quiltGroup.addTemplate(FileTemplateDescriptor(QUILT_BUILD_GRADLE_TEMPLATE, PlatformAssets.QUILT_ICON)) + quiltGroup.addTemplate( + FileTemplateDescriptor(QUILT_GRADLE_PROPERTIES_TEMPLATE, PlatformAssets.QUILT_ICON), + ) + quiltGroup.addTemplate(FileTemplateDescriptor(QUILT_MIXINS_JSON_TEMPLATE, PlatformAssets.QUILT_ICON)) + quiltGroup.addTemplate(FileTemplateDescriptor(QUILT_MOD_JSON_TEMPLATE, PlatformAssets.QUILT_ICON)) + quiltGroup.addTemplate(FileTemplateDescriptor(QUILT_SETTINGS_GRADLE_TEMPLATE, PlatformAssets.QUILT_ICON)) + } + FileTemplateGroupDescriptor("LiteLoader", PlatformAssets.LITELOADER_ICON).let { liteGroup -> group.addTemplate(liteGroup) liteGroup.addTemplate(FileTemplateDescriptor(LITELOADER_MAIN_CLASS_TEMPLATE)) From 4f48c2f2dee79766319cf3a13898208749d66396 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:10:35 +0200 Subject: [PATCH 05/21] Fix generated qmj --- src/main/kotlin/platform/quilt/creator/asset-steps.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index 0c6d83df0..93d5cf2f2 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -107,12 +107,13 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin val mainClassName = "$packageName.${modName.toJavaClassName()}" val clientClassName = "$packageName.client.${modName.toJavaClassName()}Client" entryPoints = listOf( - EntryPoint("main", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), - EntryPoint("client", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), + EntryPoint("init", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), + EntryPoint("client_init", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), ) // TODO: un-hardcode? assets.addTemplateProperties( "ARTIFACT_ID" to buildSystemProps.artifactId, + "GROUP_ID" to buildSystemProps.groupId, "MOD_NAME" to StringUtil.escapeStringCharacters(modName), "MOD_DESCRIPTION" to StringUtil.escapeStringCharacters(description), "MOD_ENVIRONMENT" to envName, From 5810f9ad237e2d858616596a30213e4b3e691745 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:13:58 +0200 Subject: [PATCH 06/21] Dont generate client Entry Point on Server-Only mods --- .../kotlin/platform/quilt/creator/asset-steps.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index 93d5cf2f2..52af9c1c6 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -106,10 +106,15 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}" val mainClassName = "$packageName.${modName.toJavaClassName()}" val clientClassName = "$packageName.client.${modName.toJavaClassName()}Client" - entryPoints = listOf( - EntryPoint("init", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), - EntryPoint("client_init", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), - ) // TODO: un-hardcode? + entryPoints = when (data.getUserData(QuiltEnvironmentStep.KEY) ?: Side.NONE) { + Side.SERVER -> listOf( + EntryPoint("init", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), + ) + else -> listOf( + EntryPoint("init", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), + EntryPoint("client_init", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), + ) + } // TODO: un-hardcode? assets.addTemplateProperties( "ARTIFACT_ID" to buildSystemProps.artifactId, From d8e7fd218c09e9bd5581659178be6f7cadb2d333 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:28:54 +0200 Subject: [PATCH 07/21] Fix environment information in QMJ --- src/main/kotlin/platform/quilt/creator/asset-steps.kt | 2 +- src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index 52af9c1c6..eb5a54669 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -93,7 +93,7 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin val description = data.getUserData(DescriptionStep.KEY) ?: "" val envName = when (data.getUserData(QuiltEnvironmentStep.KEY) ?: Side.NONE) { Side.CLIENT -> "client" - Side.SERVER -> "server" + Side.SERVER -> "dedicated_server" else -> "*" } val loaderVersion = data.getUserData(QuiltVersionChainStep.LOADER_VERSION_KEY) ?: return diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft index 1e0ba82e9..e5bffc874 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft @@ -36,4 +36,7 @@ "${ARTIFACT_ID}.mixins.json" ], #end + "minecraft": { + "environment": "${MOD_ENVIRONMENT}" + } } From 3fa28cfb1d13fe9769c7a8a8b57487bd2c37623a Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Mon, 27 Mar 2023 22:00:25 +0200 Subject: [PATCH 08/21] Fix entrypoint name detected as name listener --- .../quilt/reference/QuiltReferenceContributor.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt index 54e806d99..7c90810cf 100644 --- a/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt +++ b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt @@ -35,7 +35,16 @@ class QuiltReferenceContributor : PsiReferenceContributor() { 2, PlatformPatterns.psiElement(JsonObject::class.java).isPropertyValue("entrypoints"), ), - ) or stringInModJson.withSuperParent(2, PlatformPatterns.psiElement(JsonObject::class.java).isPropertyValue("entrypoints")) + ) or stringInModJson + .withSuperParent(2, PlatformPatterns.psiElement(JsonObject::class.java).isPropertyValue("entrypoints")) + .with( + object : PatternCondition("isNotPropertyName") { + override fun accepts(t: JsonElement, context: ProcessingContext?): Boolean { + val parent = t.parent as? JsonProperty ?: return false + return parent.nameElement != t + } + } + ) registrar.registerReferenceProvider(entryPointPattern, EntryPointReference) From be2ecc518a4765ce4afb825e16da4f7c976c0d3c Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:00:27 +0200 Subject: [PATCH 09/21] QMJ template fix: use artifact id in mod icon path --- src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft index e5bffc874..dcc2e6258 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_mod.json.ft @@ -10,7 +10,7 @@ "description": "${MOD_DESCRIPTION}", "contributors": {}, "contact": {}, - "icon": "assets/example_mod/icon.png" + "icon": "assets/${ARTIFACT_ID}/icon.png" }, "intermediate_mappings": "net.fabricmc:intermediary", "entrypoints": {}, From 76f9ac1efd537908aa9d3ab6c0cee02dad636f19 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:02:30 +0200 Subject: [PATCH 10/21] Temp fix: remove gradle wrapper step to avoid sync and wrapper running at the same time, resulting in one of them failing sometimes --- src/main/kotlin/platform/quilt/creator/gradle-steps.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt index ea89f15da..de23f2a6b 100644 --- a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -18,7 +18,6 @@ import com.demonwav.mcdev.creator.buildsystem.* import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep -import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep import com.demonwav.mcdev.util.MinecraftTemplates import com.demonwav.mcdev.util.SemanticVersion import com.intellij.ide.wizard.NewProjectWizardStep @@ -29,7 +28,7 @@ class QuiltGradleSupport : BuildSystemSupport { override fun createStep(step: String, parent: NewProjectWizardStep): NewProjectWizardStep { return when (step) { - BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent).nextStep(::GradleWrapperStep) + BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent) // TODO: Read fixed version of Gradle Wrapper Step BuildSystemSupport.POST_STEP -> GradleImportStep(parent) else -> EmptyStep(parent) } From 2a958a34364074da4e77cbe3870db3848b6794fa Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:22:16 +0200 Subject: [PATCH 11/21] Fix: metadata is now properly filled --- .../kotlin/platform/quilt/creator/asset-steps.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index eb5a54669..53286a49d 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -153,9 +153,9 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin val generator = JsonElementGenerator(project) jsonFile.runWriteAction { - ((json.findProperty("quilt_loader")?.value as? JsonObject) - ?.findProperty("metadata") as? JsonObject) - ?.findProperty("contributors") + val quiltLoaderProperty = json.findProperty("quilt_loader")?.value as? JsonObject + val metadataProperty = quiltLoaderProperty?.findProperty("metadata")?.value as? JsonObject + (metadataProperty?.findProperty("contributors")?.value as? JsonObject) ?.let { authorsObject -> for (i in authors.indices) { if (i != 0) { @@ -167,9 +167,7 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin } } - ((json.findProperty("quilt_loader")?.value as? JsonObject) - ?.findProperty("metadata") as? JsonObject) - ?.findProperty("contact") + (metadataProperty?.findProperty("contact")?.value as? JsonObject) ?.let { contactObject -> val properties = mutableListOf>() if (!website.isNullOrBlank()) { @@ -191,8 +189,7 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin } } - ((json.findProperty("quilt_loader")?.value as? JsonObject) - ?.findProperty("entrypoints")?.value as? JsonObject) + (quiltLoaderProperty?.findProperty("entrypoints")?.value as? JsonObject) ?.let { entryPointsObject -> val entryPointsByCategory = entryPoints .groupBy { it.category } From 76a1ad2f4f071ba8685ac29af0cb23e79a954bb5 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 22:36:08 +0200 Subject: [PATCH 12/21] Fix formatting --- .../platform/quilt/creator/asset-steps.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index 53286a49d..eb8bfce69 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -19,7 +19,14 @@ import com.demonwav.mcdev.creator.buildsystem.AbstractRunBuildSystemStep import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport import com.demonwav.mcdev.creator.findStep -import com.demonwav.mcdev.creator.step.* +import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.AbstractModNameStep +import com.demonwav.mcdev.creator.step.DescriptionStep +import com.demonwav.mcdev.creator.step.IssueTrackerStep +import com.demonwav.mcdev.creator.step.LicenseStep +import com.demonwav.mcdev.creator.step.RepositoryStep +import com.demonwav.mcdev.creator.step.UseMixinsStep +import com.demonwav.mcdev.creator.step.WebsiteStep import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side import com.demonwav.mcdev.platform.quilt.EntryPoint import com.demonwav.mcdev.platform.quilt.util.QuiltConstants @@ -112,9 +119,14 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin ) else -> listOf( EntryPoint("init", EntryPoint.Type.CLASS, mainClassName, QuiltConstants.MOD_INITIALIZER), - EntryPoint("client_init", EntryPoint.Type.CLASS, clientClassName, QuiltConstants.CLIENT_MOD_INITIALIZER), + EntryPoint( + "client_init", + EntryPoint.Type.CLASS, + clientClassName, + QuiltConstants.CLIENT_MOD_INITIALIZER + ), ) - } // TODO: un-hardcode? + } // TODO: un-hardcode? assets.addTemplateProperties( "ARTIFACT_ID" to buildSystemProps.artifactId, From 66953fea41261ace768df89cf72d5ee4d7601cf8 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 23:02:01 +0200 Subject: [PATCH 13/21] Forgot some licenses --- .../util/QuiltStandardLibrariesVersions.kt | 16 ++++++++++++++-- .../kotlin/platform/quilt/util/QuiltVersions.kt | 17 +++++++++++++++-- .../j2ee/quilt/quilt_libs_versions.toml.html | 10 ++++++++++ 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt index 745b482f5..65c5c131f 100644 --- a/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt +++ b/src/main/kotlin/platform/quilt/util/QuiltStandardLibrariesVersions.kt @@ -1,3 +1,13 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + package com.demonwav.mcdev.platform.quilt.util import com.demonwav.mcdev.creator.selectProxy @@ -41,7 +51,9 @@ class QuiltStandardLibrariesVersions(val versions: List) { continue@versionLoop } } - val versionNumber = version["version_number"]?.asString?.let(SemanticVersion.Companion::tryParse) + val versionNumber = version["version_number"] + ?.asString + ?.let(SemanticVersion.Companion::tryParse) ?: return null val gameVersions = version["game_versions"]?.asJsonArray ?: return null val gameVersionsList = mutableListOf() @@ -65,4 +77,4 @@ class QuiltStandardLibrariesVersions(val versions: List) { return null } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt index 5812c5ec0..fb0bf02fd 100644 --- a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt +++ b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt @@ -1,3 +1,13 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2023 minecraft-dev + * + * MIT License + */ + package com.demonwav.mcdev.platform.quilt.util import com.demonwav.mcdev.creator.selectProxy @@ -59,7 +69,10 @@ class QuiltVersions(val game: List, val mappings: List, val load val loaders = json["loader"]?.asJsonArray ?: return null for (loader in loaders) { val loaderObj = loader?.asJsonObject ?: return null - val version = loaderObj["version"]?.asString?.let(SemanticVersion.Companion::tryParse) ?: return null + val version = loaderObj["version"] + ?.asString + ?.let(SemanticVersion.Companion::tryParse) + ?: return null loaderList += version } } @@ -76,4 +89,4 @@ class QuiltVersions(val game: List, val mappings: List, val load return null } } -} \ No newline at end of file +} diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html index ea0cb8786..916976760 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.html @@ -1,3 +1,13 @@ + +

This is a built-in file template used to create a new libs.versions.toml file for Quilt projects.

From 93dde67f5741ba6ad9fe728ed46cd60a705f7bd3 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 28 Mar 2023 23:19:18 +0200 Subject: [PATCH 14/21] Some more formatting --- .../platform/quilt/creator/gradle-steps.kt | 10 +++++++--- .../kotlin/platform/quilt/creator/ui-steps.kt | 19 +++++++++++++++++-- .../reference/QuiltReferenceContributor.kt | 8 +++++--- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt index de23f2a6b..349f99f4b 100644 --- a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -14,7 +14,11 @@ import com.demonwav.mcdev.creator.EmptyStep import com.demonwav.mcdev.creator.JdkProjectSetupFinalizer import com.demonwav.mcdev.creator.addGradleGitignore import com.demonwav.mcdev.creator.addTemplates -import com.demonwav.mcdev.creator.buildsystem.* +import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep +import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport +import com.demonwav.mcdev.creator.buildsystem.GRADLE_VERSION_KEY +import com.demonwav.mcdev.creator.buildsystem.GradleImportStep +import com.demonwav.mcdev.creator.buildsystem.addGradleWrapperProperties import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep @@ -28,7 +32,7 @@ class QuiltGradleSupport : BuildSystemSupport { override fun createStep(step: String, parent: NewProjectWizardStep): NewProjectWizardStep { return when (step) { - BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent) // TODO: Read fixed version of Gradle Wrapper Step + BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent) // TODO: fixed version of Gradle Wrapper Step BuildSystemSupport.POST_STEP -> GradleImportStep(parent) else -> EmptyStep(parent) } @@ -75,7 +79,7 @@ class QuiltGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs "gradle/libs.versions.toml" to MinecraftTemplates.QUILT_LIBS_VERSIONS_TEMPLATE ) - assets.data.putUserData(GRADLE_VERSION_KEY, SemanticVersion.release(8,0,2)) + assets.data.putUserData(GRADLE_VERSION_KEY, SemanticVersion.release(8, 0, 2)) assets.addGradleWrapperProperties(project) if (gitEnabled) { diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt index 59706b49b..12979ab14 100644 --- a/src/main/kotlin/platform/quilt/creator/ui-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -11,8 +11,20 @@ package com.demonwav.mcdev.platform.quilt.creator import com.demonwav.mcdev.creator.platformtype.ModPlatformStep -import com.demonwav.mcdev.creator.step.* +import com.demonwav.mcdev.creator.step.AbstractCollapsibleStep +import com.demonwav.mcdev.creator.step.AbstractLatentStep +import com.demonwav.mcdev.creator.step.AbstractMcVersionChainStep +import com.demonwav.mcdev.creator.step.AbstractOptionalStringBasedOnProjectNameStep +import com.demonwav.mcdev.creator.step.DescriptionStep +import com.demonwav.mcdev.creator.step.IssueTrackerStep +import com.demonwav.mcdev.creator.step.LicenseStep +import com.demonwav.mcdev.creator.step.ModNameStep import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep +import com.demonwav.mcdev.creator.step.RepositoryStep +import com.demonwav.mcdev.creator.step.UseMixinsStep +import com.demonwav.mcdev.creator.step.VersionChainComboBox +import com.demonwav.mcdev.creator.step.WaitForSmartModeStep +import com.demonwav.mcdev.creator.step.WebsiteStep import com.demonwav.mcdev.platform.forge.inspections.sideonly.Side import com.demonwav.mcdev.platform.quilt.util.QuiltStandardLibrariesVersions import com.demonwav.mcdev.platform.quilt.util.QuiltVersions @@ -193,7 +205,10 @@ class QuiltVersionChainStep( super.setupProject(project) data.putUserData(MC_VERSION_KEY, (getVersion(MINECRAFT_VERSION) as QuiltMcVersion).version) data.putUserData(LOADER_VERSION_KEY, getVersion(LOADER_VERSION) as SemanticVersion) - data.putUserData(QUILT_MAPPINGS_VERSION_KEY, (getVersion(QUILT_MAPPINGS_VERSION) as QuiltVersions.QuiltMappingsVersion).name) + data.putUserData( + QUILT_MAPPINGS_VERSION_KEY, + (getVersion(QUILT_MAPPINGS_VERSION) as QuiltVersions.QuiltMappingsVersion).name + ) if (useApi) { data.putUserData(API_VERSION_KEY, getVersion(QFAPI_VERSION) as SemanticVersion) } diff --git a/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt index 7c90810cf..e7480019d 100644 --- a/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt +++ b/src/main/kotlin/platform/quilt/reference/QuiltReferenceContributor.kt @@ -15,7 +15,11 @@ import com.demonwav.mcdev.platform.fabric.reference.LicenseReference import com.demonwav.mcdev.platform.fabric.reference.ResourceFileReference import com.demonwav.mcdev.platform.quilt.util.QuiltConstants import com.demonwav.mcdev.util.isPropertyValue -import com.intellij.json.psi.* +import com.intellij.json.psi.JsonArray +import com.intellij.json.psi.JsonElement +import com.intellij.json.psi.JsonObject +import com.intellij.json.psi.JsonProperty +import com.intellij.json.psi.JsonStringLiteral import com.intellij.patterns.PatternCondition import com.intellij.patterns.PlatformPatterns import com.intellij.psi.PsiReferenceContributor @@ -23,12 +27,10 @@ import com.intellij.psi.PsiReferenceRegistrar import com.intellij.util.ProcessingContext import org.jetbrains.kotlin.idea.completion.or - class QuiltReferenceContributor : PsiReferenceContributor() { override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) { val stringInModJson = PlatformPatterns.psiElement(JsonStringLiteral::class.java) .inVirtualFile(PlatformPatterns.virtualFile().withName(QuiltConstants.QUILT_MOD_JSON)) - val entryPointPattern = stringInModJson.withParent( PlatformPatterns.psiElement(JsonArray::class.java) .withSuperParent( From bf81f890a4f197e4fd13bc6d8fdb147a00758f69 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Thu, 13 Apr 2023 13:53:14 +0200 Subject: [PATCH 15/21] Fix for https://github.com/QuiltMC/update-quilt-meta/issues/9 --- .../platform/quilt/util/QuiltVersions.kt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt index fb0bf02fd..fed6a382d 100644 --- a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt +++ b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt @@ -44,7 +44,7 @@ class QuiltVersions(val game: List, val mappings: List, val load .await() val gameList = mutableListOf() - val mappingsList = mutableListOf() + // val mappingsList = mutableListOf() TODO: workaround for https://github.com/QuiltMC/update-quilt-meta/issues/9, change back when fixed val loaderList = mutableListOf() response.body().toStream().use { stream -> val json = JsonParser.parseReader(stream.reader())?.asJsonObject ?: return null @@ -57,14 +57,14 @@ class QuiltVersions(val game: List, val mappings: List, val load gameList += Game(gameVer, stable) } - val mappings = json["mappings"]?.asJsonArray ?: return null + /*val mappings = json["mappings"]?.asJsonArray ?: return null TODO: see above for (mapping in mappings) { val mappingObj = mapping?.asJsonObject ?: return null val gameVersion = mappingObj["gameVersion"]?.asString ?: return null val version = mappingObj["version"]?.asString ?: return null val build = mappingObj["build"]?.asInt ?: return null mappingsList += Mappings(gameVersion, QuiltMappingsVersion(version, build)) - } + }*/ val loaders = json["loader"]?.asJsonArray ?: return null for (loader in loaders) { @@ -76,6 +76,22 @@ class QuiltVersions(val game: List, val mappings: List, val load loaderList += version } } + // TODO: see above + val mappingsList = mutableListOf() + val response2 = manager.get("https://meta.quiltmc.org/v3/versions/quilt-mappings") + .header("User-Agent", PluginUtil.useragent) + .suspendable() + .await() + response2.body().toStream().use { + val json = JsonParser.parseReader(it.reader())?.asJsonArray ?: return null + for (mapping in json) { + val mappingObj = mapping?.asJsonObject ?: return null + val gameVersion = mappingObj["gameVersion"]?.asString ?: return null + val version = mappingObj["version"]?.asString ?: return null + val build = mappingObj["build"]?.asInt ?: return null + mappingsList += Mappings(gameVersion, QuiltMappingsVersion(version, build)) + } + } return QuiltVersions(gameList, mappingsList, loaderList) } catch (e: IOException) { LOGGER.error(e) From 976575421677058b9bf1bf7bd6bbf989f4426f9b Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:30:08 +0200 Subject: [PATCH 16/21] Readd gradle wrapper step as it seems to be fixed since the merge --- src/main/kotlin/platform/quilt/creator/gradle-steps.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt index 349f99f4b..bfdfb0bb6 100644 --- a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -18,10 +18,12 @@ import com.demonwav.mcdev.creator.buildsystem.BuildSystemPropertiesStep import com.demonwav.mcdev.creator.buildsystem.BuildSystemSupport import com.demonwav.mcdev.creator.buildsystem.GRADLE_VERSION_KEY import com.demonwav.mcdev.creator.buildsystem.GradleImportStep +import com.demonwav.mcdev.creator.buildsystem.GradleWrapperStep import com.demonwav.mcdev.creator.buildsystem.addGradleWrapperProperties import com.demonwav.mcdev.creator.findStep import com.demonwav.mcdev.creator.gitEnabled import com.demonwav.mcdev.creator.step.AbstractLongRunningAssetsStep +import com.demonwav.mcdev.creator.step.NewProjectWizardChainStep.Companion.nextStep import com.demonwav.mcdev.util.MinecraftTemplates import com.demonwav.mcdev.util.SemanticVersion import com.intellij.ide.wizard.NewProjectWizardStep @@ -32,7 +34,7 @@ class QuiltGradleSupport : BuildSystemSupport { override fun createStep(step: String, parent: NewProjectWizardStep): NewProjectWizardStep { return when (step) { - BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent) // TODO: fixed version of Gradle Wrapper Step + BuildSystemSupport.PRE_STEP -> QuiltGradleFilesStep(parent).nextStep(::GradleWrapperStep) BuildSystemSupport.POST_STEP -> GradleImportStep(parent) else -> EmptyStep(parent) } From df4142f1501665871f2924c241b0dcc7ac5e445f Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:30:50 +0200 Subject: [PATCH 17/21] Revert "Fix for https://github.com/QuiltMC/update-quilt-meta/issues/9", as quilt fixed it This reverts commit bf81f890a4f197e4fd13bc6d8fdb147a00758f69. --- .../platform/quilt/util/QuiltVersions.kt | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt index fed6a382d..fb0bf02fd 100644 --- a/src/main/kotlin/platform/quilt/util/QuiltVersions.kt +++ b/src/main/kotlin/platform/quilt/util/QuiltVersions.kt @@ -44,7 +44,7 @@ class QuiltVersions(val game: List, val mappings: List, val load .await() val gameList = mutableListOf() - // val mappingsList = mutableListOf() TODO: workaround for https://github.com/QuiltMC/update-quilt-meta/issues/9, change back when fixed + val mappingsList = mutableListOf() val loaderList = mutableListOf() response.body().toStream().use { stream -> val json = JsonParser.parseReader(stream.reader())?.asJsonObject ?: return null @@ -57,14 +57,14 @@ class QuiltVersions(val game: List, val mappings: List, val load gameList += Game(gameVer, stable) } - /*val mappings = json["mappings"]?.asJsonArray ?: return null TODO: see above + val mappings = json["mappings"]?.asJsonArray ?: return null for (mapping in mappings) { val mappingObj = mapping?.asJsonObject ?: return null val gameVersion = mappingObj["gameVersion"]?.asString ?: return null val version = mappingObj["version"]?.asString ?: return null val build = mappingObj["build"]?.asInt ?: return null mappingsList += Mappings(gameVersion, QuiltMappingsVersion(version, build)) - }*/ + } val loaders = json["loader"]?.asJsonArray ?: return null for (loader in loaders) { @@ -76,22 +76,6 @@ class QuiltVersions(val game: List, val mappings: List, val load loaderList += version } } - // TODO: see above - val mappingsList = mutableListOf() - val response2 = manager.get("https://meta.quiltmc.org/v3/versions/quilt-mappings") - .header("User-Agent", PluginUtil.useragent) - .suspendable() - .await() - response2.body().toStream().use { - val json = JsonParser.parseReader(it.reader())?.asJsonArray ?: return null - for (mapping in json) { - val mappingObj = mapping?.asJsonObject ?: return null - val gameVersion = mappingObj["gameVersion"]?.asString ?: return null - val version = mappingObj["version"]?.asString ?: return null - val build = mappingObj["build"]?.asInt ?: return null - mappingsList += Mappings(gameVersion, QuiltMappingsVersion(version, build)) - } - } return QuiltVersions(gameList, mappingsList, loaderList) } catch (e: IOException) { LOGGER.error(e) From 62651ed87d2c6aed16e39aa831934edd112c040b Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:12:58 +0200 Subject: [PATCH 18/21] Add Standard Library selector uses a segmented button, allows for QSL selection, but warns that it isnt supported and disables version selection --- .../platform/quilt/creator/asset-steps.kt | 7 +- .../platform/quilt/creator/gradle-steps.kt | 7 +- .../kotlin/platform/quilt/creator/ui-steps.kt | 117 ++++++++++++------ .../j2ee/quilt/quilt_build.gradle.ft | 6 + .../j2ee/quilt/quilt_libs_versions.toml.ft | 4 + 5 files changed, 103 insertions(+), 38 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/asset-steps.kt b/src/main/kotlin/platform/quilt/creator/asset-steps.kt index eb8bfce69..6435022ce 100644 --- a/src/main/kotlin/platform/quilt/creator/asset-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/asset-steps.kt @@ -107,7 +107,8 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin val mcVersion = data.getUserData(QuiltVersionChainStep.MC_VERSION_KEY) ?: return val javaVersion = findStep().preferredJdk.ordinal val license = data.getUserData(LicenseStep.KEY) ?: return - val apiVersion = data.getUserData(QuiltVersionChainStep.API_VERSION_KEY) + val apiVersion = data.getUserData(QuiltStandardLibrariesStep.API_VERSION_KEY) + val apiName = data.getUserData(QuiltStandardLibrariesStep.API_NAME_KEY) val useMixins = data.getUserData(UseMixinsStep.KEY) ?: false val packageName = "${buildSystemProps.groupId.toPackageName()}.${buildSystemProps.artifactId.toPackageName()}" @@ -144,6 +145,10 @@ class QuiltSmartModeFilesStep(parent: NewProjectWizardStep) : AbstractLongRunnin assets.addTemplateProperties("API_VERSION" to apiVersion) } + if (apiName != null) { + assets.addTemplateProperties("API_NAME" to apiName) + } + if (useMixins) { assets.addTemplateProperties("MIXINS" to "true") } diff --git a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt index bfdfb0bb6..d87aa8fad 100644 --- a/src/main/kotlin/platform/quilt/creator/gradle-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/gradle-steps.kt @@ -51,7 +51,8 @@ class QuiltGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs val loaderVersion = data.getUserData(QuiltVersionChainStep.LOADER_VERSION_KEY) ?: return val loomVersion = "1.1.+" // TODO val javaVersion = findStep().preferredJdk.ordinal - val apiVersion = data.getUserData(QuiltVersionChainStep.API_VERSION_KEY) + val apiVersion = data.getUserData(QuiltStandardLibrariesStep.API_VERSION_KEY) + val apiName = data.getUserData(QuiltStandardLibrariesStep.API_NAME_KEY) val officialMappings = data.getUserData(QuiltVersionChainStep.OFFICIAL_MAPPINGS_KEY) ?: false assets.addTemplateProperties( @@ -69,6 +70,10 @@ class QuiltGradleFilesStep(parent: NewProjectWizardStep) : AbstractLongRunningAs assets.addTemplateProperties("API_VERSION" to apiVersion) } + if (apiName != null) { + assets.addTemplateProperties("API_NAME" to apiName) + } + if (officialMappings) { assets.addTemplateProperties("OFFICIAL_MAPPINGS" to "true") } diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt index 12979ab14..caea8e2e5 100644 --- a/src/main/kotlin/platform/quilt/creator/ui-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -34,6 +34,10 @@ import com.demonwav.mcdev.util.bindEnabled import com.intellij.ide.users.LocalUserSettings import com.intellij.ide.wizard.AbstractNewProjectWizardStep import com.intellij.ide.wizard.NewProjectWizardStep +import com.intellij.openapi.observable.properties.GraphProperty +import com.intellij.openapi.observable.properties.ObservableMutableProperty +import com.intellij.openapi.observable.properties.transform +import com.intellij.openapi.observable.util.bind import com.intellij.openapi.observable.util.bindBooleanStorage import com.intellij.openapi.observable.util.bindStorage import com.intellij.openapi.observable.util.not @@ -64,7 +68,8 @@ class QuiltPlatformStep( override fun createStep(data: Pair): NewProjectWizardStep { val (quiltVersions, apiVersions) = data - return QuiltVersionChainStep(this, quiltVersions, apiVersions) + return QuiltVersionChainStep(this, quiltVersions) + .nextStep { QuiltStandardLibrariesStep(this, apiVersions) } .nextStep(::QuiltEnvironmentStep) .nextStep(::UseMixinsStep) .nextStep(::ModNameStep) @@ -85,29 +90,24 @@ class QuiltPlatformStep( class QuiltVersionChainStep( parent: NewProjectWizardStep, - private val quiltVersions: QuiltVersions, - private val apiVersions: QuiltStandardLibrariesVersions, -) : AbstractMcVersionChainStep(parent, "Loader Version:", "Quilt Mappings Version:", "QFAPI/QSL Version:") { + private val quiltVersions: QuiltVersions +) : AbstractMcVersionChainStep(parent, "Loader Version:", "Quilt Mappings Version:") { companion object { private const val LOADER_VERSION = 1 private const val QUILT_MAPPINGS_VERSION = 2 - private const val QFAPI_VERSION = 3 val MC_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.mcVersion") val LOADER_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.loaderVersion") val QUILT_MAPPINGS_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.quiltVersion") - val API_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.qfapiVersion") val OFFICIAL_MAPPINGS_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.officialMappings") + + lateinit var MC_VERSION_PROPERTY: ObservableMutableProperty> } private val showSnapshotsProperty = propertyGraph.property(false) .bindBooleanStorage("${javaClass.name}.showSnapshots") private var showSnapshots by showSnapshotsProperty - private val useApiProperty = propertyGraph.property(true) - .bindBooleanStorage("${javaClass.name}.useApi") - private var useApi by useApiProperty - private val useOfficialMappingsProperty = propertyGraph.property(false) .bindBooleanStorage("${javaClass.name}.useOfficialMappings") private var useOfficialMappings by useOfficialMappingsProperty @@ -145,22 +145,6 @@ class QuiltVersionChainStep( ).bindEnabled(useOfficialMappingsProperty.not()).component.foreground = JBColor.YELLOW comboBox } - QFAPI_VERSION -> { - val comboBox = super.createComboBox(row, index, items).bindEnabled(useApiProperty) - row.checkBox("Use Quilted Fabric API").bindSelected(useApiProperty) - row.label(EMPTY_LABEL).bindText( - getVersionProperty(MINECRAFT_VERSION).transform { mcVersion -> - mcVersion as QuiltMcVersion - val matched = apiVersions.versions.any { mcVersion.version in it.gameVersions } - if (matched) { - EMPTY_LABEL - } else { - "Unable to match QFAPI/QSL versions to Minecraft version" - } - }, - ).bindEnabled(useApiProperty).component.foreground = JBColor.YELLOW - comboBox - } else -> super.createComboBox(row, index, items) } } @@ -176,13 +160,6 @@ class QuiltVersionChainStep( } filteredVersions.ifEmpty { quiltVersions.mappings.map { it.version } } } - QFAPI_VERSION -> { - val mcVersion = versionsAbove[MINECRAFT_VERSION] as QuiltMcVersion - val filteredVersions = apiVersions.versions.mapNotNull { api -> - api.version.takeIf { mcVersion.version in api.gameVersions } - } - filteredVersions.ifEmpty { apiVersions.versions.map { it.version } } - } else -> throw IncorrectOperationException() } } @@ -192,6 +169,7 @@ class QuiltVersionChainStep( if (!showSnapshots) { updateVersionBox() } + MC_VERSION_PROPERTY = getVersionProperty(MINECRAFT_VERSION) } private fun updateVersionBox() { @@ -209,9 +187,6 @@ class QuiltVersionChainStep( QUILT_MAPPINGS_VERSION_KEY, (getVersion(QUILT_MAPPINGS_VERSION) as QuiltVersions.QuiltMappingsVersion).name ) - if (useApi) { - data.putUserData(API_VERSION_KEY, getVersion(QFAPI_VERSION) as SemanticVersion) - } data.putUserData(OFFICIAL_MAPPINGS_KEY, useOfficialMappings) } } @@ -255,6 +230,76 @@ class QuiltEnvironmentStep(parent: NewProjectWizardStep) : AbstractNewProjectWiz } } +class QuiltStandardLibrariesStep( + parent: NewProjectWizardStep, + private val apiVersions: QuiltStandardLibrariesVersions +) : AbstractNewProjectWizardStep(parent) { + companion object { + val API_NAME_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.QuiltApiName") + val API_VERSION_KEY = Key.create("${QuiltVersionChainStep::class.java.name}.quiltApiVersion") + } + + private val apiNameProperty = propertyGraph.property("QFAPI") + .bindStorage("${javaClass.name}.apiName") + private var apiName by apiNameProperty + + private val apiVersionProperty: GraphProperty> = propertyGraph + .property(apiVersions.versions.first().version) + private var apiVersion by apiVersionProperty + override fun setupUI(builder: Panel) { + with(builder) { + row("Standard Library:") { + segmentedButton(listOf("QSL", "QFAPI", "QFAPI/deprecated FAPI", "None")) { it } + .bind(apiNameProperty) + }.label("QSL is not yet supported").let { cell -> + cell.visible(apiNameProperty.transform { apiName == "QSL" }.get()) + apiNameProperty.transform { apiName == "QSL" }.afterChange { cell.visible(it) } + cell.component.foreground = JBColor.YELLOW + } + + row("Library Version: ") { + val comboBox = cell( + VersionChainComboBox(getVersionsList(QuiltVersionChainStep.MC_VERSION_PROPERTY.get())) + .bind(apiVersionProperty) + ) + QuiltVersionChainStep.MC_VERSION_PROPERTY.afterChange { + comboBox.component.setSelectableItems(getVersionsList(it)) + } + comboBox.enabled(apiNameProperty.transform { apiName != "QSL" && apiName != "None" }.get()) + apiNameProperty.transform { apiName != "QSL" && apiName != "None" }.afterChange { comboBox.enabled(it) } + }.let { row -> + row.label(EMPTY_LABEL).bindText( + QuiltVersionChainStep.MC_VERSION_PROPERTY.transform { mcVersion -> + mcVersion as QuiltMcVersion + val matched = apiVersions.versions.any { mcVersion.version in it.gameVersions } + if (matched) { + EMPTY_LABEL + } else { + "Unable to match QFAPI/QSL versions to Minecraft version" + } + }, + ).component.foreground = JBColor.YELLOW + } + } + } + + private fun getVersionsList(mcVersion: Comparable<*>): List { + val mcVersion = mcVersion as QuiltMcVersion + val filteredVersions = apiVersions.versions.mapNotNull { api -> + api.version.takeIf { mcVersion.version in api.gameVersions } + } + return filteredVersions.ifEmpty { apiVersions.versions.map { it.version } } + } + + override fun setupProject(project: Project) { + super.setupProject(project) + if (apiName != "None") { + data.putUserData(API_VERSION_KEY, apiVersion as SemanticVersion) + } + data.putUserData(API_NAME_KEY, apiName) + } +} + class QuiltOptionalSettingsStep(parent: NewProjectWizardStep) : AbstractCollapsibleStep(parent) { override val title = "Optional Settings" diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft index 6365e3177..3057e2e5a 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_build.gradle.ft @@ -31,9 +31,15 @@ dependencies { modImplementation libs.quilt.loader #if (${API_VERSION}) +#if(${API_NAME}=="QFAPI") // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. // Quilted Fabric API will automatically pull in the correct QSL version. modImplementation libs.quilted.fabric.api +#elseif(${API_NAME}=="QFAPI/deprecated FAPI") + // QSL is not a complete API; You will need Quilted Fabric API to fill in the gaps. + // Quilted Fabric API will automatically pull in the correct QSL version. The bundle also includes deprecated FAPI libraries + modImplementation libs.bundles.quilted.fabric.api +#end #end } diff --git a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft index 36d4ae102..96b327fdc 100644 --- a/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft +++ b/src/main/resources/fileTemplates/j2ee/quilt/quilt_libs_versions.toml.ft @@ -17,14 +17,18 @@ quilt_loader = { module = "org.quiltmc:quilt-loader", version.ref = "quilt_loade #if (${API_VERSION}) quilted_fabric_api = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api", version.ref = "quilted_fabric_api" } +#if(${API_NAME}=="QFAPI/deprecated FAPI") quilted_fabric_api_deprecated = { module = "org.quiltmc.quilted-fabric-api:quilted-fabric-api-deprecated", version.ref = "quilted_fabric_api" } #end +#end # If you have multiple similar dependencies, you can declare a dependency bundle and reference it on the build script with "libs.bundles.example". [bundles] #if (${API_VERSION}) +#if(${API_NAME}=="QFAPI/deprecated FAPI") quilted_fabric_api = ["quilted_fabric_api", "quilted_fabric_api_deprecated"] #end +#end [plugins] quilt_loom = { id = "org.quiltmc.loom", version = "${LOOM_VERSION}" } \ No newline at end of file From f4c1bab4b7a9df4edaf21024e0d66c431d39b332 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Wed, 19 Apr 2023 16:32:25 +0200 Subject: [PATCH 19/21] Properly store changes to the authors input --- src/main/kotlin/platform/quilt/creator/ui-steps.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt index caea8e2e5..f7498bd3f 100644 --- a/src/main/kotlin/platform/quilt/creator/ui-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -14,7 +14,7 @@ import com.demonwav.mcdev.creator.platformtype.ModPlatformStep import com.demonwav.mcdev.creator.step.AbstractCollapsibleStep import com.demonwav.mcdev.creator.step.AbstractLatentStep import com.demonwav.mcdev.creator.step.AbstractMcVersionChainStep -import com.demonwav.mcdev.creator.step.AbstractOptionalStringBasedOnProjectNameStep +import com.demonwav.mcdev.creator.step.AbstractOptionalStringStep import com.demonwav.mcdev.creator.step.DescriptionStep import com.demonwav.mcdev.creator.step.IssueTrackerStep import com.demonwav.mcdev.creator.step.LicenseStep @@ -310,12 +310,14 @@ class QuiltOptionalSettingsStep(parent: NewProjectWizardStep) : AbstractCollapsi .nextStep(::IssueTrackerStep) } -class QuiltAuthorsStep(parent: NewProjectWizardStep) : AbstractOptionalStringBasedOnProjectNameStep(parent) { +class QuiltAuthorsStep(parent: NewProjectWizardStep) : AbstractOptionalStringStep(parent) { override val label = "Authors:" override val bindToStorage = true init { - value = "${LocalUserSettings.userName}:Owner" + if (value == "") { + value = "${LocalUserSettings.userName}: Owner" + } } override fun setupProject(project: Project) { From fe0a0a62816c69dd672bd1354e567313f40c7b9d Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Wed, 19 Apr 2023 22:10:09 +0200 Subject: [PATCH 20/21] Refactor: Move row init inside init blocks --- src/main/kotlin/platform/quilt/creator/ui-steps.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt index f7498bd3f..052c322fe 100644 --- a/src/main/kotlin/platform/quilt/creator/ui-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -251,12 +251,13 @@ class QuiltStandardLibrariesStep( row("Standard Library:") { segmentedButton(listOf("QSL", "QFAPI", "QFAPI/deprecated FAPI", "None")) { it } .bind(apiNameProperty) - }.label("QSL is not yet supported").let { cell -> - cell.visible(apiNameProperty.transform { apiName == "QSL" }.get()) - apiNameProperty.transform { apiName == "QSL" }.afterChange { cell.visible(it) } - cell.component.foreground = JBColor.YELLOW - } + label("QSL is not yet supported").let { cell -> + cell.visible(apiNameProperty.transform { apiName == "QSL" }.get()) + apiNameProperty.transform { apiName == "QSL" }.afterChange { cell.visible(it) } + cell.component.foreground = JBColor.YELLOW + } + } row("Library Version: ") { val comboBox = cell( VersionChainComboBox(getVersionsList(QuiltVersionChainStep.MC_VERSION_PROPERTY.get())) From 00ef5a909ca66aac7d9d3786b779f226d890c158 Mon Sep 17 00:00:00 2001 From: anonymous123-code <61744596+anonymous123-code@users.noreply.github.com> Date: Thu, 20 Apr 2023 19:47:29 +0200 Subject: [PATCH 21/21] Refactor: Move row init inside init blocks --- src/main/kotlin/platform/quilt/creator/ui-steps.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/platform/quilt/creator/ui-steps.kt b/src/main/kotlin/platform/quilt/creator/ui-steps.kt index 052c322fe..85e72f1f0 100644 --- a/src/main/kotlin/platform/quilt/creator/ui-steps.kt +++ b/src/main/kotlin/platform/quilt/creator/ui-steps.kt @@ -268,8 +268,8 @@ class QuiltStandardLibrariesStep( } comboBox.enabled(apiNameProperty.transform { apiName != "QSL" && apiName != "None" }.get()) apiNameProperty.transform { apiName != "QSL" && apiName != "None" }.afterChange { comboBox.enabled(it) } - }.let { row -> - row.label(EMPTY_LABEL).bindText( + + label(EMPTY_LABEL).bindText( QuiltVersionChainStep.MC_VERSION_PROPERTY.transform { mcVersion -> mcVersion as QuiltMcVersion val matched = apiVersions.versions.any { mcVersion.version in it.gameVersions } @@ -285,7 +285,7 @@ class QuiltStandardLibrariesStep( } private fun getVersionsList(mcVersion: Comparable<*>): List { - val mcVersion = mcVersion as QuiltMcVersion + mcVersion as QuiltMcVersion val filteredVersions = apiVersions.versions.mapNotNull { api -> api.version.takeIf { mcVersion.version in api.gameVersions } }