'use client' import { useState, useMemo } from 'react' import { useUIStore } from '@/stores/uiStore' import { usePlayerStore } from '@/stores/playerStore' import { BLOCK_DEFS, CREATIVE_BLOCKS, BLOCK_CATEGORIES } from '@/engine/constants' const CATEGORY_TABS = [ { key: 'all', label: 'All' }, { key: 'Natural', label: 'Natural' }, { key: 'Wood', label: 'Wood' }, { key: 'Ores', label: 'Ores' }, { key: 'Wool', label: 'Wool' }, { key: 'Concrete', label: 'Concrete' }, { key: 'Glass', label: 'Glass' }, { key: 'Bricks', label: 'Bricks' }, { key: 'Functional', label: 'Functional' }, { key: 'Redstone', label: 'Redstone' }, { key: 'Nether', label: 'Nether' }, { key: 'End', label: 'End' }, { key: 'Plants', label: 'Plants' }, { key: 'Lights', label: 'Lights' }, { key: 'Mineral Blocks', label: 'Minerals' }, { key: 'Copper', label: 'Copper' }, { key: 'Terracotta', label: 'Terracotta' }, ] export function CreativeInventory() { const { showInventory, setShowInventory } = useUIStore() const { player } = usePlayerStore() const [activeTab, setActiveTab] = useState('all') const [searchQuery, setSearchQuery] = useState('') if (!showInventory || !player) return null const handleSelect = (blockId: number) => { const { hotbarSlot } = useUIStore.getState() const newHotbar = [...player.inventory.hotbar] newHotbar[hotbarSlot] = { id: blockId, count: 64, damage: 0 } usePlayerStore.setState({ player: { ...player, inventory: { ...player.inventory, hotbar: newHotbar } } }) } // Get blocks for current tab const displayBlocks = useMemo(() => { let blocks: number[] if (activeTab === 'all') { blocks = CREATIVE_BLOCKS } else { blocks = BLOCK_CATEGORIES[activeTab] || [] } // Apply search filter if (searchQuery) { const query = searchQuery.toLowerCase() blocks = blocks.filter(id => { const def = BLOCK_DEFS[id] return def && def.name.toLowerCase().includes(query) }) } return blocks }, [activeTab, searchQuery]) return (
{ if (e.target === e.currentTarget) setShowInventory(false) }}>
{/* Header */}

Creative Inventory

{/* Search */}
setSearchQuery(e.target.value)} placeholder="Search blocks..." className="w-full px-3 py-1.5 bg-gray-800/80 border border-gray-600/50 rounded text-white text-sm placeholder-gray-500 focus:outline-none focus:border-blue-500" />
{/* Category tabs */}
{CATEGORY_TABS.map(tab => ( ))}
{/* Block grid */}
{displayBlocks.map((blockId) => { const def = BLOCK_DEFS[blockId] if (!def) return null return (
handleSelect(blockId)} title={def.name} >
{def.name}
) })}
{displayBlocks.length === 0 && (
No blocks found
)}
{/* Footer */}

{displayBlocks.length} blocks

Click a block to add to hotbar

) }