Skip to content

Commit

Permalink
🐛 Add support for 25w03a (#1719)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored Jan 15, 2025
1 parent f301ba9 commit 7035f51
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 24 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/symbol/Symbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ export const RegistryCategories = Object.freeze(
'slot_display',
'sound_event',
'stat_type',
'test_environment_definition_type',
'test_function',
'test_instance_type',
'trigger_type',
'villager_profession',
'villager_type',
Expand Down Expand Up @@ -129,6 +132,8 @@ export const NormalFileCategories = Object.freeze(
'predicate',
'recipe',
'structure',
'test_environment',
'test_instance',
'trial_spawner',
'trim_material',
'trim_pattern',
Expand Down
2 changes: 2 additions & 0 deletions packages/java-edition/src/binder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ resource('instrument', { since: '1.21.2' })
resource('jukebox_song', { since: '1.21' })
resource('painting_variant', { since: '1.21' })
resource('pig_variant', { since: '1.21.5' })
resource('test_instance', { since: '1.21.5' })
resource('test_environment', { since: '1.21.5' })
resource('trial_spawner', { since: '1.21.2' })
resource('trim_pattern', { since: '1.19.4' })
resource('trim_material', { since: '1.19.4' })
Expand Down
3 changes: 2 additions & 1 deletion packages/java-edition/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ export const initialize: core.ProjectInitializer = async (ctx) => {
&& !n.symbol?.path[0]?.startsWith('::minecraft')),
})

registerMcdocAttributes(meta, release)
registerMcdocAttributes(meta, summary.commands, release)
registerPackFormatAttribute(meta, release, versions, packs)
registerPackFormatAttribute(meta, release, versions, packs)

meta.registerLanguage('zip', { extensions: ['.zip'] })
Expand Down
72 changes: 50 additions & 22 deletions packages/java-edition/src/mcdocAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ import * as core from '@spyglassmc/core'
import { localize } from '@spyglassmc/locales'
import * as mcdoc from '@spyglassmc/mcdoc'
import { NEXT_RELEASE_VERSION, ReleaseVersion } from './dependency/index.js'
import type { McmetaVersions, PackInfo } from './dependency/index.js'
import type { McmetaCommands, McmetaVersions, PackInfo } from './dependency/index.js'

export function registerMcdocAttributes(meta: core.MetaRegistry, release: ReleaseVersion) {
mcdoc.runtime.registerAttribute(meta, 'since', mcdoc.runtime.attribute.validator.string, {
const validator = mcdoc.runtime.attribute.validator

const gameRuleValidator = validator.tree({
type: validator.options('boolean', 'int'),
})

export function registerMcdocAttributes(
meta: core.MetaRegistry,
commands: McmetaCommands,
release: ReleaseVersion,
) {
mcdoc.runtime.registerAttribute(meta, 'since', validator.string, {
filterElement: (config, ctx) => {
if (!config.startsWith('1.')) {
ctx.logger.warn(`Invalid mcdoc attribute for "since": ${config}`)
Expand All @@ -14,7 +24,7 @@ export function registerMcdocAttributes(meta: core.MetaRegistry, release: Releas
return ReleaseVersion.cmp(release, config as ReleaseVersion) >= 0
},
})
mcdoc.runtime.registerAttribute(meta, 'until', mcdoc.runtime.attribute.validator.string, {
mcdoc.runtime.registerAttribute(meta, 'until', validator.string, {
filterElement: (config, ctx) => {
if (!config.startsWith('1.')) {
ctx.logger.warn(`Invalid mcdoc attribute for "until": ${config}`)
Expand All @@ -23,26 +33,44 @@ export function registerMcdocAttributes(meta: core.MetaRegistry, release: Releas
return ReleaseVersion.cmp(release, config as ReleaseVersion) < 0
},
})
mcdoc.runtime.registerAttribute(
meta,
'deprecated',
mcdoc.runtime.attribute.validator.optional(mcdoc.runtime.attribute.validator.string),
{
mapField: (config, field, ctx) => {
if (config === undefined) {
return { ...field, deprecated: true }
}
if (!config.startsWith('1.')) {
ctx.logger.warn(`Invalid mcdoc attribute for "deprecated": ${config}`)
return field
}
if (ReleaseVersion.cmp(release, config as ReleaseVersion) >= 0) {
return { ...field, deprecated: true }
}
mcdoc.runtime.registerAttribute(meta, 'deprecated', validator.optional(validator.string), {
mapField: (config, field, ctx) => {
if (config === undefined) {
return { ...field, deprecated: true }
}
if (!config.startsWith('1.')) {
ctx.logger.warn(`Invalid mcdoc attribute for "deprecated": ${config}`)
return field
},
}
if (ReleaseVersion.cmp(release, config as ReleaseVersion) >= 0) {
return { ...field, deprecated: true }
}
return field
},
)
})
const gameRuleNode = commands.children.gamerule?.children
if (gameRuleNode) {
const [boolGameRules, intGameRules] = ['brigadier:bool', 'brigadier:integer'].map((type) =>
Object.entries(gameRuleNode).flatMap(([key, node]) =>
node.children?.value?.type === 'argument' && node.children.value.parser === type
? [key]
: []
)
)
mcdoc.runtime.registerAttribute(meta, 'game_rule', gameRuleValidator, {
stringParser: (config, _, ctx) => {
return core.literal({
pool: config.type === 'boolean' ? boolGameRules : intGameRules,
colorTokenType: 'string',
})
},
stringMocker: (config, _, ctx) => {
return core.LiteralNode.mock(ctx.offset, {
pool: config.type === 'boolean' ? boolGameRules : intGameRules,
})
},
})
}
}

export function registerPackFormatAttribute(
Expand Down
6 changes: 5 additions & 1 deletion packages/java-edition/src/mcfunction/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function getItemSlotArgumentValues(ctx: core.ContextBase) {
'armor.head',
'armor.legs',
'horse.chest',
'horse.saddle',
'weapon',
'weapon.mainhand',
'weapon.offhand',
Expand All @@ -36,6 +35,11 @@ export function getItemSlotArgumentValues(ctx: core.ContextBase) {
} else {
output.push('horse.armor')
}
if (ReleaseVersion.cmp(release, '1.21.5') >= 0) {
output.push('saddle')
} else {
output.push('horse.saddle')
}
return output
}

Expand Down
2 changes: 2 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@
"data/*/recipe/**/*.json",
"data/*/recipes/**/*.json",
"data/*/tags/**/*.json",
"data/*/test_instance/**/*.json",
"data/*/test_environment/**/*.json",
"data/*/trim_material/**/*.json",
"data/*/trim_pattern/**/*.json",
"data/*/wolf_variant/**/*.json",
Expand Down

0 comments on commit 7035f51

Please sign in to comment.