From b1f632673f5133ec157b9f631bc43365f1b2f453 Mon Sep 17 00:00:00 2001 From: Misode Date: Wed, 25 Sep 2019 14:09:16 +0200 Subject: [PATCH] Add damage source properties --- model.js | 18 ++++++++-- schemas/1.14.json | 83 ++++++++++++++++++++++++++++++++++++++++++++++- view.js | 5 ++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/model.js b/model.js index 024015f4..93fe990c 100644 --- a/model.js +++ b/model.js @@ -246,7 +246,7 @@ function updateField(el) { let type = getType(el); let value = undefined; - if (type === 'string' || type === 'int' || type === 'float' || type === 'enum' || type === 'json' || type === 'nbt') { + if (type === 'string' || type === 'int' || type === 'float' || type === 'enum' || type === 'json' || type === 'nbt' || type === 'chance-list') { value = $(el).val(); } if (type === 'int') { @@ -259,7 +259,21 @@ function updateField(el) { if (isNaN(value)) { value = ''; } - } else if(type === 'enum') { + } else if (type === 'chance-list') { + value = '[' + value + ']'; + try { + value = JSON.parse(value); + for (let i = 0; i < value.length; i += 1) { + if (value[i] > 1) { + value[i] = 1; + } else if (value[i] < 0) { + value[i] = 0; + } + } + } catch(e) { + value = []; + } + } else if (type === 'enum') { if (value === 'unset') { value = ''; } diff --git a/schemas/1.14.json b/schemas/1.14.json index 54066a3c..03f9a192 100644 --- a/schemas/1.14.json +++ b/schemas/1.14.json @@ -423,7 +423,7 @@ }, { "id": "chances", - "type": "list", + "type": "chance-list", "require": [ "minecraft:table_bonus" ] @@ -466,6 +466,14 @@ "minecraft:match_tool" ] }, + { + "id": "predicate", + "type": "object", + "value": "damage_source", + "require": [ + "minecraft:damage_source_properties" + ] + }, { "id": "term", "type": "object", @@ -655,6 +663,79 @@ "type": "nbt" } ] + }, + { + "id": "damage_source", + "type": "object", + "color": "dark", + "fields": [ + { + "id": "dealt", + "type": "range" + }, + { + "id": "taken", + "type": "range" + }, + { + "id": "blocked", + "type": "boolean" + }, + { + "id": "type", + "type": "object", + "color": "dark", + "collapse": true, + "fields": [ + { + "id": "is_explosion", + "type": "boolean" + }, + { + "id": "is_projectile", + "type": "boolean" + }, + { + "id": "is_fire", + "type": "boolean" + }, + { + "id": "is_lightning", + "type": "boolean" + }, + { + "id": "is_magic", + "type": "boolean" + }, + { + "id": "bypasses_magic", + "type": "boolean" + }, + { + "id": "bypasses_invulnerability", + "type": "boolean" + }, + { + "id": "bypasses_armor", + "type": "boolean" + } + ] + }, + { + "id": "source_entity", + "type": "object", + "color": "dark", + "collapse": true, + "value": "entity" + }, + { + "id": "direct_entity", + "type": "object", + "color": "dark", + "collapse": true, + "value": "entity" + } + ] } ], "collections": { diff --git a/view.js b/view.js index 63c46adf..b5ff6cfe 100644 --- a/view.js +++ b/view.js @@ -58,6 +58,7 @@ function generateComponent(data, struct) { case 'string': return generateString(data, struct); case 'int': return generateString(data, struct); case 'float': return generateString(data, struct); + case 'chance-list': return generateString(data, struct); case 'boolean': return generateBoolean(data, struct); case 'random': return generateRandom(data, struct); case 'range': return generateRange(data, struct); @@ -76,6 +77,7 @@ function generateComponent(data, struct) { function generateString(data, struct) { let $el = $('#components').find('[data-type="string"]').clone(); + $el.attr('data-type', struct.type); $el.attr('data-index', struct.id); $el.find('[data-name]').attr('data-i18n', struct.id); $el.find('input').val(data); @@ -282,7 +284,8 @@ function generateObject(data, struct, header) { if (field.collapse) { $body.append(''); if (data[field.id] === undefined) { - break; + $body.append('
'); + continue; } } try {