Fetch registries from mcdata

This commit is contained in:
Misode
2020-06-15 15:16:02 +02:00
parent 9ad4e5bb39
commit 2d29de7903
3 changed files with 70 additions and 51 deletions

View File

@@ -0,0 +1,11 @@
import { CollectionRegistry } from "minecraft-schemas";
export const mcdata = (version: string, registry: string) => `https://raw.githubusercontent.com/Arcensoth/mcdata/${version}/processed/reports/registries/${registry}/${registry}.min.json`
export const RegistryFetcher = async (target: CollectionRegistry, registries: string[], version = 'master') => {
await Promise.all(registries.map(async r => {
const res = await fetch(mcdata(version, r))
const data = await res.json()
target.register(r, data.values)
}))
}

View File

@@ -1,57 +1,46 @@
import {
ObjectNode,
EnumNode,
StringNode,
NumberNode,
BooleanNode,
RangeNode,
EnumNode,
NumberNode,
ObjectNode,
ListNode,
MapNode,
ListNode
Switch,
Case,
Reference,
JsonNode,
RangeNode,
Resource,
SCHEMAS
} from 'minecraft-schemas'
const EntityCollection = ['sheep', 'pig']
export const SandboxSchema = new ObjectNode({
condition: new EnumNode(['foo', 'bar'], {
default: () => 'bar'
}),
number: new NumberNode({integer: false, min: 0}),
range: new RangeNode({
enable: (path) => path.push('condition').get() === 'foo'
}),
predicate: new ObjectNode({
type: new EnumNode(EntityCollection),
nbt: new StringNode({
default: (v) => 'hahaha'
}),
test: new BooleanNode({force: () => true}),
recipes: new MapNode(
new StringNode(),
new RangeNode({
default: (v) => RangeNode.isExact(v) ? 2 : v,
transform: (v: any) => RangeNode.isRange(v) ? ({
min: v?.min ?? -2147483648,
max: v?.max ?? 2147483647
}) : v
})
)
}),
effects: new ListNode(
new ObjectNode({
type: new EnumNode(EntityCollection),
nbt: new StringNode()
}, {
default: () => ({
type: 'sheep'
})
SCHEMAS.register('foo', ObjectNode({
foo: StringNode(),
bar: BooleanNode({ radio: true }),
nested: ObjectNode({
baz: NumberNode({ min: 1 }),
range: RangeNode()
}, { collapse: true }),
arr: ListNode(
ObjectNode({
aaa: StringNode(),
bbb: JsonNode()
})
)
}, {
default: () => ({
condition: 'foo',
predicate: {
nbt: 'hi'
),
map: MapNode(
EnumNode(['pig', 'sheep']),
Resource(StringNode())
),
recursive: ListNode(
Reference('foo')
),
[Switch]: path => path.push('foo').get(),
[Case]: {
'blah': {
haha: StringNode()
}
}),
transform: (v: any) => v?.condition === 'foo' ? ({...v, test: 'hello'}) : v
});
}
}))
export const SandboxSchema = SCHEMAS.get('foo')

View File

@@ -1,3 +1,4 @@
import { RegistryFetcher } from './RegistryFetcher'
import {
DataModel,
IView,
@@ -9,7 +10,8 @@ import {
DimensionSchema,
DimensionTypeSchema,
LOCALES,
locale
locale,
COLLECTIONS
} from 'minecraft-schemas'
import Split from 'split.js'
@@ -33,10 +35,27 @@ const languages: { [key: string]: string } = {
'zh-CN': '简体中文'
}
const registries = [
'attribute',
'biome',
'biome_source',
'block',
'enchantment',
'entity_type',
'fluid',
'item',
'loot_condition_type',
'loot_function_type',
'loot_pool_entry_type',
'stat_type',
'structure_feature'
]
const publicPath = process.env.NODE_ENV === 'production' ? '/dev/' : '/';
Promise.all([
fetch(publicPath + 'locales/schema/en.json').then(r => r.json()),
fetch(publicPath + 'locales/app/en.json').then(r => r.json())
fetch(publicPath + 'locales/app/en.json').then(r => r.json()),
RegistryFetcher(COLLECTIONS, registries)
]).then(responses => {
LOCALES.register('en', {...responses[0], ...responses[1]})