diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index f2b9629f..44dff9d2 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -101,6 +101,14 @@ function StringHead({ type, node, makeEdit, ctx }: StringHeadProps) { }) }, [node, makeEdit]) + const idAttribute = type.attributes?.find(a => a.name === 'id')?.value + const idRegistry = idAttribute?.kind === 'literal' && idAttribute.value.kind === 'string' + ? idAttribute.value.value + : idAttribute?.kind === 'tree' && idAttribute.values.registry?.kind === 'literal' && idAttribute.values.registry?.value.kind === 'string' + ? idAttribute.values.registry?.value.value + : undefined + const isSelect = idRegistry && selectRegistries.has(idRegistry) + const completions = useMemo(() => { return getValues(type, { ...ctx, offset: node?.range.start ?? 0 }) .filter(c => c.kind === 'string') @@ -117,10 +125,16 @@ function StringHead({ type, node, makeEdit, ctx }: StringHeadProps) { }, [onChangeValue]) return <> - {completions.length > 0 && - {completions.map(c => )} - } - onChangeValue((e.target as HTMLInputElement).value)} list={completions.length > 0 ? datalistId : undefined} /> + {isSelect ? <> + + : <> + {completions.length > 0 && + {completions.map(c => )} + } + onChangeValue((e.target as HTMLInputElement).value)} list={completions.length > 0 ? datalistId : undefined} /> + } {colorKind === 'hex_rgb' && <> onChangeValue((e.target as HTMLInputElement).value)} /> @@ -170,7 +184,7 @@ function EnumHead({ type, optional, node, makeEdit }: EnumHeadProps) { return } @@ -271,7 +285,7 @@ function UnionHead({ type, optional, node, makeEdit, ctx }: UnionHeadProps) { {(selectedType || !optional) && } @@ -483,9 +497,7 @@ function StructBody({ type: outerType, node, makeEdit, ctx }: StructBodyProps) { } function Key({ label }: { label: string | number | boolean }) { - const formatted = label.toString().replaceAll('_', ' ') - const captizalized = formatted.charAt(0).toUpperCase() + formatted.substring(1) - return + return } interface ListBodyProps extends Props { @@ -735,6 +747,11 @@ function getDefault(type: McdocType, range: core.Range, ctx: McdocContext): Json return { type: 'json:null', range } } +function formatIdentifier(id: string) { + const formatted = id.replace(/^minecraft:/, '').replaceAll('_', ' ') + return formatted.charAt(0).toUpperCase() + formatted.substring(1) +} + function getCategory(type: McdocType) { if (type.kind === 'reference' && type.path) { switch (type.path) { @@ -755,6 +772,63 @@ function getCategory(type: McdocType) { return undefined } +const selectRegistries = new Set([ + 'atlas', + 'block_predicate_type', + 'chunk_status', + 'consume_effect_type', + 'creative_mode_tab', + 'enchantment_effect_component_type', + 'enchantment_entity_effect_type', + 'enchantment_level_based_value_type', + 'enchantment_location_based_effect_type', + 'enchantment_provider_type', + 'enchantment_value_effect_type', + 'entity_sub_predicate_type', + 'float_provider_type', + 'frog_variant', + 'height_provider_type', + 'int_provider_type', + 'loot_condition_type', + 'loot_function_type', + 'loot_nbt_provider_type', + 'loot_number_provider_type', + 'loot_pool_entry_type', + 'loot_score_provider_type', + 'map_decoration_type', + 'number_format_type', + 'pos_rule_test', + 'position_source_type', + 'recipe_book_category', + 'recipe_display', + 'recipe_serializer', + 'recipe_type', + 'rule_block_entity_modifier', + 'rule_test', + 'slot_display', + 'stat_type', + 'trigger_type', + 'worldgen/biome_source', + 'worldgen/block_state_provider_type', + 'worldgen/carver', + 'worldgen/chunk_generator', + 'worldgen/density_function_type', + 'worldgen/feature', + 'worldgen/feature_size_type', + 'worldgen/foliage_placer_type', + 'worldgen/material_condition', + 'worldgen/material_rule', + 'worldgen/placement_modifier_type', + 'worldgen/pool_alias_binding', + 'worldgen/root_placer_type', + 'worldgen/structure_placement', + 'worldgen/structure_pool_element', + 'worldgen/structure_processor', + 'worldgen/structure_type', + 'worldgen/tree_decorator_type', + 'worldgen/trunk_placer_type', +]) + function simplifyType(type: McdocType, ctx: McdocContext): SimplifiedMcdocType { const node: SimplifyValueNode = { entryNode: { diff --git a/src/app/components/previews/LootTable.ts b/src/app/components/previews/LootTable.ts index 456ea733..9cdcbb5c 100644 --- a/src/app/components/previews/LootTable.ts +++ b/src/app/components/previews/LootTable.ts @@ -516,6 +516,9 @@ function testCondition(condition: any, ctx: LootContext): boolean { if (Array.isArray(condition)) { return composeConditions(condition)(ctx) } + if (!isObject(condition) || typeof condition.condition !== 'string') { + return false + } const type = condition.condition?.replace(/^minecraft:/, '') return (LootConditions[type]?.(condition) ?? (() => true))(ctx) } diff --git a/src/app/services/Spyglass.ts b/src/app/services/Spyglass.ts index c515dde6..177528e4 100644 --- a/src/app/services/Spyglass.ts +++ b/src/app/services/Spyglass.ts @@ -195,6 +195,9 @@ export class SpyglassService { gameVersion: version.ref ?? version.id, dependencies: ['@vanilla-mcdoc'], }, + lint: { + idOmitDefaultNamespace: false, + }, }), initializers: [mcdoc.initialize, initialize], },