mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-24 23:56:51 +00:00
Add block state validation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { Identifier } from 'deepslate'
|
||||
import type { BlockStateData } from '../../services/DataFetcher.js'
|
||||
import { fetchAllPresets, fetchBlockStates } from '../../services/DataFetcher.js'
|
||||
import type { VersionId } from '../../services/Versions.js'
|
||||
import { deepClone, deepEqual } from '../../Utils.js'
|
||||
@@ -17,7 +18,7 @@ interface Context {
|
||||
model: CustomizedModel,
|
||||
initial: CustomizedModel,
|
||||
version: VersionId,
|
||||
blockStates: Map<string, {properties: Record<string, string[]>, default: Record<string, string>}>,
|
||||
blockStates: Map<string, BlockStateData>,
|
||||
vanilla: CustomizedPack,
|
||||
out: CustomizedPack,
|
||||
featureCollisionIndex: number,
|
||||
@@ -77,7 +78,7 @@ function generateNoiseSettings(ctx: Context) {
|
||||
sea_level: ctx.model.seaLevel,
|
||||
default_fluid: {
|
||||
Name: defaultFluid,
|
||||
Properties: ctx.blockStates.get(defaultFluid)?.default,
|
||||
Properties: ctx.blockStates.get(defaultFluid.replace(/^minecraft:/, ''))?.[1],
|
||||
},
|
||||
noise: {
|
||||
...vanilla.noise,
|
||||
|
||||
@@ -81,10 +81,7 @@ export async function fetchRegistries(versionId: VersionId) {
|
||||
}
|
||||
}
|
||||
|
||||
export interface BlockStateData {
|
||||
properties: Record<string, string[]>
|
||||
default: Record<string, string>
|
||||
}
|
||||
export type BlockStateData = [Record<string, string[]>, Record<string, string>]
|
||||
|
||||
export async function fetchBlockStates(versionId: VersionId) {
|
||||
console.debug(`[fetchBlockStates] ${versionId}`)
|
||||
@@ -94,10 +91,7 @@ export async function fetchBlockStates(versionId: VersionId) {
|
||||
try {
|
||||
const data = await cachedFetch<any>(`${mcmeta(version, 'summary')}/blocks/data.min.json`)
|
||||
for (const id in data) {
|
||||
result.set('minecraft:' + id, {
|
||||
properties: data[id][0],
|
||||
default: data[id][1],
|
||||
})
|
||||
result.set(id, data[id])
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Error occurred while fetching block states:', message(e))
|
||||
|
||||
@@ -319,16 +319,48 @@ const initialize: core.ProjectInitializer = async (ctx) => {
|
||||
const summary: McmetaSummary = {
|
||||
registries: Object.fromEntries((await fetchRegistries(version.id)).entries()),
|
||||
blocks: Object.fromEntries([...(await fetchBlockStates(version.id)).entries()]
|
||||
.map(([id, data]) => [id, [data.properties, data.default]])),
|
||||
.map(([id, data]) => [id, data])),
|
||||
fluids: Fluids,
|
||||
commands: { type: 'root', children: {} },
|
||||
}
|
||||
|
||||
const versionChecksum = getVersionChecksum(version.id)
|
||||
|
||||
meta.registerSymbolRegistrar('mcmeta-summary', {
|
||||
checksum: getVersionChecksum(version.id),
|
||||
checksum: versionChecksum,
|
||||
registrar: symbolRegistrar(summary),
|
||||
})
|
||||
|
||||
meta.registerSymbolRegistrar('mcdoc-block-states', {
|
||||
checksum: versionChecksum,
|
||||
registrar: (symbols) => {
|
||||
const uri = 'mcmeta://summary/block_states.json'
|
||||
symbols.query(uri, 'mcdoc/dispatcher', 'mcdoc:block_states').enter({
|
||||
usage: { type: 'declaration' },
|
||||
}).onEach(Object.entries(summary.blocks), ([id, [properties]], blockQuery) => {
|
||||
const data: mcdoc.binder.TypeDefSymbolData = { typeDef: {
|
||||
kind: 'struct',
|
||||
fields: Object.entries(properties).map(([propKey, propValues]) => ({
|
||||
kind: 'pair',
|
||||
key: propKey,
|
||||
type: {
|
||||
kind: 'union',
|
||||
members: propValues.map(value => ({
|
||||
kind: 'literal', value: { kind: 'string', value },
|
||||
})),
|
||||
},
|
||||
})),
|
||||
} }
|
||||
blockQuery.member(id, (stateQuery) => {
|
||||
stateQuery.enter({
|
||||
data: { data },
|
||||
usage: { type: 'declaration' },
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
registerAttributes(meta, release, versions)
|
||||
|
||||
json.initialize(ctx)
|
||||
|
||||
Reference in New Issue
Block a user