Skip to content

Commit

Permalink
feat: resource packs apply order and incompatible packs prepare to re…
Browse files Browse the repository at this point in the history
…lease 0.0.5-alpha
  • Loading branch information
EchoEllet committed Feb 11, 2025
1 parent 45a55d0 commit 19b48f0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ data class ResourcePackSyncInfo(
* TODO: Add an option to override the apply order
*/
val applyResourcePacks: Boolean = false,
/**
* The applied resource-packs in the game options (`options.txt`).
*
* Resource packs listed first have lower priority, while those listed last have higher priority.
*
* Example:
* `resourcePacks:["file/FantasticCombatMusic.synced.zip","file/EFM_IronsV2.0.synced.zip","file/LowOnFire_1.20.1.synced.zip","file/Enhanced Audio r6.synced.zip","file/Alacrity.synced.zip","file/EpicFightSoundOverhaul2.1_modified.synced.zip","file/Minimal-Rain-and-Snow-2.2.synced.zip","file/[1.4.1] Enhanced Boss Bars.synced.zip","file/TZP_1.20.1_2.7.synced.zip","file/FreshAnimations_v1.9.2.synced.zip","file/FA All_Extensions-v1.4.synced.zip","file/Icon_Xaero_X_FA_v2.4_1.20.2.synced.zip","file/Icon_Xaeros_1.2_HF.synced.zip"]`.
*
* Only applicable if [applyResourcePacks] is `true`.
*
* @see [incompatibleResourcePacks]
* */
val resourcePacksOrder: List<String>? = null,
/**
* By default, resource-packs that are made for newer or older Minecraft versions will be marked
* as incompatible and will be disabled by defaults on game launch unless they are declared in this list.
*
* Only applicable if [applyResourcePacks] is `true`.
* */
val incompatibleResourcePacks: List<String>? = null,
/**
* Will override [SyncInfo.verifyAssetFilesIntegrity] for the resource-packs
*
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[versions]
project = "0.0.4-alpha"
project = "0.0.5-alpha"

kotlin = "2.1.10"
kotlinx-serialization = "1.8.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class ResourcePacksSyncService :
}
Logger.info {
"\uD83D\uDEAB The resource-pack: '$resourcePackFileName' has invalid integrity. Deleting the resource-pack " +
"and downloading it again."
"and downloading it again."
}
resourcePackFilePath.deleteExistingOrTerminate(
fileEntityType = "resource-pack",
Expand Down Expand Up @@ -172,7 +172,7 @@ class ResourcePacksSyncService :
progress = downloadedProgress.toInt(),
detailsText =
"${downloadedBytes.convertBytesToReadableMegabytesAsString()} MB /" +
" ${bytesToDownload.convertBytesToReadableMegabytesAsString()} MB",
" ${bytesToDownload.convertBytesToReadableMegabytesAsString()} MB",
)
},
).downloadFile(fileEntityType = "Resource pack")
Expand All @@ -185,7 +185,7 @@ class ResourcePacksSyncService :
title = "❌ File Integrity Check Failed",
message =
"\uD83D\uDEA8 The newly downloaded file has failed the integrity check. This might be due to a bug " +
"in the script \uD83D\uDC1B or an incorrect integrity info value provided by the admin.",
"in the script \uD83D\uDC1B or an incorrect integrity info value provided by the admin.",
)
}
}
Expand All @@ -203,15 +203,21 @@ class ResourcePacksSyncService :
optionsResourcePacks
?.filterIsInstance<MinecraftOptionsManager.ResourcePack.BuiltIn>()

fun mapResourcePacksToResourcePacksMinecraft(resourcePacks: List<String>) = resourcePacks.map {
if (it.startsWith("file/")) MinecraftOptionsManager.ResourcePack.File(
it.replace("file/", "")
) else MinecraftOptionsManager.ResourcePack.BuiltIn(it)
}

MinecraftOptionsManager.setResourcePacks(
resourcePacks =
buildList {
resourcePacks = resourcePackSyncInfo.resourcePacksOrder?.let { mapResourcePacksToResourcePacksMinecraft(it) }
?: buildList {
builtInOptionsResourcePacks?.let { addAll(it) }
if (resourcePackSyncInfo.allowUsingOthers) {
val userOptionsResourcePacks =
optionsResourcePacks?.filter {
it is MinecraftOptionsManager.ResourcePack.File &&
!isScriptResourcePackFile(Paths.get(it.resourcePackZipFileName))
!isScriptResourcePackFile(Paths.get(it.resourcePackZipFileName))
}
userOptionsResourcePacks?.let { addAll(userOptionsResourcePacks) }
}
Expand All @@ -222,6 +228,12 @@ class ResourcePacksSyncService :
)
},
)

resourcePackSyncInfo.incompatibleResourcePacks?.let {
MinecraftOptionsManager.setIncompatibleResourcePacks(
mapResourcePacksToResourcePacksMinecraft(it)
)
}
}

private fun getResourcePackFilePath(resourcePack: ResourcePack): Path =
Expand Down

0 comments on commit 19b48f0

Please sign in to comment.