minecraft-inventory 0.1.13 → 0.1.15
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 +1 -1
- package/src/InventoryGUI.tsx +4 -1
- package/src/components/InventoryOverlay/InventoryOverlay.tsx +1 -1
- package/src/components/Slot/Slot.tsx +2 -1
- package/src/context/InventoryContext.tsx +5 -1
- package/src/registry/index.ts +23 -17
- package/src/registry/inventories.ts +14 -0
- package/src/types.ts +5 -0
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}
|
|
@@ -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,
|
package/src/registry/index.ts
CHANGED
|
@@ -5,41 +5,47 @@ const registry = new Map<string, InventoryTypeDefinition>(
|
|
|
5
5
|
Object.entries(inventoryDefinitions),
|
|
6
6
|
)
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
8
|
+
/** Built from each definition’s `aliases` field in `inventories.ts`. */
|
|
9
|
+
function buildAliasToNameMap(
|
|
10
|
+
defs: Record<string, InventoryTypeDefinition>,
|
|
11
|
+
): Map<string, string> {
|
|
12
|
+
const m = new Map<string, string>()
|
|
13
|
+
for (const def of Object.values(defs)) {
|
|
14
|
+
if (def.aliases) {
|
|
15
|
+
for (const a of def.aliases) {
|
|
16
|
+
m.set(a, def.name)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return m
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
const aliasToName = buildAliasToNameMap(inventoryDefinitions)
|
|
24
|
+
|
|
25
|
+
/** Runtime aliases from {@link registerTypeAlias} / {@link registerInventoryType}. */
|
|
26
|
+
const dynamicAliasToName = new Map<string, string>()
|
|
27
|
+
|
|
22
28
|
export function registerInventoryType(def: InventoryTypeDefinition): void {
|
|
23
29
|
registry.set(def.name, def)
|
|
30
|
+
def.aliases?.forEach((a) => dynamicAliasToName.set(a, def.name))
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
/**
|
|
27
34
|
* Resolve an inventory type name or alias to its definition.
|
|
28
35
|
* Handles:
|
|
29
36
|
* - Exact matches (e.g. "crafting_table")
|
|
30
|
-
* -
|
|
37
|
+
* - `aliases` on each definition in `inventories.ts`
|
|
31
38
|
* - "minecraft:" namespace prefix (e.g. "minecraft:generic_9x3" → "generic_9x3")
|
|
32
39
|
*/
|
|
33
40
|
export function getInventoryType(name: string): InventoryTypeDefinition | undefined {
|
|
34
|
-
// Strip "minecraft:" namespace prefix if present
|
|
35
41
|
const stripped = name.startsWith('minecraft:') ? name.slice('minecraft:'.length) : name
|
|
36
|
-
|
|
37
|
-
|
|
42
|
+
const canonical =
|
|
43
|
+
dynamicAliasToName.get(stripped) ?? aliasToName.get(stripped) ?? stripped
|
|
38
44
|
return registry.get(canonical)
|
|
39
45
|
}
|
|
40
46
|
|
|
41
47
|
export function registerTypeAlias(alias: string, canonical: string): void {
|
|
42
|
-
|
|
48
|
+
dynamicAliasToName.set(alias, canonical)
|
|
43
49
|
}
|
|
44
50
|
|
|
45
51
|
export function getAllInventoryTypes(): InventoryTypeDefinition[] {
|
|
@@ -87,9 +87,14 @@ const makeInventoryDefinitions = <T extends string>(
|
|
|
87
87
|
]),
|
|
88
88
|
) as Record<T, InventoryTypeDefinition>
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Canonical inventory GUIs. Optional `aliases` lists protocol / prismarine-windows
|
|
92
|
+
* names that map to each `name` (see {@link getInventoryType} in `./index.ts`).
|
|
93
|
+
*/
|
|
90
94
|
export const inventoryDefinitions = makeInventoryDefinitions({
|
|
91
95
|
player: {
|
|
92
96
|
name: 'player',
|
|
97
|
+
aliases: ['inventory'],
|
|
93
98
|
title: 'Inventory',
|
|
94
99
|
backgroundTexture: '1.21.11/textures/gui/container/inventory.png',
|
|
95
100
|
backgroundWidth: 176,
|
|
@@ -228,6 +233,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
228
233
|
|
|
229
234
|
crafting_table: {
|
|
230
235
|
name: 'crafting_table',
|
|
236
|
+
aliases: ['crafting', 'crafting3x3'],
|
|
231
237
|
title: 'Crafting',
|
|
232
238
|
backgroundTexture: '1.21.11/textures/gui/container/crafting_table.png',
|
|
233
239
|
backgroundWidth: 176,
|
|
@@ -433,6 +439,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
433
439
|
|
|
434
440
|
enchanting_table: {
|
|
435
441
|
name: 'enchanting_table',
|
|
442
|
+
aliases: ['enchantment'],
|
|
436
443
|
title: 'Enchant',
|
|
437
444
|
backgroundTexture: '1.21.11/textures/gui/container/enchanting_table.png',
|
|
438
445
|
backgroundWidth: 176,
|
|
@@ -455,6 +462,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
455
462
|
|
|
456
463
|
smithing_table: {
|
|
457
464
|
name: 'smithing_table',
|
|
465
|
+
aliases: ['smithing'],
|
|
458
466
|
title: 'Upgrade Gear',
|
|
459
467
|
backgroundTexture: '1.21.11/textures/gui/container/smithing.png',
|
|
460
468
|
backgroundWidth: 176,
|
|
@@ -505,6 +513,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
505
513
|
|
|
506
514
|
dispenser: {
|
|
507
515
|
name: 'dispenser',
|
|
516
|
+
/** wiki `generic_3x3`; same 3×3 + player layout as dropper */
|
|
517
|
+
aliases: ['generic_3x3'],
|
|
508
518
|
title: 'Dispenser',
|
|
509
519
|
backgroundTexture: '1.21.11/textures/gui/container/dispenser.png',
|
|
510
520
|
backgroundWidth: 176,
|
|
@@ -541,6 +551,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
541
551
|
|
|
542
552
|
horse: {
|
|
543
553
|
name: 'horse',
|
|
554
|
+
aliases: ['EntityHorse'],
|
|
544
555
|
title: 'Horse',
|
|
545
556
|
backgroundTexture: '1.21.11/textures/gui/container/horse.png',
|
|
546
557
|
backgroundWidth: 176,
|
|
@@ -587,6 +598,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
587
598
|
|
|
588
599
|
villager: {
|
|
589
600
|
name: 'villager',
|
|
601
|
+
aliases: ['merchant'],
|
|
590
602
|
title: 'Villager',
|
|
591
603
|
backgroundTexture: '1.14/textures/gui/container/villager2.png',
|
|
592
604
|
backgroundWidth: 276,
|
|
@@ -626,6 +638,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
626
638
|
|
|
627
639
|
cartography_table: {
|
|
628
640
|
name: 'cartography_table',
|
|
641
|
+
aliases: ['cartography'],
|
|
629
642
|
title: 'Cartography Table',
|
|
630
643
|
backgroundTexture: '1.21.11/textures/gui/container/cartography_table.png',
|
|
631
644
|
backgroundWidth: 176,
|
|
@@ -668,6 +681,7 @@ export const inventoryDefinitions = makeInventoryDefinitions({
|
|
|
668
681
|
|
|
669
682
|
crafter: {
|
|
670
683
|
name: 'crafter',
|
|
684
|
+
aliases: ['crafter_3x3'],
|
|
671
685
|
title: 'Crafter',
|
|
672
686
|
backgroundTexture: '1.21.11/textures/gui/container/crafter.png',
|
|
673
687
|
backgroundWidth: 176,
|
package/src/types.ts
CHANGED
|
@@ -164,6 +164,11 @@ export interface EntityDisplayArea {
|
|
|
164
164
|
|
|
165
165
|
export interface InventoryTypeDefinition {
|
|
166
166
|
name: string
|
|
167
|
+
/**
|
|
168
|
+
* Alternate type strings that resolve to this definition (e.g. protocol names like `crafting` → crafting_table).
|
|
169
|
+
* Do not include `minecraft:` — that prefix is stripped before lookup.
|
|
170
|
+
*/
|
|
171
|
+
aliases?: string[]
|
|
167
172
|
title: string
|
|
168
173
|
backgroundTexture: string
|
|
169
174
|
backgroundWidth: number
|