Support 1.15

This commit is contained in:
Misode
2020-12-19 17:58:21 +01:00
parent b2c963005f
commit 25ff5d03f1
7 changed files with 130 additions and 68 deletions

8
package-lock.json generated
View File

@@ -9,6 +9,14 @@
"resolved": "https://registry.npmjs.org/@mcschema/core/-/core-0.11.7.tgz",
"integrity": "sha512-1N+krHwQpkmPCIqxxYL80NoOzZI1du12mX+d7dlYb8h7nfr4Rvv+ID5HTITxgCL1jVEN1DOMZK7swic2RuDivA=="
},
"@mcschema/java-1.15": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/@mcschema/java-1.15/-/java-1.15-0.1.1.tgz",
"integrity": "sha512-NS65iqMiQyuywThJCBs4/zc5Fq5sbXb19n6c5pdx4KQlVP2V/fOB+MS0CvKEtVJKwFt9koBRdvK56BTlx9OK9w==",
"requires": {
"@mcschema/core": "^0.11.2"
}
},
"@mcschema/java-1.16": {
"version": "0.5.15",
"resolved": "https://registry.npmjs.org/@mcschema/java-1.16/-/java-1.16-0.5.15.tgz",

View File

@@ -13,6 +13,7 @@
"license": "MIT",
"dependencies": {
"@mcschema/core": "^0.11.7",
"@mcschema/java-1.15": "^0.1.1",
"@mcschema/java-1.16": "^0.5.15",
"@mcschema/java-1.17": "^0.1.9",
"@mcschema/locales": "^0.1.15",

View File

@@ -1,4 +1,5 @@
import { CollectionRegistry, DataModel, ObjectNode, SchemaRegistry } from '@mcschema/core';
import * as java15 from '@mcschema/java-1.15'
import * as java16 from '@mcschema/java-1.16'
import * as java17 from '@mcschema/java-1.17'
import { LocalStorageProperty } from './state/LocalStorageProperty';
@@ -19,6 +20,7 @@ const Versions: {
getSchemas: (collections: CollectionRegistry) => SchemaRegistry,
}
} = {
'1.15': java15,
'1.16': java16,
'1.17': java17
}
@@ -98,7 +100,7 @@ async function updateSchemas(version: string) {
const schemas = Versions[version].getSchemas(collections)
config.models
.filter(m => m.schema)
.filter(m => checkVersion(App.version.get(), m.minVersion ?? config.versions[0].id))
.filter(m => checkVersion(App.version.get(), m.minVersion))
.forEach(m => {
const model = Models[m.id]
const schema = schemas.get(m.schema!)
@@ -120,10 +122,11 @@ async function updateLocale(language: string) {
Locales[language] = data
}
export function checkVersion(versionId: string, minVersionId: string) {
export function checkVersion(versionId: string, minVersionId: string | undefined, maxVersionId?: string) {
const version = config.versions.findIndex(v => v.id === versionId)
const minVersion = config.versions.findIndex(v => v.id === minVersionId)
return minVersion <= version
const minVersion = minVersionId ? config.versions.findIndex(v => v.id === minVersionId) : 0
const maxVersion = maxVersionId ? config.versions.findIndex(v => v.id === maxVersionId) : config.versions.length - 1
return minVersion <= version && version <= maxVersion
}
document.addEventListener('keyup', (evt) => {

View File

@@ -2,6 +2,13 @@ import { CollectionRegistry } from '@mcschema/core'
import { checkVersion } from './App'
import config from '../config.json'
type RegistryConfig = {
id: string
minVersion?: string
maxVersion?: string
path?: string
}
const localStorageCache = (version: string) => `cache_${version}`
declare var __MCDATA_MASTER_HASH__: string;
@@ -18,36 +25,62 @@ export const RegistryFetcher = async (target: CollectionRegistry, versionId: str
const cacheValid = version.mcdata_ref !== 'master' || cache.mcdata_hash === __MCDATA_MASTER_HASH__
let cacheDirty = false
await Promise.all(config.registries.map(async r => {
const id = typeof r === 'string' ? r : r.id
if (checkVersion('1.15', versionId)) {
const url = `${baseUrl}/${version.mcdata_ref}/generated/reports/registries.json`
if (cacheValid && cache.registries) {
config.registries.forEach((r: string | RegistryConfig) => {
if (typeof r === 'string') r = { id: r }
if (!checkVersion(versionId, r.minVersion, r.maxVersion)) return
if (typeof r !== 'string' && r.minVersion) {
if (!checkVersion(versionId, r.minVersion)) return
target.register(r.id, cache.registries[r.id])
})
} else {
try {
const res = await fetch(url)
const data = await res.json()
config.registries.forEach(async (r: string | RegistryConfig) => {
if (typeof r === 'string') r = { id: r }
if (!checkVersion(versionId, r.minVersion, r.maxVersion)) return
if (!cache.registries) cache.registries = {}
const values = Object.keys(data[`minecraft:${r.id}`].entries)
target.register(r.id, values)
cache.registries[r.id] = values
cacheDirty = true
})
} catch (e) {
console.warn(`Error occurred while fetching registries for version ${versionId}`)
}
}
if (!cache.registries) {
cache.registries = {}
}
if (cacheValid && cache.registries?.[id]) {
target.register(id, cache.registries[id])
return
}
const url = typeof r !== 'string' && r.path
? `${baseUrl}/${version.mcdata_ref}/${r.path}/data.min.json`
: mcdata(version.mcdata_ref, typeof r === 'string' ? r : r.id)
try {
const res = await fetch(url)
const data = await res.json()
target.register(id, data.values)
cache.registries[id] = data.values
cacheDirty = true
} catch (e) {
console.warn(`Error occurred while fetching registry "${id}":`, e)
}
}))
} else {
await Promise.all(config.registries.map(async (r: string | RegistryConfig) => {
if (typeof r === 'string') r = { id: r }
if (r.minVersion && !checkVersion(versionId, r.minVersion)) return
if (r.maxVersion && !checkVersion(r.maxVersion, versionId)) return
if (!cache.registries) cache.registries = {}
if (cacheValid && cache.registries?.[r.id]) {
target.register(r.id, cache.registries[r.id])
return
}
const url = r.path
? `${baseUrl}/${version.mcdata_ref}/${r.path}/data.min.json`
: mcdata(version.mcdata_ref, typeof r === 'string' ? r : r.id)
try {
const res = await fetch(url)
const data = await res.json()
target.register(r.id, data.values)
cache.registries[r.id] = data.values
cacheDirty = true
} catch (e) {
console.warn(`Error occurred while fetching registry "${r.id}":`, e)
}
}))
}
if (cacheDirty) {
if (version.mcdata_ref === 'master') {

View File

@@ -18,7 +18,7 @@ const router = async () => {
let title = locale('title.home')
if (urlParts.length === 0){
App.model.set({ id: '', name: 'Data Pack', category: true})
App.model.set({ id: '', name: 'Data Pack', category: true, minVersion: '1.15'})
target.innerHTML = Home(view)
} else if (urlParts[0] === 'settings' && urlParts[1] === 'fields') {
target.innerHTML = FieldSettings(view)

View File

@@ -62,7 +62,7 @@ export const TreePanel = (view: View, model: DataModel) => {
</div>
<div class="panel-menu-list btn-group">
${config.versions
.filter(v => checkVersion(v.id, App.model.get()!.minVersion ?? '1.16'))
.filter(v => checkVersion(v.id, App.model.get()!.minVersion ?? '1.15'))
.reverse()
.map(v => `
<div class="btn" data-id="${view.onClick(() => {

View File

@@ -42,6 +42,10 @@
}
],
"versions": [
{
"id": "1.15",
"mcdata_ref": "13355f7"
},
{
"id": "1.16",
"mcdata_ref": "1.16.4"
@@ -76,105 +80,118 @@
{
"id": "dimension",
"name": "Dimension",
"schema": "dimension"
"schema": "dimension",
"minVersion": "1.16"
},
{
"id": "dimension-type",
"name": "Dimension Type",
"schema": "dimension_type"
"schema": "dimension_type",
"minVersion": "1.16"
},
{
"id": "world",
"name": "World Settings",
"schema": "world_settings"
"schema": "world_settings",
"minVersion": "1.16"
},
{
"id": "worldgen",
"name": "Worldgen",
"category": true
"category": true,
"minVersion": "1.16"
},
{
"id": "worldgen/biome",
"name": "Biome",
"category": "worldgen",
"schema": "biome"
"schema": "biome",
"minVersion": "1.16"
},
{
"id": "worldgen/carver",
"name": "Carver",
"category": "worldgen",
"schema": "configured_carver"
"schema": "configured_carver",
"minVersion": "1.16"
},
{
"id": "worldgen/feature",
"name": "Feature",
"category": "worldgen",
"schema": "configured_feature"
"schema": "configured_feature",
"minVersion": "1.16"
},
{
"id": "worldgen/noise-settings",
"name": "Noise Settings",
"category": "worldgen",
"schema": "noise_settings"
"schema": "noise_settings",
"minVersion": "1.16"
},
{
"id": "worldgen/structure-feature",
"name": "Structure Feature",
"category": "worldgen",
"schema": "configured_structure_feature"
"schema": "configured_structure_feature",
"minVersion": "1.16"
},
{
"id": "worldgen/surface-builder",
"name": "Surface Builder",
"category": "worldgen",
"schema": "configured_surface_builder"
"schema": "configured_surface_builder",
"minVersion": "1.16"
},
{
"id": "worldgen/processor-list",
"name": "Processor List",
"category": "worldgen",
"schema": "processor_list"
"schema": "processor_list",
"minVersion": "1.16"
},
{
"id": "worldgen/template-pool",
"name": "Template Pool",
"category": "worldgen",
"schema": "template_pool"
"schema": "template_pool",
"minVersion": "1.16"
}
],
"registries": [
"attribute",
{ "id": "attribute", "minVersion": "1.16" },
"block",
"enchantment",
"entity_type",
"fluid",
"item",
"loot_condition_type",
"loot_function_type",
{ "id": "loot_condition_type", "minVersion": "1.16" },
{ "id": "loot_function_type", "minVersion": "1.16" },
{ "id": "loot_nbt_provider_type", "minVersion": "1.17" },
{ "id": "loot_number_provider_type", "minVersion": "1.17" },
"loot_pool_entry_type",
{ "id": "loot_pool_entry_type", "minVersion": "1.16" },
{ "id": "loot_score_provider_type", "minVersion": "1.17" },
"mob_effect",
"rule_test",
"pos_rule_test",
{ "id": "rule_test", "minVersion": "1.16" },
{ "id": "pos_rule_test", "minVersion": "1.16" },
"sound_event",
"stat_type",
"worldgen/block_state_provider_type",
"worldgen/block_placer_type",
"worldgen/biome_source",
"worldgen/carver",
"worldgen/chunk_generator",
"worldgen/decorator",
"worldgen/feature",
"worldgen/feature_size_type",
"worldgen/foliage_placer_type",
"worldgen/structure_feature",
"worldgen/structure_pool_element",
"worldgen/structure_processor",
"worldgen/surface_builder",
"worldgen/tree_decorator_type",
"worldgen/trunk_placer_type",
{ "id": "worldgen/biome", "path": "processed/reports/biomes" }
{ "id": "worldgen/block_state_provider_type", "minVersion": "1.16" },
{ "id": "worldgen/block_placer_type", "minVersion": "1.16" },
{ "id": "worldgen/biome_source", "minVersion": "1.16" },
{ "id": "worldgen/carver", "minVersion": "1.16" },
{ "id": "worldgen/chunk_generator", "minVersion": "1.16" },
{ "id": "worldgen/decorator", "minVersion": "1.16" },
{ "id": "worldgen/feature", "minVersion": "1.16" },
{ "id": "worldgen/feature_size_type", "minVersion": "1.16" },
{ "id": "worldgen/foliage_placer_type", "minVersion": "1.16" },
{ "id": "worldgen/structure_feature", "minVersion": "1.16" },
{ "id": "worldgen/structure_pool_element", "minVersion": "1.16" },
{ "id": "worldgen/structure_processor", "minVersion": "1.16" },
{ "id": "worldgen/surface_builder", "minVersion": "1.16" },
{ "id": "worldgen/tree_decorator_type", "minVersion": "1.16" },
{ "id": "worldgen/trunk_placer_type", "minVersion": "1.16" },
{ "id": "biome", "maxVersion": "1.15" },
{ "id": "worldgen/biome", "minVersion": "1.16", "path": "processed/reports/biomes" }
]
}