From 3fe6dcdb9209ba55e3e5a070239ea15c55520483 Mon Sep 17 00:00:00 2001 From: Misode Date: Tue, 11 Nov 2025 15:23:59 +0100 Subject: [PATCH] Fix #813 item displays in recipe viewer in 1.20.4 --- .../components/generator/McdocRenderer.tsx | 12 +- src/app/components/previews/Recipe.ts | 144 +++++++++++++++ src/app/components/previews/Recipe1204.ts | 127 ++++++++++++++ src/app/components/previews/RecipePreview.tsx | 166 ++---------------- 4 files changed, 297 insertions(+), 152 deletions(-) create mode 100644 src/app/components/previews/Recipe.ts create mode 100644 src/app/components/previews/Recipe1204.ts diff --git a/src/app/components/generator/McdocRenderer.tsx b/src/app/components/generator/McdocRenderer.tsx index 5252231c..a74c40f4 100644 --- a/src/app/components/generator/McdocRenderer.tsx +++ b/src/app/components/generator/McdocRenderer.tsx @@ -8,16 +8,20 @@ import type { ListType, LiteralType, McdocType, NumericType, PrimitiveArrayType, import { handleAttributes } from '@spyglassmc/mcdoc/lib/runtime/attribute/index.js' import type { SimplifiedEnum, SimplifiedMcdocType, SimplifiedMcdocTypeNoUnion, SimplifiedStructType, SimplifiedStructTypePairField } from '@spyglassmc/mcdoc/lib/runtime/checker/index.js' import { getValues } from '@spyglassmc/mcdoc/lib/runtime/completer/index.js' -import { Identifier, ItemStack } from 'deepslate' +import { Identifier as Identifier1204, ItemStack as ItemStack1204 } from 'deepslate-1.20.4/core' +import { Identifier, ItemStack } from 'deepslate/core' import DOMPurify from 'dompurify' import { marked } from 'marked' import { useCallback, useEffect, useMemo, useState } from 'preact/hooks' import config from '../../Config.js' import { useLocale } from '../../contexts/Locale.jsx' +import { useVersion } from '../../contexts/Version.jsx' import { useFocus } from '../../hooks/useFocus.js' +import { checkVersion } from '../../services/Versions.js' import { generateColor, hexId, intToHexRgb, randomInt, randomSeed } from '../../Utils.js' import { Btn } from '../Btn.jsx' import { ItemDisplay } from '../ItemDisplay.jsx' +import { ItemDisplay1204 } from '../ItemDisplay1204.jsx' import { Octicon } from '../Octicon.jsx' import { formatIdentifier, getCategory, getChange, getDefault, getItemType, isDefaultCollapsedType, isFixedList, isInlineTuple, isListOrArray, isNumericType, isSelectRegistry, quickEqualTypes, simplifyType } from './McdocHelpers.js' @@ -138,6 +142,8 @@ const SPECIAL_UNSET = '__unset__' function StringHead({ type, optional, excludeStrings, node, ctx }: Props) { const { locale } = useLocale() + const { version } = useVersion() + const use1204 = !checkVersion(version, '1.20.5') const nodeValue = (JsonStringNode.is(node) ? node.value : undefined)?.replaceAll('\n', '\\n') const [value, setValue] = useState(nodeValue) @@ -202,7 +208,9 @@ function StringHead({ type, optional, excludeStrings, node, ctx }: Props {((idRegistry === 'item' || idRegistry === 'block') && idTags !== 'implicit' && value && !value.startsWith('#')) && } {isSelect ? <>