Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/creator/custom/TemplateDescriptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class TemplateDescriptor(

companion object {

const val FORMAT_VERSION = 2
const val FORMAT_VERSION = 3
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Minecraft Development for IntelliJ
*
* https://mcdev.io/
*
* Copyright (C) 2026 minecraft-dev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, version 3.0 only.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package com.demonwav.mcdev.creator.custom.derivation

import com.demonwav.mcdev.creator.custom.PropertyDerivation
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.creator.custom.types.CreatorProperty
import com.demonwav.mcdev.update.PluginUtil
import com.demonwav.mcdev.util.MinecraftVersions
import com.demonwav.mcdev.util.SemanticVersion
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.http.*
import kotlinx.coroutines.runBlocking
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.int
import kotlinx.serialization.json.jsonArray
import kotlinx.serialization.json.jsonObject
import kotlinx.serialization.json.jsonPrimitive

class FetchPaperDependencyVersionForMcVersion : PreparedDerivation {

override fun derive(parentValues: List<Any?>): Any {
val version = parentValues[0] as SemanticVersion
if (version < MinecraftVersions.MC_26_1) {
return "${version}-R0.1-SNAPSHOT";
}

val isMaven = (parentValues[1] as String) == "Maven"
if (isMaven) {
val latestBuild = fetchPaperBuildData(version.toString());
return "${version}.build.${latestBuild.id}-${latestBuild.channel}"
}
return "${version}.build.+"
}

private fun fetchPaperBuildData(version: String): PaperBuild {
return runBlocking {
val client = HttpClient()
val response = client.get("https://fill.papermc.io/v3/projects/paper/versions/${version}/builds", block = {
this.header(
"User-Agent",
"minecraft-dev/${PluginUtil.pluginVersion} (https://github.com/minecraft-dev/MinecraftDev)"
)
})
if (response.status.isSuccess()) {
return@runBlocking Json.parseToJsonElement(response.bodyAsText()).jsonArray[0]
.let { build ->
return@let PaperBuild(
build.jsonObject["id"]!!.jsonPrimitive.int,
build.jsonObject["channel"]!!.jsonPrimitive.content.lowercase()
)
}
} else {
throw IllegalStateException("Failed to fetch latest Paper build for version ${version}: ${response.bodyAsText()}")
}
}
}

private data class PaperBuild(
val id: Int,
val channel: String,
);

companion object : PropertyDerivationFactory {

override fun create(
reporter: TemplateValidationReporter,
parents: List<CreatorProperty<*>?>?,
derivation: PropertyDerivation
): PreparedDerivation? {
if (parents.isNullOrEmpty()) {
reporter.error("Expected a parent")
return null
}

if (!parents[0]!!.acceptsType(SemanticVersion::class.java)) {
reporter.error("First parent must produce a semantic version")
return null
}

if (!parents[1]!!.acceptsType(String::class.java)) {
reporter.error("Second parent must produce a string")
return null
}

return FetchPaperDependencyVersionForMcVersion()
}
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/creator/custom/types/StringCreatorProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.demonwav.mcdev.creator.custom.CreatorContext
import com.demonwav.mcdev.creator.custom.PropertyDerivation
import com.demonwav.mcdev.creator.custom.TemplatePropertyDescriptor
import com.demonwav.mcdev.creator.custom.TemplateValidationReporter
import com.demonwav.mcdev.creator.custom.derivation.FetchPaperDependencyVersionForMcVersion
import com.demonwav.mcdev.creator.custom.derivation.PreparedDerivation
import com.demonwav.mcdev.creator.custom.derivation.ReplacePropertyDerivation
import com.demonwav.mcdev.creator.custom.derivation.SelectPropertyDerivation
Expand Down Expand Up @@ -73,6 +74,11 @@ class StringCreatorProperty(
ReplacePropertyDerivation.create(reporter, parents, derives)
}

"fetchPaperDependencyVersionForMcVersion" -> {
val parents = collectDerivationParents(reporter)
FetchPaperDependencyVersionForMcVersion.create(reporter, parents, derives)
}

null -> {
// No need to collect parent values for this one because it is not used
SelectPropertyDerivation.create(reporter, emptyList(), derives)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MinecraftMissingLVTChecker : MissingLVTChecker {
!className.startsWith("net.minecraft.") && !className.startsWith("com.mojang.blaze3d.") -> false
else -> {
val mcVersion = context.mcVersion
mcVersion != null && mcVersion <= MinecraftVersions.MC25_4
mcVersion != null && mcVersion <= MinecraftVersions.MC_1_21_11
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/util/MinecraftVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ object MinecraftVersions {
val MC1_20_6 = SemanticVersion.release(1, 20, 6)
val MC1_21 = SemanticVersion.release(1, 21)
val MC1_21_1 = SemanticVersion.release(1, 21, 1)
val MC25_4 = SemanticVersion.release(25, 4) // placeholder till we know what the last 2025 winter drop version is
val MC_1_21_11 = SemanticVersion.release(1, 21, 11)
val MC_26_1 = SemanticVersion.release(26, 1)

fun requiredJavaVersion(minecraftVersion: SemanticVersion) = when {
minecraftVersion <= MC1_16_5 -> JavaSdkVersion.JDK_1_8
minecraftVersion <= MC1_17_1 -> JavaSdkVersion.JDK_16
minecraftVersion <= MC1_20_4 -> JavaSdkVersion.JDK_17
minecraftVersion<= MC25_4 -> JavaSdkVersion.JDK_21
minecraftVersion <= MC_1_21_11 -> JavaSdkVersion.JDK_21
else -> JavaSdkVersion.JDK_25
}
}
Loading