Skip to content

Commit 408cadf

Browse files
committed
🩹 Fix pack.mcmeta not providing range of supported versions
1 parent 8ee2b62 commit 408cadf

File tree

5 files changed

+95
-88
lines changed

5 files changed

+95
-88
lines changed

src/systems/datapackCompiler/index.ts

Lines changed: 62 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DataPackTag,
88
type FunctionTagJSON,
99
getDataPackFormat,
10+
getNextSupportedVersion,
1011
parseBlock,
1112
parseDataPackPath,
1213
parseResourceLocation,
@@ -402,16 +403,13 @@ async function generateRootEntityPassengers(
402403
const passengers: NbtList = new NbtList()
403404

404405
const dataEntity = new NbtCompound()
405-
switch (version) {
406-
case '1.20.4':
407-
case '1.20.5':
408-
case '1.21.2':
409-
case '1.21.4':
410-
dataEntity.set('id', new NbtString('minecraft:marker'))
411-
break
412-
case '1.21.5':
413-
default:
414-
dataEntity.set('id', new NbtString('minecraft:item_display'))
406+
407+
if (!compareVersions('1.21.5', version) /* >= 1.21.5 */) {
408+
dataEntity.set('id', new NbtString('minecraft:item_display'))
409+
} else if (!compareVersions('1.20.4', version) /* >= 1.20.4 */) {
410+
dataEntity.set('id', new NbtString('minecraft:marker'))
411+
} else {
412+
throw new Error(`Minecraft version is below minimum supported version 1.20.4!`)
415413
}
416414

417415
passengers.add(
@@ -471,61 +469,46 @@ async function generateRootEntityPassengers(
471469
throw new Error(`Model for bone '${node.storage_name}' not found!`)
472470
}
473471

474-
switch (version) {
475-
case '1.20.4': {
476-
item.set(
477-
'tag',
478-
new NbtCompound().set(
479-
'CustomModelData',
480-
new NbtInt(variantModel.custom_model_data)
481-
)
482-
)
483-
// `Count` does not default to 1.
484-
// However, `count` does default to 1 in later versions, so we only need this for 1.20.4.
485-
item.set('Count', new NbtInt(1))
486-
break
487-
}
488-
case '1.20.5': {
489-
item.set(
490-
'components',
491-
new NbtCompound().set(
472+
if (!compareVersions('1.21.4', version) /* >= 1.21.4 */) {
473+
item.set(
474+
'components',
475+
new NbtCompound()
476+
.set('minecraft:item_model', new NbtString(variantModel.item_model))
477+
.set(
492478
'minecraft:custom_model_data',
493-
new NbtInt(variantModel.custom_model_data)
494-
)
495-
)
496-
break
497-
}
498-
case '1.21.2': {
499-
item.set(
500-
'components',
501-
new NbtCompound().set(
502-
'minecraft:item_model',
503-
new NbtString(variantModel.item_model)
479+
new NbtCompound().set(
480+
'strings',
481+
new NbtList([new NbtString('default')])
482+
)
504483
)
484+
)
485+
} else if (!compareVersions('1.21.2', version) /* >= 1.21.2 */) {
486+
item.set(
487+
'components',
488+
new NbtCompound().set(
489+
'minecraft:item_model',
490+
new NbtString(variantModel.item_model)
505491
)
506-
break
507-
}
508-
case '1.21.4':
509-
case '1.21.5': {
510-
item.set(
511-
'components',
512-
new NbtCompound()
513-
.set('minecraft:item_model', new NbtString(variantModel.item_model))
514-
.set(
515-
'minecraft:custom_model_data',
516-
new NbtCompound().set(
517-
'strings',
518-
new NbtList([new NbtString('default')])
519-
)
520-
)
492+
)
493+
} else if (!compareVersions('1.20.5', version) /* >= 1.20.5 */) {
494+
item.set(
495+
'components',
496+
new NbtCompound().set(
497+
'minecraft:custom_model_data',
498+
new NbtInt(variantModel.custom_model_data)
521499
)
522-
break
523-
}
524-
default: {
525-
throw new Error(
526-
`Unsupported Minecraft version '${version}' for item display!`
500+
)
501+
} else if (!compareVersions('1.20.4', version) /* >= 1.20.4 */) {
502+
item.set(
503+
'tag',
504+
new NbtCompound().set(
505+
'CustomModelData',
506+
new NbtInt(variantModel.custom_model_data)
527507
)
528-
}
508+
)
509+
// `Count` does not default to 1.
510+
// However, `count` does default to 1 in later versions, so we only need this for 1.20.4.
511+
item.set('Count', new NbtInt(1))
529512
}
530513

531514
if (node.configs?.default) {
@@ -577,24 +560,10 @@ async function generateRootEntityPassengers(
577560
.set('item', item)
578561
.set('item_display', new NbtString(node.item_display))
579562

580-
switch (version) {
581-
case '1.20.4': {
582-
// `Count` does not default to 1.
583-
item.set('Count', new NbtInt(1))
584-
break
585-
}
586-
case '1.20.5':
587-
case '1.21.2':
588-
case '1.21.4':
589-
case '1.21.5': {
590-
// `count` defaults to 1, so we can omit it.
591-
break
592-
}
593-
default: {
594-
throw new Error(
595-
`Unsupported Minecraft version '${version}' for item display!`
596-
)
597-
}
563+
if (compareVersions(version, '1.20.4') /* <= 1.20.4 */) {
564+
// `Count` does not default to 1 in 1.20.4.
565+
item.set('Count', new NbtInt(1))
566+
break
598567
}
599568

600569
if (node.config) {
@@ -827,7 +796,21 @@ export default async function compileDataPack(
827796
const packMetaPath = PathModule.join(options.dataPackFolder, 'pack.mcmeta')
828797
const packMeta = PackMeta.fromFile(packMetaPath)
829798
packMeta.content.pack ??= {}
830-
packMeta.content.pack.pack_format = getDataPackFormat(targetVersions[0])
799+
800+
const nextVersion = getNextSupportedVersion(targetVersions[0])
801+
const format = getDataPackFormat(targetVersions[0])
802+
const nextFormat = nextVersion ? getDataPackFormat(nextVersion) : 10000000
803+
if (!compareVersions('1.21.9', targetVersions[0]) /* >= 1.21.9 */) {
804+
packMeta.content.pack.min_format = format
805+
packMeta.content.pack.max_format = nextFormat - 1
806+
} else {
807+
packMeta.content.pack.pack_format = format
808+
packMeta.content.pack.supported_formats = {
809+
min_inclusive: format,
810+
max_inclusive: nextFormat - 1,
811+
}
812+
}
813+
831814
packMeta.content.pack.description ??= `Animated Java Data Pack for ${targetVersions.join(', ')}`
832815

833816
// if (targetVersions.length > 1) {

src/systems/global.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import { IntentionalExportError, IntentionalExportErrorFromInvalidFile } from '.
33
import { sortObjectKeys } from './util'
44

55
export enum SUPPORTED_MINECRAFT_VERSIONS {
6-
'1.21.9' = '1.21.9',
7-
'1.21.6' = '1.21.6',
8-
'1.21.5' = '1.21.5',
9-
'1.21.4' = '1.21.4',
10-
'1.21.2' = '1.21.2',
11-
'1.20.5' = '1.20.5',
126
'1.20.4' = '1.20.4',
7+
'1.20.5' = '1.20.5',
8+
'1.21.2' = '1.21.2',
9+
'1.21.4' = '1.21.4',
10+
'1.21.5' = '1.21.5',
11+
'1.21.6' = '1.21.6',
12+
'1.21.9' = '1.21.9',
1313
}
1414

1515
type OldSerializedAJMeta = Record<
@@ -126,7 +126,7 @@ export interface SerializedPackMeta {
126126
pack?: {
127127
pack_format?: number
128128
/** Minecraft enforces this field does not to exist if the pack doesn't support versions older than 1.21.9 */
129-
supported_formats?: PackMetaFormats[]
129+
supported_formats?: PackMetaFormats
130130
description?: string
131131
// Below since 1.21.9
132132
min_format?: number

src/systems/minecraft/fontManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,7 @@ export class MinecraftFont {
381381
return material
382382
}
383383

384+
// TODO - Add support for rendering object text components
384385
async generateTextDisplayMesh({
385386
jsonText,
386387
maxLineWidth = TextDisplay.properties.maxLineWidth.default,

src/systems/resourcepackCompiler/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MAX_PROGRESS, PROGRESS, PROGRESS_DESCRIPTION } from '../../interface/dialog/exportProgress'
2-
import { getResourcePackFormat } from '../../util/minecraftUtil'
2+
import { getNextSupportedVersion, getResourcePackFormat } from '../../util/minecraftUtil'
33
import { IntentionalExportError } from '../exporter'
44
import { type IRenderedRig } from '../rigRenderer'
55
import type { ExportedFile } from '../util'
@@ -109,7 +109,21 @@ export default async function compileResourcePack(
109109
const packMetaPath = PathModule.join(options.resourcePackFolder, 'pack.mcmeta')
110110
const packMeta = PackMeta.fromFile(packMetaPath)
111111
packMeta.content.pack ??= {}
112-
packMeta.content.pack.pack_format = getResourcePackFormat(targetVersions[0])
112+
113+
const nextVersion = getNextSupportedVersion(targetVersions[0])
114+
const format = getResourcePackFormat(targetVersions[0])
115+
const nextFormat = nextVersion ? getResourcePackFormat(nextVersion) : 10000000
116+
if (!compareVersions('1.21.9', targetVersions[0]) /* >= 1.21.9 */) {
117+
packMeta.content.pack.min_format = format
118+
packMeta.content.pack.max_format = nextFormat - 1
119+
} else {
120+
packMeta.content.pack.pack_format = format
121+
packMeta.content.pack.supported_formats = {
122+
min_inclusive: format,
123+
max_inclusive: nextFormat - 1,
124+
}
125+
}
126+
113127
packMeta.content.pack.description ??= `Animated Java Resource Pack for ${targetVersions.join(
114128
', '
115129
)}`

src/util/minecraftUtil.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,15 @@ export function getResourcePackFormat(version: SUPPORTED_MINECRAFT_VERSIONS): nu
335335
}
336336
}
337337

338+
export function getNextSupportedVersion(
339+
version: SUPPORTED_MINECRAFT_VERSIONS
340+
): SUPPORTED_MINECRAFT_VERSIONS | undefined {
341+
const versions = Object.values(SUPPORTED_MINECRAFT_VERSIONS)
342+
const index = versions.indexOf(version)
343+
if (index === -1 || index === versions.length - 1) return undefined
344+
return versions[index + 1]
345+
}
346+
338347
export function functionReferenceExists(dataPackRoot: string, resourceLocation: string): boolean {
339348
const parsed = parseResourceLocation(resourceLocation)
340349
if (!parsed) return false

0 commit comments

Comments
 (0)