Skip to content

Commit

Permalink
🐛 Fix version resolution for resource pack only workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
misode committed Nov 22, 2024
1 parent 70142b6 commit a5c1548
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
19 changes: 16 additions & 3 deletions packages/java-edition/src/dependency/mcmeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function resolveConfiguredVersion(
inputVersion: string,
versions: McmetaVersions,
packMcmeta: PackMcmeta | undefined,
packType: 'assets' | 'data' | undefined,
): VersionInfo {
function findReleaseTarget(version: McmetaVersion): string {
if (version.release_target) {
Expand Down Expand Up @@ -55,18 +56,30 @@ export function resolveConfiguredVersion(
const packFormat = packMcmeta?.pack.pack_format
if (packFormat && latestRelease) {
// If the pack format is larger than the latest release, use the latest snapshot
if (packFormat > latestRelease.data_pack_version) {
if (
packFormat > (packType === 'assets'
? latestRelease.resource_pack_version
: latestRelease.data_pack_version)
) {
return toVersionInfo(versions[0], 'auto')
}
// Look for versions from recent to oldest, picking the most recent release that matches
let oldestRelease = undefined
for (const version of versions) {
if (version.type === 'release') {
// If we already passed the pack format, use the oldest release so far
if (packFormat > version.data_pack_version) {
if (
packFormat > (packType === 'assets'
? version.resource_pack_version
: version.data_pack_version)
) {
return toVersionInfo(oldestRelease, 'auto')
}
if (packFormat === version.data_pack_version) {
if (
packFormat === (packType === 'assets'
? version.resource_pack_version
: version.data_pack_version)
) {
return toVersionInfo(version, 'auto')
}
oldestRelease = version
Expand Down
10 changes: 6 additions & 4 deletions packages/java-edition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
config.env.gameVersion,
versions,
packMcmeta,
type,
)
packs.push({ type, packRoot, packMcmeta, versionInfo })
}
Expand All @@ -83,21 +84,22 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
const packs = await findPackMcmetas(versions)

function selectVersionInfo(packs: PackInfo[], versions: McmetaVersions) {
// Select the first valid data pack.mcmeta
// Select the first valid pack.mcmeta, prioritizing data packs
const pack = packs.find(p => p.packMcmeta !== undefined && p.type === 'data')
?? packs.find(p => p.packMcmeta !== undefined && p.type === 'assets')
const version = pack === undefined
? resolveConfiguredVersion(config.env.gameVersion, versions, undefined)
? resolveConfiguredVersion(config.env.gameVersion, versions, undefined, undefined)
: pack.versionInfo
const packMessage = pack === undefined
? 'Failed finding a valid pack.mcmeta'
: `Found a valid pack.mcmeta ${pack.packRoot}/pack.mcmeta`
const reasonMessage = pack && version.reason === 'auto'
? `using pack format ${pack.packMcmeta?.pack.pack_format} to select`
? `using ${pack.type} pack format ${pack.packMcmeta?.pack.pack_format} to select`
: version.reason === 'config'
? `but using config override "${config.env.gameVersion}" to select`
: version.reason === 'fallback'
? 'using fallback'
: 'loading' // should never occur
: 'impossible' // should never occur
const versionMessage = `version ${version.release}${
version.id === version.release ? '' : ` (${version.id})`
}`
Expand Down
1 change: 1 addition & 0 deletions packages/java-edition/test/dependency/mcmeta.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ describe('mcmeta', () => {
version,
Fixtures.Versions,
packMcmeta,
undefined,
)
snapshot(actual)
})
Expand Down

0 comments on commit a5c1548

Please sign in to comment.