minecraft-inventory 0.1.14 → 0.1.16
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
|
@@ -31,6 +31,8 @@ export interface InventoryOverlayProps {
|
|
|
31
31
|
jeiPosition?: 'left' | 'right'
|
|
32
32
|
jeiOnGetRecipes?: (item: JEIItem) => RecipeGuide[]
|
|
33
33
|
jeiOnGetUsages?: (item: JEIItem) => RecipeGuide[]
|
|
34
|
+
jeiOnItemClick?: (item: JEIItem) => void
|
|
35
|
+
jeiOnItemRightClick?: (item: JEIItem) => void
|
|
34
36
|
/** Enable Notes sidebar (uses localStorage by default if callbacks not provided) */
|
|
35
37
|
enableNotes?: boolean
|
|
36
38
|
/** Callback to get notes. If not provided and enableNotes is true, uses localStorage. */
|
|
@@ -72,6 +74,8 @@ export function InventoryOverlay({
|
|
|
72
74
|
jeiPosition = 'right',
|
|
73
75
|
jeiOnGetRecipes,
|
|
74
76
|
jeiOnGetUsages,
|
|
77
|
+
jeiOnItemClick,
|
|
78
|
+
jeiOnItemRightClick,
|
|
75
79
|
enableNotes = false,
|
|
76
80
|
notesOnGet,
|
|
77
81
|
notesOnSave,
|
|
@@ -144,6 +148,8 @@ export function InventoryOverlay({
|
|
|
144
148
|
<JEI
|
|
145
149
|
items={jeiItems}
|
|
146
150
|
position={jeiPosition}
|
|
151
|
+
onItemClick={jeiOnItemClick}
|
|
152
|
+
onItemRightClick={jeiOnItemRightClick}
|
|
147
153
|
onGetRecipes={jeiOnGetRecipes}
|
|
148
154
|
onGetUsages={jeiOnGetUsages}
|
|
149
155
|
onPushRecipeFrame={pushRecipeFrame}
|
|
@@ -298,7 +304,7 @@ export function InventoryOverlay({
|
|
|
298
304
|
lineHeight: 1,
|
|
299
305
|
}}
|
|
300
306
|
>
|
|
301
|
-
INV 0.1.
|
|
307
|
+
INV 0.1.16
|
|
302
308
|
</a>
|
|
303
309
|
)}
|
|
304
310
|
|
|
@@ -26,6 +26,7 @@ interface JEIProps {
|
|
|
26
26
|
maxHeight?: number
|
|
27
27
|
onItemClick?: (item: JEIItem) => void
|
|
28
28
|
onItemMiddleClick?: (item: JEIItem) => void
|
|
29
|
+
onItemRightClick?: (item: JEIItem) => void
|
|
29
30
|
/** Called when R is pressed while hovering an item — return list of recipes to display */
|
|
30
31
|
onGetRecipes?: (item: JEIItem) => RecipeGuide[]
|
|
31
32
|
/** Called when U is pressed while hovering an item — return list of usages to display */
|
|
@@ -67,6 +68,7 @@ export function JEI({
|
|
|
67
68
|
maxHeight,
|
|
68
69
|
onItemClick,
|
|
69
70
|
onItemMiddleClick,
|
|
71
|
+
onItemRightClick,
|
|
70
72
|
onGetRecipes,
|
|
71
73
|
onGetUsages,
|
|
72
74
|
onPushRecipeFrame,
|
|
@@ -353,6 +355,12 @@ export function JEI({
|
|
|
353
355
|
} else {
|
|
354
356
|
pushRecipeFrame(jeiItem, 'recipes')
|
|
355
357
|
}
|
|
358
|
+
} else if (button === 'right' && mode === 'normal') {
|
|
359
|
+
if (onItemRightClick) {
|
|
360
|
+
onItemRightClick(jeiItem)
|
|
361
|
+
} else {
|
|
362
|
+
pushRecipeFrame(jeiItem, 'usages')
|
|
363
|
+
}
|
|
356
364
|
} else if (button === 'middle' && onItemMiddleClick) {
|
|
357
365
|
onItemMiddleClick(jeiItem)
|
|
358
366
|
}
|
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
|