import React from 'react' import { useInventoryContext } from '../../context/InventoryContext' import { useScale } from '../../context/ScaleContext' import { useTextures } from '../../context/TextureContext' import { Slot } from '../Slot' import type { ItemStack } from '../../types' interface HotbarExtrasProps { showOffhand: boolean container: boolean offhandItem: ItemStack | null } /** Renders a sprite from the widgets.png using the same inner-div+transform approach as InventoryBackground */ function WidgetSprite({ url, srcX, srcY, srcW, srcH, scale, style, }: { url: string srcX: number srcY: number srcW: number srcH: number scale: number style?: React.CSSProperties }) { return (
) } /** * Hotbar-specific extras rendered inside InventoryBackground alongside the regular slots. * Mirrors layouts.mjs Hotbar children: * - Active slot indicator (always) * - Offhand slot left of the strip (when showOffhand) * - Open-inventory button right of the strip (when container) */ export function HotbarExtras({ showOffhand, container, offhandItem }: HotbarExtrasProps) { const { playerState, sendAction } = useInventoryContext() const { scale } = useScale() const textures = useTextures() const activeSlot = playerState?.activeHotbarSlot ?? 0 const hotbarUrl = textures.getGuiTextureUrl('1.15/textures/gui/widgets.png') // Sprite regions within widgets.png (native pixels): // Hotbar strip : [0, 0, 182, 22] // Active box : [0, 22, 24, 24] // Offhand box : [24, 22, 24, 24] const GAP = 2 return ( <> {/* ── Active slot indicator ── */} {/* ── Offhand slot (left of hotbar) ── */} {showOffhand && (
{/* Item at slot 45 (offhand) */}
)} {/* ── Open-inventory button (right of hotbar) ── */} {container && (
sendAction({ type: 'open-inventory' })} onTouchEnd={(e) => { e.stopPropagation() e.preventDefault() sendAction({ type: 'open-inventory' }) }} > {/* Three white dots centered */} {[0, 1, 2].map((i) => (
))}
)} ) }