From 666834b0f5d073a8b083b36699f3826c0ffa69d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 14 Oct 2017 20:11:03 +0200 Subject: [PATCH 01/11] Add basic setup for JSON validation through schemas --- .../com/demonwav/mcdev/i18n/I18nAnnotator.kt | 4 +- .../i18n/I18nEditorNotificationProvider.kt | 4 +- .../demonwav/mcdev/i18n/I18nElementFactory.kt | 4 +- .../com/demonwav/mcdev/i18n/i18n-utils.kt | 8 +-- .../i18n/lang/I18nCompletionContributor.kt | 4 +- .../demonwav/mcdev/i18n/sorting/I18nSorter.kt | 6 +- .../com/demonwav/mcdev/json/providers.kt | 52 ++++++++++++++ .../kotlin/com/demonwav/mcdev/util/files.kt | 10 ++- src/main/resources/META-INF/plugin.xml | 4 ++ .../jsonSchemas/blockstates.schema.json | 70 +++++++++++++++++++ .../resources/jsonSchemas/sounds.schema.json | 50 +++++++++++++ 11 files changed, 198 insertions(+), 18 deletions(-) create mode 100644 src/main/kotlin/com/demonwav/mcdev/json/providers.kt create mode 100644 src/main/resources/jsonSchemas/blockstates.schema.json create mode 100644 src/main/resources/jsonSchemas/sounds.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nAnnotator.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nAnnotator.kt index cc7169b52..748af410c 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nAnnotator.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nAnnotator.kt @@ -15,7 +15,7 @@ import com.demonwav.mcdev.i18n.intentions.RemoveUnmatchedEntryIntention import com.demonwav.mcdev.i18n.intentions.TrimKeyIntention import com.demonwav.mcdev.i18n.lang.gen.psi.I18nEntry import com.demonwav.mcdev.i18n.lang.gen.psi.I18nTypes -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.intellij.lang.annotation.AnnotationHolder import com.intellij.lang.annotation.Annotator import com.intellij.openapi.util.TextRange @@ -50,7 +50,7 @@ class I18nAnnotator : Annotator { } private fun checkEntryMatchesDefault(entry: I18nEntry, annotations: AnnotationHolder) { - if (entry.project.findDefaultLangEntries(domain = entry.containingFile.virtualFile.mcDomain).any { it.key == entry.key }) { + if (entry.project.findDefaultLangEntries(domain = entry.containingFile.virtualFile.resourceDomain).any { it.key == entry.key }) { return } annotations.createWarningAnnotation(entry.textRange, "Translation key not included in default localization file.") diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nEditorNotificationProvider.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nEditorNotificationProvider.kt index 7ab523d2a..ea1482cbb 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nEditorNotificationProvider.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nEditorNotificationProvider.kt @@ -16,7 +16,7 @@ import com.demonwav.mcdev.i18n.lang.gen.psi.I18nTypes import com.demonwav.mcdev.i18n.sorting.I18nSorter import com.demonwav.mcdev.i18n.sorting.Ordering import com.demonwav.mcdev.util.applyWriteAction -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.intellij.openapi.editor.colors.EditorColors import com.intellij.openapi.editor.colors.EditorColorsManager import com.intellij.openapi.fileEditor.FileEditor @@ -80,7 +80,7 @@ class I18nEditorNotificationProvider(private val project: Project) : EditorNotif } private fun getMissingEntries(file: VirtualFile): Map { - val defaultEntries = project.findDefaultLangEntries(scope = Scope.PROJECT, domain = file.mcDomain) + val defaultEntries = project.findDefaultLangEntries(scope = Scope.PROJECT, domain = file.resourceDomain) val entries = project.findLangEntries(file = file, scope = Scope.PROJECT) val keys = entries.map { it.key } val missingEntries = defaultEntries.associate { it.key to it }.toMutableMap() diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nElementFactory.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nElementFactory.kt index 51cf3810d..f02d260ee 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/I18nElementFactory.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/I18nElementFactory.kt @@ -15,7 +15,7 @@ import com.demonwav.mcdev.i18n.lang.I18nFileType import com.demonwav.mcdev.i18n.lang.gen.psi.I18nEntry import com.demonwav.mcdev.i18n.lang.gen.psi.I18nTypes import com.demonwav.mcdev.util.applyWriteAction -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.intellij.ide.DataManager import com.intellij.openapi.actionSystem.DataContext import com.intellij.openapi.module.Module @@ -50,7 +50,7 @@ object I18nElementFactory { val files = FileTypeIndex.getFiles(I18nFileType, GlobalSearchScope.moduleScope(module)) if (files.count { it.nameWithoutExtension.toLowerCase(Locale.ROOT) == I18nConstants.DEFAULT_LOCALE } > 1) { - val choices = files.mapNotNull { it.mcDomain }.distinct().sorted() + val choices = files.mapNotNull { it.resourceDomain }.distinct().sorted() val swingList = JBList(choices) DataManager.getInstance().dataContextFromFocus.doWhenDone(Consumer { JBPopupFactory.getInstance() diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/i18n-utils.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/i18n-utils.kt index a2fd15d3c..908bea4ad 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/i18n-utils.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/i18n-utils.kt @@ -13,7 +13,7 @@ package com.demonwav.mcdev.i18n import com.demonwav.mcdev.i18n.lang.I18nFile import com.demonwav.mcdev.i18n.lang.I18nFileType import com.demonwav.mcdev.i18n.lang.gen.psi.I18nEntry -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.intellij.openapi.project.Project import com.intellij.openapi.vfs.VirtualFile import com.intellij.psi.PsiManager @@ -47,7 +47,7 @@ fun Project.findLangEntries(scope: Scope = Scope.GLOBAL, key: String? = null, fi { it.virtualFile != null && (file == null || it.virtualFile.path == file.path) - && (domain == null || it.virtualFile.mcDomain == domain) + && (domain == null || it.virtualFile.resourceDomain == domain) }, { key == null || it.key == key } ) @@ -58,7 +58,7 @@ fun Project.findDefaultLangEntries(scope: Scope = Scope.GLOBAL, key: String? = n { it.virtualFile != null && it.virtualFile.nameWithoutExtension.toLowerCase(Locale.ROOT) == I18nConstants.DEFAULT_LOCALE && (file == null || it.virtualFile.path == file.path) - && (domain == null || it.virtualFile.mcDomain == domain) + && (domain == null || it.virtualFile.resourceDomain == domain) }, { key == null || it.key == key } ) @@ -69,4 +69,4 @@ fun Project.findDefaultLangFile(domain: String? = null) = I18nConstants.DEFAULT_LOCALE_FILE, false, GlobalSearchScope.projectScope(this) - ).firstOrNull { domain == null || it.mcDomain == domain } + ).firstOrNull { domain == null || it.resourceDomain == domain } diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/lang/I18nCompletionContributor.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/lang/I18nCompletionContributor.kt index 5bb69be11..e4c69bfec 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/lang/I18nCompletionContributor.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/lang/I18nCompletionContributor.kt @@ -17,7 +17,7 @@ import com.demonwav.mcdev.i18n.findDefaultLangEntries import com.demonwav.mcdev.i18n.lang.gen.psi.I18nEntry import com.demonwav.mcdev.i18n.lang.gen.psi.I18nTypes import com.demonwav.mcdev.util.getSimilarity -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.intellij.codeInsight.completion.CompletionContributor import com.intellij.codeInsight.completion.CompletionParameters import com.intellij.codeInsight.completion.CompletionResultSet @@ -55,7 +55,7 @@ class I18nCompletionContributor : CompletionContributor() { if (KEY_PATTERN.accepts(position) || DUMMY_PATTERN.accepts(position)) { val text = position.text.let { it.substring(0, it.length - CompletionUtil.DUMMY_IDENTIFIER.length) } - val domain = file.mcDomain + val domain = file.resourceDomain handleKey(text, position, domain, result) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/i18n/sorting/I18nSorter.kt b/src/main/kotlin/com/demonwav/mcdev/i18n/sorting/I18nSorter.kt index ab1fd538c..5ab3bf1d3 100644 --- a/src/main/kotlin/com/demonwav/mcdev/i18n/sorting/I18nSorter.kt +++ b/src/main/kotlin/com/demonwav/mcdev/i18n/sorting/I18nSorter.kt @@ -17,7 +17,7 @@ import com.demonwav.mcdev.i18n.findDefaultLangFile import com.demonwav.mcdev.i18n.lang.gen.psi.I18nEntry import com.demonwav.mcdev.i18n.lang.gen.psi.I18nTypes import com.demonwav.mcdev.util.lexicographical -import com.demonwav.mcdev.util.mcDomain +import com.demonwav.mcdev.util.resourceDomain import com.demonwav.mcdev.util.runWriteAction import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement @@ -32,7 +32,7 @@ object I18nSorter { private val descendingComparator = ascendingComparator.reversed() fun query(project: Project, file: PsiFile, defaultSelection: Ordering = Ordering.ASCENDING) { - val defaultFileMissing = project.findDefaultLangFile(file.virtualFile.mcDomain ?: return) == null + val defaultFileMissing = project.findDefaultLangFile(file.virtualFile.resourceDomain ?: return) == null val isDefaultFile = file.name == I18nConstants.DEFAULT_LOCALE_FILE val (order, comments) = TranslationSortOrderDialog.show(defaultFileMissing || isDefaultFile, defaultSelection) if (order == null) { @@ -47,7 +47,7 @@ object I18nSorter { Ordering.ASCENDING -> I18nElementFactory.assembleElements(project, it.sortedWith(ascendingComparator), keepComments) Ordering.DESCENDING -> I18nElementFactory.assembleElements(project, it.sortedWith(descendingComparator), keepComments) Ordering.TEMPLATE -> sortByTemplate(project, TemplateManager.getProjectTemplate(project), it, keepComments) - else -> sortByTemplate(project, buildDefaultTemplate(project, file.virtualFile.mcDomain) ?: return, it, keepComments) + else -> sortByTemplate(project, buildDefaultTemplate(project, file.virtualFile.resourceDomain) ?: return, it, keepComments) } } diff --git a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt new file mode 100644 index 000000000..ec6a6e7ab --- /dev/null +++ b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt @@ -0,0 +1,52 @@ +/* + * Minecraft Dev for IntelliJ + * + * https://minecraftdev.org + * + * Copyright (c) 2017 minecraft-dev + * + * MIT License + */ + +package com.demonwav.mcdev.json + +import com.demonwav.mcdev.util.resourceDomain +import com.demonwav.mcdev.util.resourcePath +import com.intellij.openapi.project.Project +import com.intellij.openapi.vfs.VirtualFile +import com.jetbrains.jsonSchema.extension.JsonSchemaFileProvider +import com.jetbrains.jsonSchema.extension.JsonSchemaProviderFactory +import com.jetbrains.jsonSchema.extension.SchemaType + +class SchemaProviderFactory : JsonSchemaProviderFactory { + override fun getProviders(project: Project) = + listOf(SoundsSchemaProvider(), BlockstatesSchemaProvider()) +} + +class SoundsSchemaProvider : JsonSchemaFileProvider { + companion object { + val FILE = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/sounds.schema.json") + } + + override fun getName() = "Minecraft Sounds JSON" + + override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath == "sounds.json" + + override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema + + override fun getSchemaFile(): VirtualFile = FILE +} + +class BlockstatesSchemaProvider : JsonSchemaFileProvider { + companion object { + val FILE = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/blockstates.schema.json") + } + + override fun getName() = "Minecraft Blockstates JSON" + + override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath?.startsWith("blockstates/") == true + + override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema + + override fun getSchemaFile(): VirtualFile = FILE +} diff --git a/src/main/kotlin/com/demonwav/mcdev/util/files.kt b/src/main/kotlin/com/demonwav/mcdev/util/files.kt index 520b2a301..d7d7fe210 100644 --- a/src/main/kotlin/com/demonwav/mcdev/util/files.kt +++ b/src/main/kotlin/com/demonwav/mcdev/util/files.kt @@ -29,10 +29,14 @@ val VirtualFile.manifest: Manifest? } // Technically resource domains are much more restricted ([a-z0-9_-]+) in modern versions, but we want to support as much as possible -private val DOMAIN_PATTERN = Regex("^.*?/assets/([^/]+)/lang.*?$") +private val RESOURCE_PATTERN = Regex("^.*?/assets/([^/]+)/(.*?)\$") + +val VirtualFile.resourceDomain: String? + get() = RESOURCE_PATTERN.matchEntire(this.path)?.groupValues?.get(1) + +val VirtualFile.resourcePath: String? + get() = RESOURCE_PATTERN.matchEntire(this.path)?.groupValues?.get(2) -val VirtualFile.mcDomain: String? - get() = DOMAIN_PATTERN.matchEntire(this.path)?.groupValues?.get(1) operator fun Manifest.get(attribute: String): String? = mainAttributes.getValue(attribute) operator fun Manifest.get(attribute: Attributes.Name): String? = mainAttributes.getValue(attribute) diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index cf4206f87..108ad6228 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -701,6 +701,10 @@ + + + + com.demonwav.mcdev.i18n.I18nFileListener diff --git a/src/main/resources/jsonSchemas/blockstates.schema.json b/src/main/resources/jsonSchemas/blockstates.schema.json new file mode 100644 index 000000000..c8a3d6581 --- /dev/null +++ b/src/main/resources/jsonSchemas/blockstates.schema.json @@ -0,0 +1,70 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Minecraft Blockstates JSON", + "definitions": { + "variantDefinition": { + "type": "object", + "additionalProperties": { + "oneOf": [ + { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/variantObject" } + }, + { + "type": "array", + "items": { "$ref": "#/definitions/variantObject" } + } + ] + } + }, + "variantObject": { + "type": "object", + "properties": { + "__comment": { + "type": "string" + }, + "model": { "type": "string" }, + "textures": { + "type": "object", + "additionalProperties": { + "type": "string" + } + } + }, + "additionalProperties": false + } + }, + "oneOf": [ + { + "type": "object", + "properties": { + "__comment": { + "type": "string" + }, + "variants": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/variantObject" } + } + }, + "additionalProperties": false, + "required": [ "variants" ], + "not": { "required": [ "forge_marker" ] } + }, + { + "type": "object", + "properties": { + "__comment": { + "type": "string" + }, + "forge_marker": { + "type": "integer", + "enum": [ 1 ] + }, + "variants": { "$ref": "#/definitions/variantDefinition" }, + "defaults": { "$ref": "#/definitions/variantObject" } + }, + "additionalProperties": false, + "required": [ "forge_marker", "variants" ] + } + ] +} diff --git a/src/main/resources/jsonSchemas/sounds.schema.json b/src/main/resources/jsonSchemas/sounds.schema.json new file mode 100644 index 000000000..f41341851 --- /dev/null +++ b/src/main/resources/jsonSchemas/sounds.schema.json @@ -0,0 +1,50 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "title": "Minecraft Sounds JSON", + "type": "object", + "additionalProperties": { + "type": "object", + "properties": { + "category": { "type": "string" }, + "replace": { "type": "boolean" }, + "subtitle": { "type": "string" }, + "sounds": { + "type": "array", + "items": { + "oneOf": [ + { "type": "string" }, + { + "type": "object", + "properties": { + "name": { "type": "string" }, + "volume": { + "type": "number", + "minimum": 0, + "maximum": 1, + "default": 1 + }, + "pitch": { + "type": "number", + "default": 1 + }, + "weight": { + "type": "number", + "default": 1 + }, + "stream": { + "type": "boolean", + "default": false + }, + "type": { + "enum": ["sound", "event"], + "default": "sound" + } + } + } + ] + }, + "uniqueItems": true + } + } + } +} From 0815508628fe8872184e8a832c291847f7fe26bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 19:36:56 +0200 Subject: [PATCH 02/11] Finish blockstates schema --- .../jsonSchemas/blockstates.schema.json | 256 +++++++++++++++--- 1 file changed, 225 insertions(+), 31 deletions(-) diff --git a/src/main/resources/jsonSchemas/blockstates.schema.json b/src/main/resources/jsonSchemas/blockstates.schema.json index c8a3d6581..2ee4eeaba 100644 --- a/src/main/resources/jsonSchemas/blockstates.schema.json +++ b/src/main/resources/jsonSchemas/blockstates.schema.json @@ -2,69 +2,263 @@ "$schema": "http://json-schema.org/draft-04/schema#", "title": "Minecraft Blockstates JSON", "definitions": { + "baseVariantObject": { + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "model": { "type": "string" }, + "textures": { + "type": "object", + "additionalProperties": { "type": "string" } + }, + "x": { + "type": "number", + "multipleOf": 22.5 + }, + "y": { + "type": "number", + "multipleOf": 22.5 + }, + "uvlock": { "type": "boolean" } + }, + "additionalProperties": false + }, + "vanillaVariantObject": { + "oneOf": [ + { "$ref": "#/definitions/baseVariantObject" }, + { + "type": "array", + "items": { + "allOf": [ + { "$ref": "#/definitions/baseVariantObject" }, + { + "properties": { + "weight": { "type": "number" } + } + } + ] + } + } + ] + }, "variantDefinition": { "type": "object", - "additionalProperties": { - "oneOf": [ - { - "type": "object", - "additionalProperties": { "$ref": "#/definitions/variantObject" } + "patternProperties": { + "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { + "type": "array", + "items": { "$ref": "#/definitions/variantObject" } + }, + "^[a-z0-9_]+$": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/variantObject" } + } + } + }, + "variantObject": { + "allOf": [ + { "$ref": "#/definitions/baseVariantObject" }, + { + "properties": { + "transform": { "$ref": "#/definitions/rootTransform" }, + "weight": { "type": "number" }, + "submodel": { + "oneOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { + "oneOf": [ + { "$ref": "#/definitions/variantObject" }, + { + "type": "array", + "items": { "$ref": "#/definitions/variantObject" } + } + ] + } + } + ] + }, + "custom": { + "type": "object", + "additionalProperties": true + } + } + } + ] + }, + "rootTransform": { + "oneOf": [ + { "$ref": "#/definitions/transform" }, + { + "type": "object", + "patternProperties": { + "(third|first)person_(left|right)hand": { "$ref": "#/definitions/transform" }, + "gui|head|ground|fixed": { "$ref": "#/definitions/transform" } }, - { - "type": "array", - "items": { "$ref": "#/definitions/variantObject" } + "additionalProperties": false + } + ] + }, + "transform": { + "oneOf": [ + { + "type": "string", + "enum": ["identity", "forge:default-block", "forge:default-item", "forge:default-tool"] + }, + { + "type": "object", + "required": ["matrix"], + "properties": { + "matrix": { "$ref": "#/definitions/transformMatrix" } } - ] + }, + { "$ref": "#/definitions/transformMatrix" }, + { + "type": "object", + "properties": { + "translation": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number" } + }, + "scale": { + "oneOf": [ + { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number" } + }, + { "type": "number" } + ] + }, + "rotation": { "$ref": "#/definitions/transformRotation" }, + "post-rotation": { "$ref": "#/definitions/transformRotation" } + } + } + ] + }, + "transformMatrix": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { "type": "number" } } }, - "variantObject": { - "type": "object", - "properties": { - "__comment": { - "type": "string" + "transformRotation": { + "oneOf": [ + { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { "type": "number" } }, - "model": { "type": "string" }, - "textures": { + { "type": "object", - "additionalProperties": { - "type": "string" + "minProperties": 1, + "maxProperties": 1, + "properties": { + "x": { "type": "number" }, + "y": { "type": "number" }, + "z": { "type": "number" } + } + }, + { + "type": "array", + "items": { + "type": "object", + "minProperties": 1, + "maxProperties": 1, + "properties": { + "x": { "type": "number" }, + "y": { "type": "number" }, + "z": { "type": "number" } + } } } + ] + }, + "multipartCase": { + "type": "object", + "properties": { + "apply": { "$ref": "#/definitions/vanillaVariantObject" }, + "when": { + "oneOf": [ + { + "type": "object", + "patternProperties": { + "^[a-z0-9_]*$": { } + }, + "additionalProperties": false, + "not": { "required": ["OR"] } + }, + { + "type": "object", + "properties": { + "OR": { + "type": "array", + "items": { + "type": "object", + "patternProperties": { + "^[a-z0-9_]*$": { } + }, + "additionalProperties": false + } + } + }, + "required": ["OR"], + "additionalProperties": false + } + ] + } }, - "additionalProperties": false + "required": ["apply"] } }, "oneOf": [ { "type": "object", "properties": { - "__comment": { - "type": "string" - }, + "__comment": { "type": "string" }, "variants": { "type": "object", - "additionalProperties": { "$ref": "#/definitions/variantObject" } + "patternProperties": { + "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { "$ref": "#/definitions/vanillaVariantObject" } + } } }, "additionalProperties": false, - "required": [ "variants" ], - "not": { "required": [ "forge_marker" ] } + "required": ["variants"] }, { "type": "object", "properties": { - "__comment": { - "type": "string" - }, + "__comment": { "type": "string" }, "forge_marker": { "type": "integer", - "enum": [ 1 ] + "enum": [1] }, "variants": { "$ref": "#/definitions/variantDefinition" }, - "defaults": { "$ref": "#/definitions/variantObject" } + "defaults": { "$ref": "#/definitions/variantObject" }, + "multipart": { + "type": "array", + "items": { "$ref": "#/definitions/multipartCase" } + } }, "additionalProperties": false, - "required": [ "forge_marker", "variants" ] + "dependencies": { + "defaults": ["forge_marker"], + "variants": ["forge_marker"], + "forge_marker": ["variants"], + "multipart": { + "not": { "required": ["forge_marker"] } + } + } } ] } From 8b94b4094801fcdcb28c3abfe2b9b7f21842fb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 21:13:17 +0200 Subject: [PATCH 03/11] Modularize blockstates schema and fix support for full variants in Forge format --- .../com/demonwav/mcdev/json/providers.kt | 2 +- .../jsonSchemas/blockstates.schema.json | 264 +----------------- .../blockstates_common.schema.json | 23 ++ .../jsonSchemas/blockstates_forge.schema.json | 161 +++++++++++ .../blockstates_vanilla.schema.json | 95 +++++++ 5 files changed, 289 insertions(+), 256 deletions(-) create mode 100644 src/main/resources/jsonSchemas/blockstates_common.schema.json create mode 100644 src/main/resources/jsonSchemas/blockstates_forge.schema.json create mode 100644 src/main/resources/jsonSchemas/blockstates_vanilla.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt index ec6a6e7ab..b3a28c6b0 100644 --- a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt +++ b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt @@ -3,7 +3,7 @@ * * https://minecraftdev.org * - * Copyright (c) 2017 minecraft-dev + * Copyright (c) 2018 minecraft-dev * * MIT License */ diff --git a/src/main/resources/jsonSchemas/blockstates.schema.json b/src/main/resources/jsonSchemas/blockstates.schema.json index 2ee4eeaba..9989a4103 100644 --- a/src/main/resources/jsonSchemas/blockstates.schema.json +++ b/src/main/resources/jsonSchemas/blockstates.schema.json @@ -1,264 +1,18 @@ { - "$schema": "http://json-schema.org/draft-04/schema#", + "$schema": "http://json-schema.org/draft-07/schema#", "title": "Minecraft Blockstates JSON", - "definitions": { - "baseVariantObject": { - "type": "object", - "properties": { - "__comment": { "type": "string" }, - "model": { "type": "string" }, - "textures": { - "type": "object", - "additionalProperties": { "type": "string" } - }, - "x": { - "type": "number", - "multipleOf": 22.5 - }, - "y": { - "type": "number", - "multipleOf": 22.5 - }, - "uvlock": { "type": "boolean" } - }, - "additionalProperties": false - }, - "vanillaVariantObject": { - "oneOf": [ - { "$ref": "#/definitions/baseVariantObject" }, - { - "type": "array", - "items": { - "allOf": [ - { "$ref": "#/definitions/baseVariantObject" }, - { - "properties": { - "weight": { "type": "number" } - } - } - ] - } - } - ] - }, - "variantDefinition": { - "type": "object", - "patternProperties": { - "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { - "type": "array", - "items": { "$ref": "#/definitions/variantObject" } - }, - "^[a-z0-9_]+$": { - "type": "object", - "additionalProperties": { "$ref": "#/definitions/variantObject" } - } - } - }, - "variantObject": { - "allOf": [ - { "$ref": "#/definitions/baseVariantObject" }, - { - "properties": { - "transform": { "$ref": "#/definitions/rootTransform" }, - "weight": { "type": "number" }, - "submodel": { - "oneOf": [ - { "type": "string" }, - { - "type": "object", - "additionalProperties": { - "oneOf": [ - { "$ref": "#/definitions/variantObject" }, - { - "type": "array", - "items": { "$ref": "#/definitions/variantObject" } - } - ] - } - } - ] - }, - "custom": { - "type": "object", - "additionalProperties": true - } - } - } - ] - }, - "rootTransform": { - "oneOf": [ - { "$ref": "#/definitions/transform" }, - { - "type": "object", - "patternProperties": { - "(third|first)person_(left|right)hand": { "$ref": "#/definitions/transform" }, - "gui|head|ground|fixed": { "$ref": "#/definitions/transform" } - }, - "additionalProperties": false - } - ] - }, - "transform": { - "oneOf": [ - { - "type": "string", - "enum": ["identity", "forge:default-block", "forge:default-item", "forge:default-tool"] - }, - { - "type": "object", - "required": ["matrix"], - "properties": { - "matrix": { "$ref": "#/definitions/transformMatrix" } - } - }, - { "$ref": "#/definitions/transformMatrix" }, - { - "type": "object", - "properties": { - "translation": { - "type": "array", - "minItems": 3, - "maxItems": 3, - "items": { "type": "number" } - }, - "scale": { - "oneOf": [ - { - "type": "array", - "minItems": 3, - "maxItems": 3, - "items": { "type": "number" } - }, - { "type": "number" } - ] - }, - "rotation": { "$ref": "#/definitions/transformRotation" }, - "post-rotation": { "$ref": "#/definitions/transformRotation" } - } - } - ] - }, - "transformMatrix": { - "type": "array", - "minItems": 3, - "maxItems": 3, - "items": { - "type": "array", - "minItems": 4, - "maxItems": 4, - "items": { "type": "number" } - } - }, - "transformRotation": { - "oneOf": [ - { - "type": "array", - "minItems": 4, - "maxItems": 4, - "items": { "type": "number" } - }, - { - "type": "object", - "minProperties": 1, - "maxProperties": 1, - "properties": { - "x": { "type": "number" }, - "y": { "type": "number" }, - "z": { "type": "number" } - } - }, - { - "type": "array", - "items": { - "type": "object", - "minProperties": 1, - "maxProperties": 1, - "properties": { - "x": { "type": "number" }, - "y": { "type": "number" }, - "z": { "type": "number" } - } - } - } - ] - }, - "multipartCase": { - "type": "object", - "properties": { - "apply": { "$ref": "#/definitions/vanillaVariantObject" }, - "when": { - "oneOf": [ - { - "type": "object", - "patternProperties": { - "^[a-z0-9_]*$": { } - }, - "additionalProperties": false, - "not": { "required": ["OR"] } - }, - { - "type": "object", - "properties": { - "OR": { - "type": "array", - "items": { - "type": "object", - "patternProperties": { - "^[a-z0-9_]*$": { } - }, - "additionalProperties": false - } - } - }, - "required": ["OR"], - "additionalProperties": false - } - ] - } - }, - "required": ["apply"] - } - }, "oneOf": [ { - "type": "object", - "properties": { - "__comment": { "type": "string" }, - "variants": { - "type": "object", - "patternProperties": { - "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { "$ref": "#/definitions/vanillaVariantObject" } - } - } - }, - "additionalProperties": false, - "required": ["variants"] + "allOf": [ + { "required": [ "forge_marker" ] }, + { "$ref": "blockstates_forge.schema.json" } + ] }, { - "type": "object", - "properties": { - "__comment": { "type": "string" }, - "forge_marker": { - "type": "integer", - "enum": [1] - }, - "variants": { "$ref": "#/definitions/variantDefinition" }, - "defaults": { "$ref": "#/definitions/variantObject" }, - "multipart": { - "type": "array", - "items": { "$ref": "#/definitions/multipartCase" } - } - }, - "additionalProperties": false, - "dependencies": { - "defaults": ["forge_marker"], - "variants": ["forge_marker"], - "forge_marker": ["variants"], - "multipart": { - "not": { "required": ["forge_marker"] } - } - } + "allOf": [ + { "not": { "required": [ "forge_marker" ] } }, + { "$ref": "blockstates_vanilla.schema.json" } + ] } ] } diff --git a/src/main/resources/jsonSchemas/blockstates_common.schema.json b/src/main/resources/jsonSchemas/blockstates_common.schema.json new file mode 100644 index 000000000..7ece95eb3 --- /dev/null +++ b/src/main/resources/jsonSchemas/blockstates_common.schema.json @@ -0,0 +1,23 @@ +{ + "baseVariant": { + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "model": { "type": "string" }, + "textures": { + "type": "object", + "additionalProperties": { "type": "string" } + }, + "x": { + "type": "number", + "multipleOf": 22.5 + }, + "y": { + "type": "number", + "multipleOf": 22.5 + }, + "uvlock": { "type": "boolean" } + }, + "additionalProperties": false + } +} diff --git a/src/main/resources/jsonSchemas/blockstates_forge.schema.json b/src/main/resources/jsonSchemas/blockstates_forge.schema.json new file mode 100644 index 000000000..be7976eb5 --- /dev/null +++ b/src/main/resources/jsonSchemas/blockstates_forge.schema.json @@ -0,0 +1,161 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Forge Blockstates JSON", + "type": "object", + "properties": { + "forge_marker": { + "type": "integer", + "enum": [ 1 ] + }, + "__comment": { "type": "string" }, + "variants": { "$ref": "#/definitions/variants" }, + "defaults": { "$ref": "#/definitions/variantObject" } + }, + "required": [ "forge_marker" ], + "additionalProperties": false, + "definitions": { + "variants": { + "type": "object", + "patternProperties": { + "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { + }, + "^[a-z0-9_]+$": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/variant" } + } + } + }, + "variant": { + "oneOf": [ + { "$ref": "#/definitions/variantObject" }, + { + "type": "array", + "items": { "$ref": "#/definitions/variantObject" } + } + ] + }, + "variantObject": { + "allOf": [ + { "$ref": "blockstates_common.schema.json#/baseVariant" }, + { + "properties": { + "transform": { "$ref": "#/definitions/rootTransform" }, + "weight": { "type": "number" }, + "submodel": { + "oneOf": [ + { "type": "string" }, + { + "type": "object", + "additionalProperties": { + "$ref": "#/definitions/variant" + } + } + ] + }, + "custom": { + "type": "object", + "additionalProperties": true + } + } + } + ] + }, + "rootTransform": { + "oneOf": [ + { "$ref": "#/definitions/transform" }, + { + "type": "object", + "patternProperties": { + "(third|first)person_(left|right)hand": { "$ref": "#/definitions/transform" }, + "gui|head|ground|fixed": { "$ref": "#/definitions/transform" } + }, + "additionalProperties": false + } + ] + }, + "transform": { + "oneOf": [ + { + "type": "string", + "enum": [ "identity", "forge:default-block", "forge:default-item", "forge:default-tool" ] + }, + { + "type": "object", + "required": [ "matrix" ], + "properties": { + "matrix": { "$ref": "#/definitions/transformMatrix" } + } + }, + { "$ref": "#/definitions/transformMatrix" }, + { + "type": "object", + "properties": { + "translation": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number" } + }, + "scale": { + "oneOf": [ + { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number" } + }, + { "type": "number" } + ] + }, + "rotation": { "$ref": "#/definitions/transformRotation" }, + "post-rotation": { "$ref": "#/definitions/transformRotation" } + } + } + ] + }, + "transformMatrix": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { "type": "number" } + } + }, + "transformRotation": { + "oneOf": [ + { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { "type": "number" } + }, + { + "type": "object", + "minProperties": 1, + "maxProperties": 1, + "properties": { + "x": { "type": "number" }, + "y": { "type": "number" }, + "z": { "type": "number" } + } + }, + { + "type": "array", + "items": { + "type": "object", + "minProperties": 1, + "maxProperties": 1, + "properties": { + "x": { "type": "number" }, + "y": { "type": "number" }, + "z": { "type": "number" } + } + } + } + ] + } + } +} diff --git a/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json new file mode 100644 index 000000000..f3abf1bec --- /dev/null +++ b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json @@ -0,0 +1,95 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Vanilla Blockstates JSON", + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "variants": { + "type": "object", + "patternProperties": { + "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { "$ref": "#/definitions/variant" } + } + }, + "multipart": { + "type": "array", + "items": { "$ref": "#/definitions/multipartCase" } + } + }, + "additionalProperties": false, + "dependencies": { + "variants": { + "required": [ "variants" ], + "not": { "title": "Multipart and full variant definitions are mutually exclusive", "required": [ "multipart" ] } + }, + "multipart": { + "required": [ "multipart" ], + "not": { "title": "Multipart and full variant definitions are mutually exclusive", "required": [ "variants" ] } + } + }, + "definitions": { + "variant": { + "oneOf": [ + { + "allOf": [ + { "$ref": "blockstates_common.schema.json#/baseVariant" }, + { "required": [ "model" ] } + ] + }, + { + "type": "array", + "items": { + "allOf": [ + { "$ref": "blockstates_common.schema.json#/baseVariant" }, + { "required": [ "model" ] }, + { + "properties": { + "weight": { + "type": "number" + } + } + } + ] + } + } + ] + }, + "multipartCase": { + "type": "object", + "properties": { + "apply": { + "$ref": "#/definitions/variant" + }, + "when": { + "oneOf": [ + { + "type": "object", + "patternProperties": { + "^[a-z0-9_]*$": { } + }, + "additionalProperties": false, + "not": { "required": [ "OR" ] } + }, + { + "type": "object", + "properties": { + "OR": { + "type": "array", + "items": { + "type": "object", + "patternProperties": { + "^[a-z0-9_]*$": { } + }, + "additionalProperties": false + } + } + }, + "required": [ "OR" ], + "additionalProperties": false + } + ] + } + }, + "required": [ "apply" ] + } + } +} From fd680f2aacc99e775d2d176bf3768432daa37871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 21:38:49 +0200 Subject: [PATCH 04/11] Handle full variants correctly --- .../jsonSchemas/blockstates_forge.schema.json | 24 ++++++++++++++----- .../blockstates_vanilla.schema.json | 5 ++-- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main/resources/jsonSchemas/blockstates_forge.schema.json b/src/main/resources/jsonSchemas/blockstates_forge.schema.json index be7976eb5..8fcc91931 100644 --- a/src/main/resources/jsonSchemas/blockstates_forge.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_forge.schema.json @@ -18,15 +18,25 @@ "type": "object", "patternProperties": { "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { + "$ref": "#/definitions/variant" }, "^[a-z0-9_]+$": { - "type": "object", - "additionalProperties": { "$ref": "#/definitions/variant" } + "oneOf": [ + { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/variant" } + }, + { + "type": "array", + "items": { "$ref": "#/definitions/variantObject" } + } + ] } - } + }, + "additionalProperties": false }, "variant": { - "oneOf": [ + "anyOf": [ { "$ref": "#/definitions/variantObject" }, { "type": "array", @@ -84,7 +94,8 @@ "required": [ "matrix" ], "properties": { "matrix": { "$ref": "#/definitions/transformMatrix" } - } + }, + "additionalProperties": false }, { "$ref": "#/definitions/transformMatrix" }, { @@ -109,7 +120,8 @@ }, "rotation": { "$ref": "#/definitions/transformRotation" }, "post-rotation": { "$ref": "#/definitions/transformRotation" } - } + }, + "additionalProperties": false } ] }, diff --git a/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json index f3abf1bec..39fa07597 100644 --- a/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json @@ -8,7 +8,8 @@ "type": "object", "patternProperties": { "^([a-z0-9_]+=[^,]*,)*([a-z0-9_]+=[^,]*)$": { "$ref": "#/definitions/variant" } - } + }, + "additionalProperties": false }, "multipart": { "type": "array", @@ -28,7 +29,7 @@ }, "definitions": { "variant": { - "oneOf": [ + "anyOf": [ { "allOf": [ { "$ref": "blockstates_common.schema.json#/baseVariant" }, From 7953e5f018075f9b0837ecc2bd4acc17a027998a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 22:42:06 +0200 Subject: [PATCH 05/11] Add item model schema --- .../com/demonwav/mcdev/json/providers.kt | 16 ++- .../blockstates_common.schema.json | 2 + .../jsonSchemas/model_common.schema.json | 111 ++++++++++++++++++ .../jsonSchemas/model_item.schema.json | 37 ++++++ 4 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/jsonSchemas/model_common.schema.json create mode 100644 src/main/resources/jsonSchemas/model_item.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt index b3a28c6b0..37bc45538 100644 --- a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt +++ b/src/main/kotlin/com/demonwav/mcdev/json/providers.kt @@ -20,7 +20,7 @@ import com.jetbrains.jsonSchema.extension.SchemaType class SchemaProviderFactory : JsonSchemaProviderFactory { override fun getProviders(project: Project) = - listOf(SoundsSchemaProvider(), BlockstatesSchemaProvider()) + listOf(SoundsSchemaProvider(), BlockstatesSchemaProvider(), ItemModelSchemaProvider()) } class SoundsSchemaProvider : JsonSchemaFileProvider { @@ -50,3 +50,17 @@ class BlockstatesSchemaProvider : JsonSchemaFileProvider { override fun getSchemaFile(): VirtualFile = FILE } + +class ItemModelSchemaProvider : JsonSchemaFileProvider { + companion object { + val FILE = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/model_item.schema.json") + } + + override fun getName() = "Minecraft Item Model JSON" + + override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath?.startsWith("models/item/") == true + + override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema + + override fun getSchemaFile(): VirtualFile = FILE +} diff --git a/src/main/resources/jsonSchemas/blockstates_common.schema.json b/src/main/resources/jsonSchemas/blockstates_common.schema.json index 7ece95eb3..12f8f0c79 100644 --- a/src/main/resources/jsonSchemas/blockstates_common.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_common.schema.json @@ -1,4 +1,6 @@ { + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Blockstates JSON", "baseVariant": { "type": "object", "properties": { diff --git a/src/main/resources/jsonSchemas/model_common.schema.json b/src/main/resources/jsonSchemas/model_common.schema.json new file mode 100644 index 000000000..fda26d335 --- /dev/null +++ b/src/main/resources/jsonSchemas/model_common.schema.json @@ -0,0 +1,111 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "elements": { + "type": "array", + "items": { + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "from": { "$ref": "#/elementCoord" }, + "to": { "$ref": "#/elementCoord" }, + "rotation": { + "type": "object", + "properties": { + "origin": { "$ref": "#/elementCoord" }, + "axis": { + "type": "string", + "enum": [ "x", "y", "z" ] + }, + "angle": { + "type": "number", + "multipleOf": 22.5, + "minimum": -45, + "maximum": 45 + } + }, + "additionalProperties": false, + "required": [ "axis" ] + }, + "faces": { + "type": "object", + "patternProperties": { + "down|up|north|south|west|east": { + "type": "object", + "properties": { + "uv": { + "type": "array", + "minItems": 4, + "maxItems": 4, + "items": { + "type": "number" + } + }, + "texture": { + "type": "string", + "pattern": "^#.*?" + }, + "cullface": { + "type": "string", + "enum": [ "down", "up", "north", "south", "west", "east" ] + }, + "rotation": { + "type": "integer", + "enum": [ 0, 90, 180, 270 ] + }, + "tintindex": { + "type": "integer" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false, + "required": [ "from", "to" ] + } + }, + "elementCoord": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { + "type": "number", + "minimum": -16, + "maximum": 32 + } + }, + "transforms": { + "type": "object", + "patternProperties": { + "(third|first)person_(left|right)hand": { "$ref": "#/transform" }, + "gui|head|ground|fixed": { "$ref": "#/transform" } + }, + "additionalProperties": false + }, + "transform": { + "type": "object", + "properties": { + "rotation": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number" } + }, + "translation": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number", "minimum": -80, "maximum": 80 } + }, + "scale": { + "type": "array", + "minItems": 3, + "maxItems": 3, + "items": { "type": "number", "minimum": -4, "maximum": 4 } + } + }, + "additionalProperties": false + } +} diff --git a/src/main/resources/jsonSchemas/model_item.schema.json b/src/main/resources/jsonSchemas/model_item.schema.json new file mode 100644 index 000000000..c251c7954 --- /dev/null +++ b/src/main/resources/jsonSchemas/model_item.schema.json @@ -0,0 +1,37 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Item Model JSON", + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "parent": { "type": "string" }, + "textures": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "elements": { "#ref": "model_common.schema.json#/elements" }, + "display": { "#ref": "model_common.schema.json#/transforms" }, + "overrides": { + "type": "array", + "items": { + "type": "object", + "properties": { + "predicate": { + "type": "object", + "additionalProperties": { "type": "number" } + }, + "model": { "type": "string" } + }, + "additionalProperties": false, + "required": [ "predicate", "model" ] + } + } + }, + "additionalProperties": false, + "anyOf": [ + { "required": [ "parent" ] }, + { "required": [ "elements" ] } + ] +} From 9b6b9b22ffd22d4d575d11be47930f40f36b42d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 22:57:26 +0200 Subject: [PATCH 06/11] Add block model schema and use a generic schema provider --- .../{providers.kt => schema_providers.kt} | 34 +++++++------------ .../jsonSchemas/model_block.schema.json | 19 +++++++++++ .../jsonSchemas/model_item.schema.json | 6 +--- 3 files changed, 32 insertions(+), 27 deletions(-) rename src/main/kotlin/com/demonwav/mcdev/json/{providers.kt => schema_providers.kt} (55%) create mode 100644 src/main/resources/jsonSchemas/model_block.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt similarity index 55% rename from src/main/kotlin/com/demonwav/mcdev/json/providers.kt rename to src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt index 37bc45538..35f52b724 100644 --- a/src/main/kotlin/com/demonwav/mcdev/json/providers.kt +++ b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt @@ -20,7 +20,12 @@ import com.jetbrains.jsonSchema.extension.SchemaType class SchemaProviderFactory : JsonSchemaProviderFactory { override fun getProviders(project: Project) = - listOf(SoundsSchemaProvider(), BlockstatesSchemaProvider(), ItemModelSchemaProvider()) + listOf( + SoundsSchemaProvider(), + PathBasedSchemaProvider("Minecraft Blockstates JSON", "blockstates", "blockstates/"), + PathBasedSchemaProvider("Minecraft Item Model JSON", "model_item", "models/item/"), + PathBasedSchemaProvider("Minecraft Block Model JSON", "model_block", "models/block/") + ) } class SoundsSchemaProvider : JsonSchemaFileProvider { @@ -37,30 +42,15 @@ class SoundsSchemaProvider : JsonSchemaFileProvider { override fun getSchemaFile(): VirtualFile = FILE } -class BlockstatesSchemaProvider : JsonSchemaFileProvider { - companion object { - val FILE = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/blockstates.schema.json") - } +class PathBasedSchemaProvider(name: String, schema: String, private val path: String) : JsonSchemaFileProvider { + private val _name = name + private val file = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/$schema.schema.json") - override fun getName() = "Minecraft Blockstates JSON" + override fun getName() = this._name - override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath?.startsWith("blockstates/") == true + override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath?.startsWith(path) == true override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema - override fun getSchemaFile(): VirtualFile = FILE -} - -class ItemModelSchemaProvider : JsonSchemaFileProvider { - companion object { - val FILE = JsonSchemaProviderFactory.getResourceFile(SchemaProviderFactory::class.java, "/jsonSchemas/model_item.schema.json") - } - - override fun getName() = "Minecraft Item Model JSON" - - override fun isAvailable(file: VirtualFile) = file.resourceDomain != null && file.resourcePath?.startsWith("models/item/") == true - - override fun getSchemaType(): SchemaType = SchemaType.embeddedSchema - - override fun getSchemaFile(): VirtualFile = FILE + override fun getSchemaFile(): VirtualFile = file } diff --git a/src/main/resources/jsonSchemas/model_block.schema.json b/src/main/resources/jsonSchemas/model_block.schema.json new file mode 100644 index 000000000..1a6f2524a --- /dev/null +++ b/src/main/resources/jsonSchemas/model_block.schema.json @@ -0,0 +1,19 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Block Model JSON", + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "parent": { "type": "string" }, + "textures": { + "type": "object", + "additionalProperties": { + "type": "string" + } + }, + "ambientocclusion": { "type": "boolean" }, + "elements": { "#ref": "model_common.schema.json#/elements" }, + "display": { "#ref": "model_common.schema.json#/transforms" } + }, + "additionalProperties": false +} diff --git a/src/main/resources/jsonSchemas/model_item.schema.json b/src/main/resources/jsonSchemas/model_item.schema.json index c251c7954..18ad9da7b 100644 --- a/src/main/resources/jsonSchemas/model_item.schema.json +++ b/src/main/resources/jsonSchemas/model_item.schema.json @@ -29,9 +29,5 @@ } } }, - "additionalProperties": false, - "anyOf": [ - { "required": [ "parent" ] }, - { "required": [ "elements" ] } - ] + "additionalProperties": false } From cc8d8074c7083eb473a0d9c11d416bfb97837149 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sat, 7 Apr 2018 23:05:06 +0200 Subject: [PATCH 07/11] Allow additional properties in models to support things like CTM --- src/main/resources/jsonSchemas/model_block.schema.json | 3 +-- src/main/resources/jsonSchemas/model_item.schema.json | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/resources/jsonSchemas/model_block.schema.json b/src/main/resources/jsonSchemas/model_block.schema.json index 1a6f2524a..420e16005 100644 --- a/src/main/resources/jsonSchemas/model_block.schema.json +++ b/src/main/resources/jsonSchemas/model_block.schema.json @@ -14,6 +14,5 @@ "ambientocclusion": { "type": "boolean" }, "elements": { "#ref": "model_common.schema.json#/elements" }, "display": { "#ref": "model_common.schema.json#/transforms" } - }, - "additionalProperties": false + } } diff --git a/src/main/resources/jsonSchemas/model_item.schema.json b/src/main/resources/jsonSchemas/model_item.schema.json index 18ad9da7b..b35413b5f 100644 --- a/src/main/resources/jsonSchemas/model_item.schema.json +++ b/src/main/resources/jsonSchemas/model_item.schema.json @@ -28,6 +28,5 @@ "required": [ "predicate", "model" ] } } - }, - "additionalProperties": false + } } From 69483521c2048427838c9d5c0e60c7c8b6d5f242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sun, 8 Apr 2018 00:27:38 +0200 Subject: [PATCH 08/11] Fix schema references --- .../resources/jsonSchemas/common.schema.json | 42 +++++++++++++++++++ .../jsonSchemas/model_block.schema.json | 4 +- .../jsonSchemas/model_item.schema.json | 4 +- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 src/main/resources/jsonSchemas/common.schema.json diff --git a/src/main/resources/jsonSchemas/common.schema.json b/src/main/resources/jsonSchemas/common.schema.json new file mode 100644 index 000000000..fc6675bbb --- /dev/null +++ b/src/main/resources/jsonSchemas/common.schema.json @@ -0,0 +1,42 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "integerRange": { + "oneOf": [ + { + "type": "integer" + }, + { + "type": "object", + "properties": { + "min": { "type": "integer" }, + "max": { "type": "integer" } + }, + "required": [ "min", "max" ], + "additionalProperties": false + } + ] + }, + "floatRange": { + "oneOf": [ + { + "type": "number" + }, + { + "type": "object", + "properties": { + "min": { "type": "number" }, + "max": { "type": "number" } + }, + "required": [ "min", "max" ], + "additionalProperties": false + } + ] + }, + "equipmentSlot": { "type": "string", "enum": [ "mainhand", "offhand", "feet", "legs", "chest", "head" ] }, + "equipmentSlots": { + "oneOf": [ + { "$ref": "#/equipmentSlot" }, + { "type": "array", "items": { "$ref": "#/equipmentSlot" } } + ] + } +} diff --git a/src/main/resources/jsonSchemas/model_block.schema.json b/src/main/resources/jsonSchemas/model_block.schema.json index 420e16005..dac2af1c9 100644 --- a/src/main/resources/jsonSchemas/model_block.schema.json +++ b/src/main/resources/jsonSchemas/model_block.schema.json @@ -12,7 +12,7 @@ } }, "ambientocclusion": { "type": "boolean" }, - "elements": { "#ref": "model_common.schema.json#/elements" }, - "display": { "#ref": "model_common.schema.json#/transforms" } + "elements": { "$ref": "model_common.schema.json#/elements" }, + "display": { "$ref": "model_common.schema.json#/transforms" } } } diff --git a/src/main/resources/jsonSchemas/model_item.schema.json b/src/main/resources/jsonSchemas/model_item.schema.json index b35413b5f..dc8fe1ef3 100644 --- a/src/main/resources/jsonSchemas/model_item.schema.json +++ b/src/main/resources/jsonSchemas/model_item.schema.json @@ -11,8 +11,8 @@ "type": "string" } }, - "elements": { "#ref": "model_common.schema.json#/elements" }, - "display": { "#ref": "model_common.schema.json#/transforms" }, + "elements": { "$ref": "model_common.schema.json#/elements" }, + "display": { "$ref": "model_common.schema.json#/transforms" }, "overrides": { "type": "array", "items": { From e70cf2e7f73a9a787d3a101617ccc8fa1465a41a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sun, 8 Apr 2018 00:36:23 +0200 Subject: [PATCH 09/11] Add loot table schema --- .../demonwav/mcdev/json/schema_providers.kt | 3 +- .../jsonSchemas/loot_table.schema.json | 214 ++++++++++++++++++ .../loot_table_conditions.schema.json | 45 ++++ .../loot_table_functions.schema.json | 76 +++++++ 4 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/jsonSchemas/loot_table.schema.json create mode 100644 src/main/resources/jsonSchemas/loot_table_conditions.schema.json create mode 100644 src/main/resources/jsonSchemas/loot_table_functions.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt index 35f52b724..ff4cf2a45 100644 --- a/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt +++ b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt @@ -24,7 +24,8 @@ class SchemaProviderFactory : JsonSchemaProviderFactory { SoundsSchemaProvider(), PathBasedSchemaProvider("Minecraft Blockstates JSON", "blockstates", "blockstates/"), PathBasedSchemaProvider("Minecraft Item Model JSON", "model_item", "models/item/"), - PathBasedSchemaProvider("Minecraft Block Model JSON", "model_block", "models/block/") + PathBasedSchemaProvider("Minecraft Block Model JSON", "model_block", "models/block/"), + PathBasedSchemaProvider("Minecraft Loot Table JSON", "loot_table", "loot_tables/") ) } diff --git a/src/main/resources/jsonSchemas/loot_table.schema.json b/src/main/resources/jsonSchemas/loot_table.schema.json new file mode 100644 index 000000000..d02355b87 --- /dev/null +++ b/src/main/resources/jsonSchemas/loot_table.schema.json @@ -0,0 +1,214 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Loot Table JSON", + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "pools": { + "type": "array", + "items": { + "type": "object", + "properties": { + "__comment": { "type": "string" }, + "conditions": { "$ref": "#/definitions/conditions" }, + "rolls": { "$ref": "common.schema.json#/integerRange" }, + "bonusRolls": { "$ref": "common.schema.json#/integerRange" }, + "entries": { + "type": "array", + "items": { + "type": "object", + "properties": { + "conditions": { "$ref": "#/definitions/conditions" }, + "type": { "type": "string" }, + "weight": { "type": "number" }, + "quality": { "type": "number" } + }, + "required": [ "type" ], + "anyOf": [ + { + "allOf": [ + { "properties": { "type": { "enum": [ "item" ] } } }, + { + "properties": { + "name": { "type": "string" }, + "functions": { "$ref": "#/definitions/functions" } + }, + "required": [ "name" ] + } + ] + }, + { + "allOf": [ + { "properties": { "type": { "enum": [ "loot_table" ] } } }, + { + "properties": { + "name": { "type": "string" } + }, + "required": [ "name" ] + } + ] + }, + { } + ] + } + } + }, + "additionalProperties": false, + "required": [ "entries" ] + } + } + }, + "additionalProperties": false, + "definitions": { + "conditions": { + "type": "array", + "items": { + "type": "object", + "properties": { + "condition": { + "anyOf": [ + { "type": "string" }, + { + "type": "string", + "enum": [ + "entity_properties", + "entity_scores", + "killed_by_player", + "random_chance", + "random_chance_with_looting" + ] + } + ] + } + }, + "required": [ "condition" ], + "anyOf": [ + { + "allOf": [ + { "properties": { "condition": { "enum": [ "entity_properties" ] } } }, + { "$ref": "loot_table_conditions.schema.json#/entityProperties" } + ] + }, + { + "allOf": [ + { "properties": { "condition": { "enum": [ "entity_scores" ] } } }, + { "$ref": "loot_table_conditions.schema.json#/entityScores" } + ] + }, + { + "allOf": [ + { "properties": { "condition": { "enum": [ "killed_by_player" ] } } }, + { "$ref": "loot_table_conditions.schema.json#/killedByPlayer" } + ] + }, + { + "allOf": [ + { "properties": { "condition": { "enum": [ "random_chance" ] } } }, + { "$ref": "loot_table_conditions.schema.json#/randomChance" } + ] + }, + { + "allOf": [ + { "properties": { "condition": { "enum": [ "random_chance_with_looting" ] } } }, + { "$ref": "loot_table_conditions.schema.json#/randomChanceWithLooting" } + ] + }, + { } + ] + } + }, + "functions": { + "type": "array", + "items": { "$ref": "#/definitions/function" } + }, + "function": { + "type": "object", + "properties": { + "function": { + "anyOf": [ + { "type": "string" }, + { + "type": "string", + "enum": [ + "enchant_randomly", + "enchant_with_levels", + "exploration_map", + "furnace_smelt", + "looting_enchant", + "set_attributes", + "set_count", + "set_damage", + "set_data", + "set_nbt" + ] + } + ] + }, + "conditions": { "$ref": "#/definitions/conditions" } + }, + "required": [ "function" ], + "anyOf": [ + { + "allOf": [ + { "properties": { "function": { "enum": [ "enchant_randomly" ] } } }, + { "$ref": "loot_table_functions.schema.json#/enchantRandomly" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "enchant_with_levels" ] } } }, + { "$ref": "loot_table_functions.schema.json#/enchantWithLevels" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "exploration_map" ] } } }, + { "$ref": "loot_table_functions.schema.json#/explorationMap" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "furnace_smelt" ] } } } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "looting_enchant" ] } } }, + { "$ref": "loot_table_functions.schema.json#/lootingEnchant" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "set_attributes" ] } } }, + { "$ref": "loot_table_functions.schema.json#/setAttributes" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "set_count" ] } } }, + { "$ref": "loot_table_functions.schema.json#/setCount" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "set_damage" ] } } }, + { "$ref": "loot_table_functions.schema.json#/setDamage" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "set_data" ] } } }, + { "$ref": "loot_table_functions.schema.json#/setData" } + ] + }, + { + "allOf": [ + { "properties": { "function": { "enum": [ "set_nbt" ] } } }, + { "$ref": "loot_table_functions.schema.json#/setNbt" } + ] + }, + { } + ] + } + } +} diff --git a/src/main/resources/jsonSchemas/loot_table_conditions.schema.json b/src/main/resources/jsonSchemas/loot_table_conditions.schema.json new file mode 100644 index 000000000..b50483727 --- /dev/null +++ b/src/main/resources/jsonSchemas/loot_table_conditions.schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "entityProperties": { + "properties": { + "entity": { + "type": "string", + "enum": [ "this", "killer", "killer_player" ] + }, + "properties": { + "type": "object", + "properties": { + "on_fire": { "type": "boolean" } + } + } + } + }, + "entityScores": { + "properties": { + "entity": { + "type": "string", + "enum": [ "this", "killer", "killer_player" ] + }, + "scores": { + "type": "object", + "additionalProperties": { "$ref": "common.schema.json#/integerRange" } + } + } + }, + "killedByPlayer": { + "properties": { + "on_fire": { "type": "inverse" } + } + }, + "randomChance": { + "properties": { + "chance": { "type": "number", "minimum": 0, "maximum": 1 } + } + }, + "randomChanceWithLooting": { + "properties": { + "chance": { "type": "number", "minimum": 0, "maximum": 1 }, + "looting_multiplier": { "type": "number" } + } + } +} diff --git a/src/main/resources/jsonSchemas/loot_table_functions.schema.json b/src/main/resources/jsonSchemas/loot_table_functions.schema.json new file mode 100644 index 000000000..55ae4b996 --- /dev/null +++ b/src/main/resources/jsonSchemas/loot_table_functions.schema.json @@ -0,0 +1,76 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "enchantRandomly": { + "properties": { + "enchantments": { + "type": "array", + "items": { "type": "string" } + } + } + }, + "enchantWithLevels": { + "properties": { + "treasure": { "type": "boolean" }, + "levels": { "$ref": "common.schema.json#/integerRange" } + } + }, + "explorationMap": { + "properties": { + "destination": { "type": "string" }, + "decoration": { "type": "string" }, + "zoom": { "type": "integer" }, + "search_radius": { "type": "integer" }, + "skip_existing_chunks": { "type": "boolean" } + } + }, + "lootingEnchant": { + "properties": { + "limit": { "type": "integer", "minimum": 0 }, + "count": { "$ref": "common.schema.json#/integerRange" } + } + }, + "setAttributes": { + "properties": { + "modifiers": { + "type": "array", + "items": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "attribute": { "type": "string" }, + "operation": { "type": "string", "enum": [ "addition", "multiply_base", "multiply_total" ] }, + "amount": { "$ref": "common.schema.json#/floatRange" }, + "id": { "type": "string" }, + "slot": { "$ref": "common.schema.json#/equipmentSlots" } + }, + "additionalProperties": false, + "required": [ "name", "attribute", "operation", "amount" ] + } + } + } + }, + "setCount": { + "properties": { + "count": { "$ref": "common.schema.json#/integerRange" } + }, + "required": [ "count" ] + }, + "setDamage": { + "properties": { + "damage": { "$ref": "common.schema.json#/floatRange" } + }, + "required": [ "damage" ] + }, + "setData": { + "properties": { + "data": { "$ref": "common.schema.json#/integerRange" } + }, + "required": [ "data" ] + }, + "setNbt": { + "properties": { + "tag": { "type": "string" } + }, + "required": [ "tag" ] + } +} From 6c4dc173fc1c565a4f9ebad4d094046248c55f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Sun, 8 Apr 2018 00:58:03 +0200 Subject: [PATCH 10/11] Remove additional properties restrictions and explicit comment properties --- .../resources/jsonSchemas/blockstates_common.schema.json | 4 +--- src/main/resources/jsonSchemas/blockstates_forge.schema.json | 2 -- .../resources/jsonSchemas/blockstates_vanilla.schema.json | 2 -- src/main/resources/jsonSchemas/loot_table.schema.json | 4 ---- src/main/resources/jsonSchemas/model_block.schema.json | 1 - src/main/resources/jsonSchemas/model_common.schema.json | 5 +---- src/main/resources/jsonSchemas/model_item.schema.json | 1 - 7 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/main/resources/jsonSchemas/blockstates_common.schema.json b/src/main/resources/jsonSchemas/blockstates_common.schema.json index 12f8f0c79..63ab4f5b1 100644 --- a/src/main/resources/jsonSchemas/blockstates_common.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_common.schema.json @@ -4,7 +4,6 @@ "baseVariant": { "type": "object", "properties": { - "__comment": { "type": "string" }, "model": { "type": "string" }, "textures": { "type": "object", @@ -19,7 +18,6 @@ "multipleOf": 22.5 }, "uvlock": { "type": "boolean" } - }, - "additionalProperties": false + } } } diff --git a/src/main/resources/jsonSchemas/blockstates_forge.schema.json b/src/main/resources/jsonSchemas/blockstates_forge.schema.json index 8fcc91931..a21c28df9 100644 --- a/src/main/resources/jsonSchemas/blockstates_forge.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_forge.schema.json @@ -7,12 +7,10 @@ "type": "integer", "enum": [ 1 ] }, - "__comment": { "type": "string" }, "variants": { "$ref": "#/definitions/variants" }, "defaults": { "$ref": "#/definitions/variantObject" } }, "required": [ "forge_marker" ], - "additionalProperties": false, "definitions": { "variants": { "type": "object", diff --git a/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json index 39fa07597..830425cd0 100644 --- a/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json +++ b/src/main/resources/jsonSchemas/blockstates_vanilla.schema.json @@ -3,7 +3,6 @@ "title": "Minecraft Vanilla Blockstates JSON", "type": "object", "properties": { - "__comment": { "type": "string" }, "variants": { "type": "object", "patternProperties": { @@ -16,7 +15,6 @@ "items": { "$ref": "#/definitions/multipartCase" } } }, - "additionalProperties": false, "dependencies": { "variants": { "required": [ "variants" ], diff --git a/src/main/resources/jsonSchemas/loot_table.schema.json b/src/main/resources/jsonSchemas/loot_table.schema.json index d02355b87..d892aef55 100644 --- a/src/main/resources/jsonSchemas/loot_table.schema.json +++ b/src/main/resources/jsonSchemas/loot_table.schema.json @@ -3,13 +3,11 @@ "title": "Minecraft Loot Table JSON", "type": "object", "properties": { - "__comment": { "type": "string" }, "pools": { "type": "array", "items": { "type": "object", "properties": { - "__comment": { "type": "string" }, "conditions": { "$ref": "#/definitions/conditions" }, "rolls": { "$ref": "common.schema.json#/integerRange" }, "bonusRolls": { "$ref": "common.schema.json#/integerRange" }, @@ -53,12 +51,10 @@ } } }, - "additionalProperties": false, "required": [ "entries" ] } } }, - "additionalProperties": false, "definitions": { "conditions": { "type": "array", diff --git a/src/main/resources/jsonSchemas/model_block.schema.json b/src/main/resources/jsonSchemas/model_block.schema.json index dac2af1c9..464aac96b 100644 --- a/src/main/resources/jsonSchemas/model_block.schema.json +++ b/src/main/resources/jsonSchemas/model_block.schema.json @@ -3,7 +3,6 @@ "title": "Minecraft Block Model JSON", "type": "object", "properties": { - "__comment": { "type": "string" }, "parent": { "type": "string" }, "textures": { "type": "object", diff --git a/src/main/resources/jsonSchemas/model_common.schema.json b/src/main/resources/jsonSchemas/model_common.schema.json index fda26d335..0bd9bfd3f 100644 --- a/src/main/resources/jsonSchemas/model_common.schema.json +++ b/src/main/resources/jsonSchemas/model_common.schema.json @@ -5,7 +5,6 @@ "items": { "type": "object", "properties": { - "__comment": { "type": "string" }, "from": { "$ref": "#/elementCoord" }, "to": { "$ref": "#/elementCoord" }, "rotation": { @@ -55,14 +54,12 @@ "tintindex": { "type": "integer" } - }, - "additionalProperties": false + } } }, "additionalProperties": false } }, - "additionalProperties": false, "required": [ "from", "to" ] } }, diff --git a/src/main/resources/jsonSchemas/model_item.schema.json b/src/main/resources/jsonSchemas/model_item.schema.json index dc8fe1ef3..adf2780b6 100644 --- a/src/main/resources/jsonSchemas/model_item.schema.json +++ b/src/main/resources/jsonSchemas/model_item.schema.json @@ -3,7 +3,6 @@ "title": "Minecraft Item Model JSON", "type": "object", "properties": { - "__comment": { "type": "string" }, "parent": { "type": "string" }, "textures": { "type": "object", From c139159629f99740cf9315fc7ece5aa36a3b5021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20R=C3=B6sch?= Date: Fri, 20 Apr 2018 22:54:42 +0200 Subject: [PATCH 11/11] Add advancement schema (without verifying criteria right now) --- .../demonwav/mcdev/json/schema_providers.kt | 3 +- .../jsonSchemas/advancement.schema.json | 112 ++++++++++++++++++ .../resources/jsonSchemas/common.schema.json | 6 + 3 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/main/resources/jsonSchemas/advancement.schema.json diff --git a/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt index ff4cf2a45..a8e49f419 100644 --- a/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt +++ b/src/main/kotlin/com/demonwav/mcdev/json/schema_providers.kt @@ -25,7 +25,8 @@ class SchemaProviderFactory : JsonSchemaProviderFactory { PathBasedSchemaProvider("Minecraft Blockstates JSON", "blockstates", "blockstates/"), PathBasedSchemaProvider("Minecraft Item Model JSON", "model_item", "models/item/"), PathBasedSchemaProvider("Minecraft Block Model JSON", "model_block", "models/block/"), - PathBasedSchemaProvider("Minecraft Loot Table JSON", "loot_table", "loot_tables/") + PathBasedSchemaProvider("Minecraft Loot Table JSON", "loot_table", "loot_tables/"), + PathBasedSchemaProvider("Minecraft Advancement JSON", "advancement", "advancements/") ) } diff --git a/src/main/resources/jsonSchemas/advancement.schema.json b/src/main/resources/jsonSchemas/advancement.schema.json new file mode 100644 index 000000000..e6aaf2c6b --- /dev/null +++ b/src/main/resources/jsonSchemas/advancement.schema.json @@ -0,0 +1,112 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "Minecraft Advancement JSON", + "type": "object", + "properties": { + "display": { + "type": "object", + "properties": { + "icon": { + "type": "object", + "properties": { + "item": { "type": "string" }, + "data": { "type": "integer", "minimum": 0, "maximum": 32767 } + }, + "required": [ "item" ] + }, + "title": { "$ref": "common.json#/textComponent" }, + "frame": { + "anyOf": [ + { "type": "string" }, + { "enum": [ "task", "goal", "challenge" ], "default": "task" } + ] + }, + "background": { "type": "string" }, + "description": { "$ref": "common.json#/textComponent" }, + "show_toast": { "type": "boolean" }, + "announce_to_chat": { "type": "boolean" }, + "hidden": { "type": "boolean" } + }, + "required": [ "title", "description", "icon" ] + }, + "parent": { "type": "string" }, + "criteria": { + "type": "object", + "additionalProperties": { "$ref": "#/definitions/trigger" }, + "minProperties": 1 + }, + "requirements": { + "type": "array", + "items": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + } + }, + "rewards": { + "type": "object", + "properties": { + "recipes": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "loot": { + "type": "array", + "items": { "type": "string", "minLength": 1 } + }, + "experience": { "type": "integer" }, + "function": { "type": "string" } + } + } + }, + "require": [ "criteria" ], + "definitions": { + "trigger": { + "type": "object", + "properties": { + "trigger": { + "anyOf": [ + { "type": "string" }, + { + "type": "string", + "enum": [ + "minecraft:bred_animals", + "minecraft:brewed_potion", + "minecraft:changed_dimension", + "minecraft:channeled_lightning", + "minecraft:construct_beacon", + "minecraft:consume_item", + "minecraft:cured_zombie_villager", + "minecraft:effects_changed", + "minecraft:enchanted_item", + "minecraft:enter_block", + "minecraft:entity_hurt_player", + "minecraft:entity_killed_player", + "minecraft:filled_bucket", + "minecraft:fishing_rod_hooked", + "minecraft:impossible", + "minecraft:inventory_changed", + "minecraft:item_durability_changed", + "minecraft:levitation", + "minecraft:location", + "minecraft:nether_travel", + "minecraft:nether_travel", + "minecraft:placed_block", + "minecraft:player_hurt_entity", + "minecraft:player_killed_entity", + "minecraft:recipe_unlocked", + "minecraft:slept_in_bed", + "minecraft:summoned_entity", + "minecraft:tame_animal", + "minecraft:tick", + "minecraft:used_ender_eye", + "minecraft:used_totem", + "minecraft:villager_trade" + ] + } + ] + } + }, + "required": [ "trigger" ] + } + } +} diff --git a/src/main/resources/jsonSchemas/common.schema.json b/src/main/resources/jsonSchemas/common.schema.json index fc6675bbb..3eaa88183 100644 --- a/src/main/resources/jsonSchemas/common.schema.json +++ b/src/main/resources/jsonSchemas/common.schema.json @@ -38,5 +38,11 @@ { "$ref": "#/equipmentSlot" }, { "type": "array", "items": { "$ref": "#/equipmentSlot" } } ] + }, + "textComponent": { + "anyOf": [ + { "type": "string" }, + { "type": "object" } + ] } }