From a4df95e0490d8b7bf6ff5dc6e01103abad5d4c68 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 21 Mar 2026 16:49:44 -0400 Subject: [PATCH] Add ItemIcon component for rendering Minecraft item icons --- web/client/src/components/ItemIcon.jsx | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 web/client/src/components/ItemIcon.jsx diff --git a/web/client/src/components/ItemIcon.jsx b/web/client/src/components/ItemIcon.jsx new file mode 100644 index 0000000..d0fc3d2 --- /dev/null +++ b/web/client/src/components/ItemIcon.jsx @@ -0,0 +1,42 @@ +import React, { useState } from 'react'; +import { getItemEmoji } from '../utils/itemUtils'; +import './ItemIcon.css'; + +/** + * Renders a Minecraft item icon. + * First tries to load the actual item sprite from mc-heads.net. + * Falls back to an emoji representation if the image fails. + */ +function ItemIcon({ itemName, size = 32 }) { + const [imgError, setImgError] = useState(false); + + if (!itemName) { + return 📦; + } + + // Strip namespace for the icon URL + const shortName = itemName.replace(/^[a-z0-9_]+:/, ''); + + if (imgError) { + return ( + + {getItemEmoji(itemName)} + + ); + } + + return ( + {shortName} setImgError(true)} + style={{ imageRendering: 'pixelated' }} + /> + ); +} + +export default ItemIcon;