Skip to content

Commit

Permalink
Fix #2382 Use latest parchment version available if none matches norm…
Browse files Browse the repository at this point in the history
…ally

Parchment is not always up-to-date and thus might not be available for
 the latest MC versions, but will still work fine.
 This commit makes the parchment properties show all known versions
 automatically if the selected MC version is not directly supported
  • Loading branch information
RedNesto committed Nov 28, 2024
1 parent fed7233 commit 692c5a9
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions src/main/kotlin/creator/custom/types/ParchmentCreatorProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ class ParchmentCreatorProperty(
val platformMcVersionPropertyName = descriptor.parameters?.get("minecraftVersionProperty") as? String
val platformMcVersionProperty = properties[platformMcVersionPropertyName]
if (platformMcVersionProperty != null) {
graphProperty.dependsOn(platformMcVersionProperty.graphProperty, true) {
platformMcVersionProperty.graphProperty.afterChange {
val minecraftVersion = getPlatformMinecraftVersion()
if (minecraftVersion != null) {
graphProperty.get().copy(minecraftVersion = minecraftVersion)
} else {
graphProperty.get()
if (mcVersionsModel.getIndexOf(minecraftVersion) == -1) {
refreshVersionsLists(forceLatestVersions = true)
} else if (minecraftVersion != null) {
graphProperty.set(graphProperty.get().copy(minecraftVersion = minecraftVersion))
}
}
}
Expand Down Expand Up @@ -167,17 +167,12 @@ class ParchmentCreatorProperty(

downloadVersions(context) {
refreshVersionsLists()

val minecraftVersion = getPlatformMinecraftVersion()
if (minecraftVersion != null) {
mcVersionProperty.set(minecraftVersion)
}
}
}

private fun refreshVersionsLists(updateMcVersions: Boolean = true) {
val includeOlderMcVersions = includeOlderMcVersionsProperty.get()
val includeSnapshots = includeSnapshotsProperty.get()
private fun refreshVersionsLists(updateMcVersions: Boolean = true, forceLatestVersions: Boolean = false) {
val includeOlderMcVersions = includeOlderMcVersionsProperty.get() || forceLatestVersions
val includeSnapshots = includeSnapshotsProperty.get() || forceLatestVersions

if (updateMcVersions) {
val platformMcVersion = getPlatformMinecraftVersion()
Expand All @@ -199,14 +194,22 @@ class ParchmentCreatorProperty(
mcVersionsModel.removeAllElements()
mcVersionsModel.addAll(mcVersions)

val selectedMcVersion = when {
mcVersionProperty.get() in mcVersions -> mcVersionProperty.get()
defaultValue.minecraftVersion in mcVersions -> defaultValue.minecraftVersion
else -> getPlatformMinecraftVersion() ?: mcVersions.first()
}
if (forceLatestVersions) {
mcVersionProperty.set(mcVersions.maxOrNull() ?: emptyVersion)
} else {
val selectedMcVersion = when {
mcVersionProperty.get() in mcVersions -> mcVersionProperty.get()
defaultValue.minecraftVersion in mcVersions -> defaultValue.minecraftVersion
else -> {
refreshVersionsLists(forceLatestVersions = true)
return
// getPlatformMinecraftVersion() ?: mcVersions.first()
}
}

if (mcVersionProperty.get() != selectedMcVersion) {
mcVersionProperty.set(selectedMcVersion)
if (mcVersionProperty.get() != selectedMcVersion) {
mcVersionProperty.set(selectedMcVersion)
}
}
}

Expand All @@ -218,7 +221,11 @@ class ParchmentCreatorProperty(
.toList()
versionsModel.removeAllElements()
versionsModel.addAll(parchmentVersions)
versionProperty.set(parchmentVersions.firstOrNull() ?: emptyVersion)
if (forceLatestVersions) {
versionProperty.set(parchmentVersions.maxOrNull() ?: emptyVersion)
} else {
versionProperty.set(parchmentVersions.firstOrNull() ?: emptyVersion)
}
}

private fun getPlatformMinecraftVersion(): SemanticVersion? {
Expand Down

0 comments on commit 692c5a9

Please sign in to comment.