From cf83e9ef35918b8764956041762f893a38667230 Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 21 Mar 2026 16:43:37 -0400 Subject: [PATCH] Add item utility functions for Minecraft icons and formatting --- web/client/src/utils/itemUtils.js | 128 ++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 web/client/src/utils/itemUtils.js diff --git a/web/client/src/utils/itemUtils.js b/web/client/src/utils/itemUtils.js new file mode 100644 index 0000000..4143bb7 --- /dev/null +++ b/web/client/src/utils/itemUtils.js @@ -0,0 +1,128 @@ +/** + * Minecraft item icon utility + * Uses mc-heads.net item renders for actual Minecraft item icons + */ + +// Format an item name for display +export function formatItemName(name) { + if (!name) return ''; + return name + .replace(/^[a-z0-9_]+:/, '') // Strip mod prefix + .replace(/_/g, ' ') + .replace(/\b\w/g, (c) => c.toUpperCase()); +} + +// Get icon URL for a Minecraft item +// Uses mc-heads.net which provides 2D item renders +export function getItemIconUrl(itemName, size = 32) { + if (!itemName) return null; + // mc-heads.net format: https://mc-heads.net/item/{item_name} + // Alternatively we can use crafatar or other MC icon APIs + // For items, we use a simple mapping approach + return `https://mc-heads.net/item/${itemName}/${size}`; +} + +// Fallback emoji mapping for common item categories +const CATEGORY_EMOJI = { + ingot: '๐Ÿช™', + ore: 'โ›๏ธ', + raw: '๐Ÿชจ', + log: '๐Ÿชต', + planks: '๐Ÿชต', + wool: '๐Ÿงถ', + dye: '๐ŸŽจ', + seed: '๐ŸŒฑ', + crop: '๐ŸŒพ', + wheat: '๐ŸŒพ', + food: '๐Ÿ–', + cooked: '๐Ÿ—', + beef: '๐Ÿฅฉ', + porkchop: '๐Ÿฅฉ', + chicken: '๐Ÿ—', + mutton: '๐Ÿฅฉ', + cod: '๐ŸŸ', + salmon: '๐ŸŸ', + potato: '๐Ÿฅ”', + carrot: '๐Ÿฅ•', + apple: '๐ŸŽ', + bread: '๐Ÿž', + sword: 'โš”๏ธ', + pickaxe: 'โ›๏ธ', + axe: '๐Ÿช“', + shovel: '๐Ÿช', + hoe: '๐ŸŒฟ', + helmet: '๐Ÿช–', + chestplate: '๐Ÿ‘•', + leggings: '๐Ÿ‘–', + boots: '๐Ÿ‘ข', + bow: '๐Ÿน', + arrow: '๐Ÿน', + shield: '๐Ÿ›ก๏ธ', + diamond: '๐Ÿ’Ž', + emerald: '๐Ÿ’š', + redstone: '๐Ÿ”ด', + lapis: '๐Ÿ”ต', + coal: 'โšซ', + iron: 'โฌœ', + gold: '๐ŸŸก', + netherite: 'โฌ›', + stone: '๐Ÿชจ', + cobblestone: '๐Ÿชจ', + dirt: '๐ŸŸซ', + sand: '๐ŸŸจ', + gravel: 'โฌœ', + glass: '๐Ÿ”ฒ', + brick: '๐Ÿงฑ', + torch: '๐Ÿ”ฆ', + bone: '๐Ÿฆด', + string: '๐Ÿงต', + leather: '๐ŸŸค', + feather: '๐Ÿชถ', + egg: '๐Ÿฅš', + book: '๐Ÿ“•', + paper: '๐Ÿ“„', + bucket: '๐Ÿชฃ', + potion: '๐Ÿงช', + pearl: '๐ŸŸฃ', + blaze: '๐Ÿ”ฅ', + gunpowder: '๐Ÿ’ฃ', + sugar: '๐Ÿฌ', + stick: '๐Ÿชต', + chest: '๐Ÿ“ฆ', + furnace: '๐Ÿ”ฅ', + sponge: '๐Ÿงฝ', + kelp: '๐ŸŒฟ', + cactus: '๐ŸŒต', +}; + +export function getItemEmoji(itemName) { + if (!itemName) return '๐Ÿ“ฆ'; + const name = itemName.replace(/^[a-z0-9_]+:/, '').toLowerCase(); + + // Check direct matches + for (const [key, emoji] of Object.entries(CATEGORY_EMOJI)) { + if (name.includes(key)) return emoji; + } + + return '๐Ÿ“ฆ'; +} + +// Compact number formatting +export function formatCount(count) { + if (count >= 1000000) return `${(count / 1000000).toFixed(1)}M`; + if (count >= 1000) return `${(count / 1000).toFixed(1)}K`; + return count.toString(); +} + +// Get rarity color based on item name +export function getRarityColor(itemName) { + if (!itemName) return '#ffffff'; + const name = itemName.toLowerCase(); + if (name.includes('netherite')) return '#4a2a4a'; + if (name.includes('diamond')) return '#4aedd9'; + if (name.includes('emerald')) return '#17dd62'; + if (name.includes('gold') || name.includes('golden')) return '#ffaa00'; + if (name.includes('iron')) return '#d8d8d8'; + if (name.includes('enchanted') || name.includes('nether_star')) return '#ff55ff'; + return '#ffffff'; +}