Skip to content

Commit

Permalink
✨ Implement mcdoc:block_states and mcdoc:block_state_keys (#1641)
Browse files Browse the repository at this point in the history
  • Loading branch information
misode authored Nov 22, 2024
1 parent 162d997 commit 6e0e705
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.

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

49 changes: 49 additions & 0 deletions packages/java-edition/src/dependency/mcmeta.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@spyglassmc/core'
import type { TypeDefSymbolData } from '@spyglassmc/mcdoc/lib/binder/index.js'
import type { PackMcmeta, ReleaseVersion, VersionInfo } from './common.js'

/**
Expand Down Expand Up @@ -160,6 +161,54 @@ export function symbolRegistrar(summary: McmetaSummary): core.SymbolRegistrar {
},
)
}

symbols.query(McmetaSummaryUri, 'mcdoc/dispatcher', 'mcdoc:block_states').enter({
usage: { type: 'declaration' },
}).onEach(Object.entries(summary.blocks), ([id, [properties]], blockQuery) => {
const data: TypeDefSymbolData = {
typeDef: {
kind: 'struct',
fields: Object.entries(properties).map(([propKey, propValues]) => ({
kind: 'pair',
key: propKey,
optional: true,
type: {
kind: 'union',
members: propValues.map(value => ({
kind: 'literal',
value: { kind: 'string', value },
})),
},
})),
},
}
blockQuery.member(id, (stateQuery) => {
stateQuery.enter({
data: { data },
usage: { type: 'declaration' },
})
})
})

symbols.query(McmetaSummaryUri, 'mcdoc/dispatcher', 'mcdoc:block_state_keys').enter({
usage: { type: 'declaration' },
}).onEach(Object.entries(summary.blocks), ([id, [properties]], blockQuery) => {
const data: TypeDefSymbolData = {
typeDef: {
kind: 'union',
members: Object.keys(properties).map(propKey => ({
kind: 'literal',
value: { kind: 'string', value: propKey },
})),
},
}
blockQuery.member(id, (stateQuery) => {
stateQuery.enter({
data: { data },
usage: { type: 'declaration' },
})
})
})
}

function addRegistriesSymbols(registries: McmetaRegistries, symbols: core.SymbolUtil) {
Expand Down

0 comments on commit 6e0e705

Please sign in to comment.