diff --git a/__snapshots__/packages/java-edition/test-out/binder/index.spec.js b/__snapshots__/packages/java-edition/test-out/binder/index.spec.js index 96f6b6555..340650c98 100644 --- a/__snapshots__/packages/java-edition/test-out/binder/index.spec.js +++ b/__snapshots__/packages/java-edition/test-out/binder/index.spec.js @@ -7,6 +7,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/advancements/data/foo/ "path": "advancements", "category": "advancement", "ext": ".json", + "pack": "data", "until": "1.21", "namespace": "minecraft", "identifier": "data/foo/predicates/bar" @@ -21,6 +22,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/loot_table/foo.json" i "path": "loot_table", "category": "loot_table", "ext": ".json", + "pack": "data", "since": "1.21", "namespace": "minecraft", "identifier": "foo" @@ -31,6 +33,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/loot_tables/foo.json" "path": "loot_tables", "category": "loot_table", "ext": ".json", + "pack": "data", "until": "1.21", "namespace": "minecraft", "identifier": "foo" @@ -41,6 +44,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/tags/block/bar.json" 1 "path": "tags/block", "category": "tag/block", "ext": ".json", + "pack": "data", "since": "1.21", "namespace": "minecraft", "identifier": "bar", @@ -52,6 +56,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/tags/block/bar.json" i "path": "tags/block", "category": "tag/block", "ext": ".json", + "pack": "data", "since": "1.21", "namespace": "minecraft", "identifier": "bar" @@ -62,6 +67,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/tags/blocks/bar.json" "path": "tags/blocks", "category": "tag/block", "ext": ".json", + "pack": "data", "until": "1.21", "namespace": "minecraft", "identifier": "bar" @@ -72,6 +78,7 @@ exports['dissectUri() Dissect Uri "file:///data/minecraft/tags/blocks/bar.json" "path": "tags/blocks", "category": "tag/block", "ext": ".json", + "pack": "data", "until": "1.21", "namespace": "minecraft", "identifier": "bar", @@ -83,6 +90,7 @@ exports['dissectUri() Dissect Uri "file:///data/qux/dimension/foo/baz.json" in 1 "path": "dimension", "category": "dimension", "ext": ".json", + "pack": "data", "since": "1.16", "namespace": "qux", "identifier": "foo/baz" @@ -97,6 +105,7 @@ exports['dissectUri() with customResources Dissect Uri "file:///data/minecraft/a "path": "advancement", "category": "advancement", "ext": ".json", + "pack": "data", "since": "1.21", "namespace": "minecraft", "identifier": "foo" @@ -107,6 +116,7 @@ exports['dissectUri() with customResources Dissect Uri "file:///data/minecraft/l "path": "loot_tables", "category": "loot_table", "ext": ".json", + "pack": "data", "until": "1.21", "namespace": "minecraft", "identifier": "foo" @@ -117,6 +127,7 @@ exports['dissectUri() with customResources Dissect Uri "file:///data/qux/biome_m "path": "biome_modifiers", "category": "fabric:biome_modifier", "ext": ".json", + "pack": "data", "namespace": "qux", "identifier": "snowy" } @@ -126,6 +137,7 @@ exports['dissectUri() with customResources Dissect Uri "file:///data/qux/tags/cu "path": "tags/custom_registry", "category": "tag/custom_registry", "ext": ".json", + "pack": "data", "namespace": "qux", "identifier": "nested/bar" } diff --git a/packages/core/src/symbol/Symbol.ts b/packages/core/src/symbol/Symbol.ts index 33fa51231..a32486ed3 100644 --- a/packages/core/src/symbol/Symbol.ts +++ b/packages/core/src/symbol/Symbol.ts @@ -170,10 +170,10 @@ export const TagFileCategories = Object.freeze( ) export type TagFileCategory = (typeof TagFileCategories)[number] -export const FileCategories = Object.freeze( +export const DataFileCategories = Object.freeze( [...NormalFileCategories, ...TagFileCategories, ...WorldgenFileCategories] as const, ) -export type FileCategory = (typeof FileCategories)[number] +export type DataFileCategory = (typeof DataFileCategories)[number] export const MiscCategories = Object.freeze( [ @@ -193,15 +193,50 @@ export const DatapackCategories = Object.freeze( 'score_holder', 'tag', 'team', - ...FileCategories, + ...DataFileCategories, ...MiscCategories, ] as const, ) export type DatapackCategory = (typeof DatapackCategories)[number] // #endregion +// #region Resource Pack Categories +export const AssetsFileCategories = Object.freeze( + [ + 'atlas', + 'block_definition', // blockstates + 'font', + 'lang', + 'model', + 'particle', + 'post_effect', + 'shader', + 'sound', + 'texture', + ] as const, +) +export type AssetsFileCategory = (typeof AssetsFileCategories)[number] + +export const ResourcepackCategories = Object.freeze( + [ + ...AssetsFileCategories, + ] as const, +) +export type ResourcepackCategory = (typeof ResourcepackCategories)[number] +// #endregion + +export const FileCategories = Object.freeze( + [...DataFileCategories, ...AssetsFileCategories] as const, +) +export type FileCategory = (typeof FileCategories)[number] + export const AllCategories = Object.freeze( - [...DatapackCategories, ...McdocCategories, ...RegistryCategories] as const, + [ + ...DatapackCategories, + ...ResourcepackCategories, + ...McdocCategories, + ...RegistryCategories, + ] as const, ) export type AllCategory = (typeof AllCategories)[number] diff --git a/packages/java-edition/src/binder/index.ts b/packages/java-edition/src/binder/index.ts index 6a73821c2..8a0893524 100644 --- a/packages/java-edition/src/binder/index.ts +++ b/packages/java-edition/src/binder/index.ts @@ -20,6 +20,7 @@ interface Resource { path: string category: FileCategory ext: `.${string}` + pack: 'data' | 'assets' since?: ReleaseVersion until?: ReleaseVersion } @@ -33,6 +34,7 @@ function resource(path: string, resource: Partial = {}) { path, category: resource.category ?? path as FileCategory, ext: resource.ext ?? '.json', + pack: resource.pack ?? 'data', ...resource, }) } @@ -120,6 +122,18 @@ for (const registry of TaggableResourceLocationCategories) { resource(`tags/${registry}`, { category: `tag/${registry}`, since: '1.18' }) } +// Resource pack +resource('atlases', { pack: 'assets', category: 'atlas', since: '1.19.3' }) +resource('blockstates', { pack: 'assets', category: 'block_definition' }) +resource('fonts', { pack: 'assets', category: 'font', since: '1.16' }) +resource('lang', { pack: 'assets', category: 'lang' }) +resource('models', { pack: 'assets', category: 'model' }) +resource('particles', { pack: 'assets', category: 'particle' }) +resource('post_effect', { pack: 'assets' }) +resource('shaders', { pack: 'assets', category: 'shader' }) // TODO: support other extensions +resource('sounds', { pack: 'assets', category: 'sound', ext: '.ogg' }) +resource('textures', { pack: 'assets', category: 'texture', ext: '.png' }) + export function* getRels( uri: string, rootUris: readonly RootUriString[], @@ -128,7 +142,7 @@ export function* getRels( const parts = uri.split('/') for (let i = parts.length - 2; i >= 0; i--) { - if (parts[i] === 'data') { // TODO: support assets + if (parts[i] === 'data' || parts[i] === 'assets') { yield parts.slice(i).join('/') } } @@ -149,8 +163,8 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { continue } const [pack, namespace, ...rest] = parts - if (pack !== 'data') { - continue // TODO: support assets + if (pack !== 'data' && pack !== 'assets') { + continue } let resource: Resource | undefined = undefined let matchIndex = 0 @@ -164,6 +178,9 @@ export function dissectUri(uri: string, ctx: UriBinderContext) { if (!resource) { continue } + if (resource.pack !== pack) { + continue + } let identifier = rest.slice(matchIndex).join('/') if (!identifier.endsWith(resource.ext)) { continue