minecraft-inventory 0.1.12 → 0.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/InventoryGUI.tsx
CHANGED
|
@@ -24,6 +24,8 @@ export interface InventoryGUIProps {
|
|
|
24
24
|
textureBaseUrl?: string
|
|
25
25
|
textureConfig?: Partial<TextureConfig>
|
|
26
26
|
enableKeyboardShortcuts?: boolean
|
|
27
|
+
/** Hide empty slot labels like Head, Chest, Legs, Feet */
|
|
28
|
+
noPlaceholders?: boolean
|
|
27
29
|
onClose?: () => void
|
|
28
30
|
className?: string
|
|
29
31
|
style?: React.CSSProperties
|
|
@@ -42,6 +44,7 @@ export function InventoryGUI({
|
|
|
42
44
|
textureBaseUrl,
|
|
43
45
|
textureConfig,
|
|
44
46
|
enableKeyboardShortcuts = true,
|
|
47
|
+
noPlaceholders = false,
|
|
45
48
|
onClose,
|
|
46
49
|
className,
|
|
47
50
|
style,
|
|
@@ -64,7 +67,7 @@ export function InventoryGUI({
|
|
|
64
67
|
return (
|
|
65
68
|
<TextureProvider baseUrl={textureBaseUrl} config={textureConfig}>
|
|
66
69
|
<ScaleProvider scale={scale}>
|
|
67
|
-
<InventoryProvider connector={connector}>
|
|
70
|
+
<InventoryProvider connector={connector} noPlaceholders={noPlaceholders}>
|
|
68
71
|
<div
|
|
69
72
|
ref={containerRef}
|
|
70
73
|
className={className}
|
|
@@ -193,29 +193,40 @@ export const ItemCanvas = memo(function ItemCanvas({
|
|
|
193
193
|
/>
|
|
194
194
|
) : null /* still loading — render nothing (slot stays empty) */}
|
|
195
195
|
|
|
196
|
-
{/* Durability bar */}
|
|
197
|
-
{hasDurability && (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
196
|
+
{/* Durability bar — vanilla layout: x=2, y=13 in 16×16 item area */}
|
|
197
|
+
{hasDurability && (() => {
|
|
198
|
+
const mcPx = Math.max(1, Math.round(pixelSize))
|
|
199
|
+
const barLeft = 2 * mcPx
|
|
200
|
+
const bgBottom = mcPx
|
|
201
|
+
const bgWidth = 13 * mcPx
|
|
202
|
+
const bgHeight = 2 * mcPx
|
|
203
|
+
const ratio = item.durability! / item.maxDurability!
|
|
204
|
+
const fillWidth = Math.round(13 * ratio) * mcPx
|
|
205
|
+
const fillHeight = mcPx
|
|
206
|
+
const fillBottom = 2 * mcPx
|
|
207
|
+
return (
|
|
208
|
+
<>
|
|
209
|
+
<div className="mc-inv-item-durability-bg" style={{
|
|
210
|
+
position: 'absolute',
|
|
211
|
+
bottom: bgBottom,
|
|
212
|
+
left: barLeft,
|
|
213
|
+
width: bgWidth,
|
|
214
|
+
height: bgHeight,
|
|
215
|
+
background: '#000',
|
|
216
|
+
pointerEvents: 'none',
|
|
217
|
+
}} />
|
|
218
|
+
<div className="mc-inv-item-durability-bar" style={{
|
|
219
|
+
position: 'absolute',
|
|
220
|
+
bottom: fillBottom,
|
|
221
|
+
left: barLeft,
|
|
222
|
+
width: fillWidth,
|
|
223
|
+
height: fillHeight,
|
|
224
|
+
background: barColor,
|
|
225
|
+
pointerEvents: 'none',
|
|
226
|
+
}} />
|
|
227
|
+
</>
|
|
228
|
+
)
|
|
229
|
+
})()}
|
|
219
230
|
|
|
220
231
|
{/* Item count */}
|
|
221
232
|
{!noCount && item.count > 1 && (
|
|
@@ -55,6 +55,7 @@ export function Slot({
|
|
|
55
55
|
focusedSlot,
|
|
56
56
|
setFocusedSlot,
|
|
57
57
|
dragEndedRef,
|
|
58
|
+
noPlaceholders,
|
|
58
59
|
} = useInventoryContext()
|
|
59
60
|
|
|
60
61
|
const { contentSize } = useScale()
|
|
@@ -377,7 +378,7 @@ export function Slot({
|
|
|
377
378
|
/>
|
|
378
379
|
)}
|
|
379
380
|
|
|
380
|
-
{!item && label && (
|
|
381
|
+
{!item && label && !noPlaceholders && (
|
|
381
382
|
<div
|
|
382
383
|
ref={labelRef}
|
|
383
384
|
className={styles.emptyLabel}
|
|
@@ -45,6 +45,8 @@ export interface InventoryContextValue {
|
|
|
45
45
|
/** Ref set to true when a drag just ended; cleared on next mouseDown.
|
|
46
46
|
* Used by Slot to suppress spurious click events that fire after endDrag. */
|
|
47
47
|
dragEndedRef: React.MutableRefObject<boolean>
|
|
48
|
+
/** When true, empty slot labels (Head, Chest, Legs, etc.) are not rendered */
|
|
49
|
+
noPlaceholders: boolean
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
const InventoryContext = createContext<InventoryContextValue | null>(null)
|
|
@@ -59,9 +61,10 @@ interface InventoryProviderProps {
|
|
|
59
61
|
connector: InventoryConnector | null
|
|
60
62
|
children: React.ReactNode
|
|
61
63
|
noDragSpread?: boolean
|
|
64
|
+
noPlaceholders?: boolean
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
export function InventoryProvider({ connector, children, noDragSpread = false }: InventoryProviderProps) {
|
|
67
|
+
export function InventoryProvider({ connector, children, noDragSpread = false, noPlaceholders = false }: InventoryProviderProps) {
|
|
65
68
|
const [windowState, setWindowState] = useState<InventoryWindowState | null>(
|
|
66
69
|
() => connector?.getWindowState() ?? null,
|
|
67
70
|
)
|
|
@@ -304,6 +307,7 @@ export function InventoryProvider({ connector, children, noDragSpread = false }:
|
|
|
304
307
|
grabOffset,
|
|
305
308
|
setGrabOffset,
|
|
306
309
|
noDragSpread,
|
|
310
|
+
noPlaceholders,
|
|
307
311
|
pKeyActive,
|
|
308
312
|
setPKeyActive,
|
|
309
313
|
focusedSlot,
|