diff --git a/src/app/components/previews/LootTable.ts b/src/app/components/previews/LootTable.ts index 6315178b..949f0b30 100644 --- a/src/app/components/previews/LootTable.ts +++ b/src/app/components/previews/LootTable.ts @@ -229,11 +229,15 @@ function createItem(entry: any, consumer: ItemConsumer, ctx: LootContext) { } switch (type) { case 'item': - entryConsumer(new ItemStack(Identifier.parse(entry.name), 1)) + try { + entryConsumer(new ItemStack(Identifier.parse(entry.name), 1)) + } catch (e) {} break case 'tag': ctx.getItemTag(entry.name).forEach(tagEntry => { - entryConsumer(new ItemStack(Identifier.parse(tagEntry), 1)) + try { + entryConsumer(new ItemStack(Identifier.parse(tagEntry), 1)) + } catch (e) {} }) break case 'loot_table': @@ -280,7 +284,10 @@ const LootFunctions: Record LootFunction> = { } if (enchantments.length > 0) { const id = enchantments[ctx.random.nextInt(enchantments.length)] - const ench = Enchantment.REGISTRY.get(Identifier.parse(id)) + let ench: Enchantment | undefined + try { + ench = Enchantment.REGISTRY.get(Identifier.parse(id)) + } catch (e) {} if (ench === undefined) return const lvl = ctx.random.nextInt(ench.maxLevel - ench.minLevel + 1) + ench.minLevel if (isBook) { @@ -337,7 +344,9 @@ const LootFunctions: Record LootFunction> = { set_enchantments: ({ enchantments, add }) => (item, ctx) => { Object.entries(enchantments).forEach(([id, level]) => { const lvl = computeInt(level, ctx) - enchantItem(item, { id: Identifier.parse(id), lvl }, add) + try { + enchantItem(item, { id: Identifier.parse(id), lvl }, add) + } catch (e) {} }) }, set_lore: ({ lore, replace }) => (item) => { @@ -361,7 +370,9 @@ const LootFunctions: Record LootFunction> = { }, set_potion: ({ id }) => (item) => { if (typeof id === 'string') { - item.tag.set('Potion', new NbtString(Identifier.parse(id).toString())) + try { + item.tag.set('Potion', new NbtString(Identifier.parse(id).toString())) + } catch (e) {} } }, } diff --git a/src/app/schema/renderHtml.tsx b/src/app/schema/renderHtml.tsx index 8c5fb5c7..9d4ca3cc 100644 --- a/src/app/schema/renderHtml.tsx +++ b/src/app/schema/renderHtml.tsx @@ -1,18 +1,18 @@ import type { BooleanHookParams, EnumOption, Hook, INode, NodeChildren, NumberHookParams, StringHookParams, ValidationOption } from '@mcschema/core' -import { DataModel, ListNode, MapNode, ModelPath, ObjectNode, Path, relativePath, StringNode } from '@mcschema/core' +import { DataModel, ListNode, MapNode, ModelPath, ObjectNode, Path, StringNode, relativePath } from '@mcschema/core' import { Identifier, ItemStack } from 'deepslate/core' import type { ComponentChildren, JSX } from 'preact' import { memo } from 'preact/compat' import { useState } from 'preact/hooks' -import { Btn, Octicon } from '../components/index.js' -import { ItemDisplay } from '../components/ItemDisplay.jsx' -import { VanillaColors } from '../components/previews/BiomeSourcePreview.jsx' import config from '../Config.js' +import { deepClone, deepEqual, generateUUID, hexId, hexToRgb, isObject, newSeed, rgbToHex, stringToColor } from '../Utils.js' +import { ItemDisplay } from '../components/ItemDisplay.jsx' +import { Btn, Octicon } from '../components/index.js' +import { VanillaColors } from '../components/previews/BiomeSourcePreview.jsx' import { localize, useLocale, useStore } from '../contexts/index.js' import { useFocus } from '../hooks/index.js' import type { BlockStateRegistry, VersionId } from '../services/index.js' import { CachedDecorator, CachedFeature } from '../services/index.js' -import { deepClone, deepEqual, generateUUID, hexId, hexToRgb, isObject, newSeed, rgbToHex, stringToColor } from '../Utils.js' import { ModelWrapper } from './ModelWrapper.js' const selectRegistries = ['loot_table.type', 'loot_entry.type', 'function.function', 'condition.condition', 'criterion.trigger', 'recipe.type', 'dimension.generator.type', 'dimension.generator.biome_source.type', 'dimension.generator.biome_source.preset', 'carver.type', 'feature.type', 'decorator.type', 'feature.tree.minimum_size.type', 'block_state_provider.type', 'trunk_placer.type', 'foliage_placer.type', 'tree_decorator.type', 'int_provider.type', 'float_provider.type', 'height_provider.type', 'structure_feature.type', 'surface_builder.type', 'processor.processor_type', 'rule_test.predicate_type', 'pos_rule_test.predicate_type', 'template_element.element_type', 'block_placer.type', 'block_predicate.type', 'material_rule.type', 'material_condition.type', 'structure_placement.type', 'density_function.type', 'root_placer.type', 'entity.type_specific.cat.variant', 'entity.type_specific.frog.variant', 'rule_block_entity_modifier.type'] @@ -140,7 +140,13 @@ const renderHtml: RenderHook = { let label: undefined | string | JSX.Element if (['loot_pool.entries.entry', 'loot_entry.alternatives.children.entry', 'loot_entry.group.children.entry', 'loot_entry.sequence.children.entry', 'function.set_contents.entries.entry'].includes(cPath.getContext().join('.'))) { if (isObject(cValue) && typeof cValue.type === 'string' && cValue.type.replace(/^minecraft:/, '') === 'item' && typeof cValue.name === 'string') { - label = + let itemStack: ItemStack | undefined + try { + itemStack = new ItemStack(Identifier.parse(cValue.name), 1) + } catch (e) {} + if (itemStack !== undefined) { + label = + } } }