Add damage source properties

This commit is contained in:
Misode
2019-09-25 14:09:16 +02:00
parent d36d77a945
commit b1f632673f
3 changed files with 102 additions and 4 deletions
+16 -2
View File
@@ -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 = '';
}
+82 -1
View File
@@ -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": {
+4 -1
View File
@@ -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('<button type="button" class="btn btn-light mt-3 dropdown-toggle" onclick="toggleCollapseObject(this)" data-index="' + field.id + '" data-i18n="' + field.id + '"></button>');
if (data[field.id] === undefined) {
break;
$body.append('<div/>');
continue;
}
}
try {