mirror of
https://github.com/misode/misode.github.io.git
synced 2026-04-30 01:32:44 +00:00
Update loot table preview, item display and tooltips to 1.21
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NbtByte, NbtCompound, NbtDouble, NbtInt, NbtList, NbtString, NbtTag } from 'deepslate'
|
||||
import { NbtTag } from 'deepslate'
|
||||
import yaml from 'js-yaml'
|
||||
import { Store } from '../Store.js'
|
||||
import { jsonToNbt } from '../Utils.js'
|
||||
|
||||
const INDENTS: Record<string, number | string | undefined> = {
|
||||
'2_spaces': 2,
|
||||
@@ -40,28 +41,6 @@ const FORMATS: Record<string, {
|
||||
},
|
||||
}
|
||||
|
||||
function jsonToNbt(value: unknown): NbtTag {
|
||||
if (typeof value === 'string') {
|
||||
return new NbtString(value)
|
||||
}
|
||||
if (typeof value === 'number') {
|
||||
return Number.isInteger(value) ? new NbtInt(value) : new NbtDouble(value)
|
||||
}
|
||||
if (typeof value === 'boolean') {
|
||||
return new NbtByte(value)
|
||||
}
|
||||
if (Array.isArray(value)) {
|
||||
return new NbtList(value.map(jsonToNbt))
|
||||
}
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
return new NbtCompound(
|
||||
new Map(Object.entries(value ?? {})
|
||||
.map(([k, v]) => [k, jsonToNbt(v)]))
|
||||
)
|
||||
}
|
||||
throw new Error(`Could not convert ${value} to NBT`)
|
||||
}
|
||||
|
||||
export function stringifySource(data: unknown, format?: string, indent?: string) {
|
||||
return FORMATS[format ?? Store.getFormat()].stringify(data, INDENTS[indent ?? Store.getIndent()])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user