minecraft-inventory 0.1.0 → 0.1.1

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/src/types.ts CHANGED
@@ -43,6 +43,8 @@ export type InventoryAction =
43
43
  | { type: 'enchant'; enchantIndex: number }
44
44
  | { type: 'beacon'; primaryEffect: number; secondaryEffect: number }
45
45
  | { type: 'hotbar-swap'; slotIndex: number; hotbarSlot: number }
46
+ /** Emitted by the Hotbar "open inventory" button; integrations (e.g. mineflayer) handle this. */
47
+ | { type: 'open-inventory' }
46
48
 
47
49
  export interface InventoryWindowState {
48
50
  windowId: number
@@ -110,11 +112,11 @@ export interface InventoryTypeDefinition {
110
112
  backgroundTexture: string
111
113
  backgroundWidth: number
112
114
  backgroundHeight: number
113
- /** Minecraft version for GUI texture lookup, e.g. '1.16.4' or '1.21.4'. Defaults to base URL version. */
114
- guiTextureVersion?: string
115
115
  slots: SlotDefinition[]
116
116
  progressBars?: ProgressBar[]
117
117
  playerInventoryOffset?: { x: number; y: number }
118
+ /** Pixel offset applied to the title position relative to the default (6px top, 8px left). */
119
+ titleOffset?: { x: number; y: number }
118
120
  properties?: Record<string, { dataSlot: number; description: string }>
119
121
  windowType?: number | string
120
122
  hasTitle?: boolean
@@ -0,0 +1,14 @@
1
+ // Module-level singleton — always reflects latest cursor position.
2
+ // A single listener is registered once at module load time, shared across all consumers.
3
+ export const globalMouse = { x: -9999, y: -9999 }
4
+
5
+ if (typeof window !== 'undefined') {
6
+ window.addEventListener(
7
+ 'mousemove',
8
+ (e) => {
9
+ globalMouse.x = e.clientX
10
+ globalMouse.y = e.clientY
11
+ },
12
+ { passive: true, capture: true },
13
+ )
14
+ }
@@ -1,180 +0,0 @@
1
- import React from 'react'
2
- import { useInventoryContext } from '../../context/InventoryContext'
3
- import { useScale } from '../../context/ScaleContext'
4
- import { useTextures } from '../../context/TextureContext'
5
- import { Slot } from '../Slot'
6
- import { ItemCanvas } from '../ItemCanvas'
7
- import type { SlotState } from '../../types'
8
-
9
- interface HotbarProps {
10
- slots?: SlotState[]
11
- activeSlot?: number
12
- showOffhand?: boolean
13
- offhandSlot?: SlotState
14
- className?: string
15
- style?: React.CSSProperties
16
- }
17
-
18
- export function Hotbar({
19
- slots: slotsProp,
20
- activeSlot: activeSlotProp,
21
- showOffhand = true,
22
- offhandSlot: offhandProp,
23
- className,
24
- style,
25
- }: HotbarProps) {
26
- const { playerState, windowState, sendAction } = useInventoryContext()
27
- const { scale } = useScale()
28
- const textures = useTextures()
29
-
30
- const hotbarSlots = slotsProp ?? (
31
- playerState?.inventory
32
- .filter((s) => s.index >= 36 && s.index <= 44)
33
- .sort((a, b) => a.index - b.index) ?? []
34
- )
35
-
36
- const activeSlot = activeSlotProp ?? playerState?.activeHotbarSlot ?? 0
37
- const offhandItem = offhandProp ?? playerState?.inventory.find((s) => s.index === 45) ?? null
38
-
39
- const SLOT_SIZE = 20 * scale
40
- const HOTBAR_H = 22 * scale
41
- const OFFHAND_W = 24 * scale
42
-
43
- const hotbarUrl = textures.getGuiTextureUrl('gui/widgets')
44
-
45
- const totalWidth = (showOffhand ? OFFHAND_W + 4 * scale : 0) + 182 * scale
46
-
47
- return (
48
- <div
49
- className={['mc-inv-root', className].filter(Boolean).join(' ')}
50
- style={{
51
- position: 'relative',
52
- width: totalWidth,
53
- height: HOTBAR_H + 2 * scale,
54
- display: 'flex',
55
- alignItems: 'flex-end',
56
- ...style,
57
- }}
58
- >
59
- {/* Offhand slot */}
60
- {showOffhand && (
61
- <div
62
- className="mc-inv-hotbar-offhand"
63
- style={{
64
- position: 'relative',
65
- width: OFFHAND_W,
66
- height: HOTBAR_H,
67
- flexShrink: 0,
68
- marginRight: 4 * scale,
69
- }}
70
- >
71
- <img
72
- className="mc-inv-hotbar-offhand-bg"
73
- src={hotbarUrl}
74
- alt=""
75
- aria-hidden
76
- style={{
77
- position: 'absolute',
78
- top: 0,
79
- left: 0,
80
- width: OFFHAND_W,
81
- height: HOTBAR_H,
82
- objectFit: 'none',
83
- objectPosition: `-${24 * scale}px -${22 * scale}px`,
84
- imageRendering: 'pixelated',
85
- display: 'block',
86
- }}
87
- draggable={false}
88
- />
89
- {offhandItem?.item && (
90
- <div
91
- className="mc-inv-hotbar-offhand-item"
92
- style={{
93
- position: 'absolute',
94
- top: 3 * scale,
95
- left: 3 * scale,
96
- }}
97
- >
98
- <ItemCanvas item={offhandItem.item} size={16 * scale} />
99
- </div>
100
- )}
101
- </div>
102
- )}
103
-
104
- {/* Main hotbar */}
105
- <div
106
- className="mc-inv-hotbar-main"
107
- style={{
108
- position: 'relative',
109
- width: 182 * scale,
110
- height: HOTBAR_H + 2 * scale,
111
- flexShrink: 0,
112
- }}
113
- >
114
- {/* Hotbar background */}
115
- <img
116
- className="mc-inv-hotbar-bg"
117
- src={hotbarUrl}
118
- alt=""
119
- aria-hidden
120
- style={{
121
- position: 'absolute',
122
- top: scale,
123
- left: 0,
124
- width: 182 * scale,
125
- height: HOTBAR_H,
126
- objectFit: 'none',
127
- objectPosition: `0 0`,
128
- imageRendering: 'pixelated',
129
- display: 'block',
130
- }}
131
- draggable={false}
132
- />
133
-
134
- {/* Active slot indicator */}
135
- <img
136
- className="mc-inv-hotbar-indicator"
137
- src={hotbarUrl}
138
- alt=""
139
- aria-hidden
140
- style={{
141
- position: 'absolute',
142
- top: 0,
143
- left: (activeSlot * 20 - 1) * scale,
144
- width: 24 * scale,
145
- height: 24 * scale,
146
- objectFit: 'none',
147
- objectPosition: `0 -${22 * scale}px`,
148
- imageRendering: 'pixelated',
149
- display: 'block',
150
- }}
151
- draggable={false}
152
- />
153
-
154
- {/* Items */}
155
- {hotbarSlots.map((slot, i) => (
156
- <div
157
- key={slot.index}
158
- className="mc-inv-hotbar-slot"
159
- style={{
160
- position: 'absolute',
161
- top: 4 * scale,
162
- left: (3 + i * 20) * scale,
163
- cursor: 'pointer',
164
- }}
165
- onClick={() => {
166
- sendAction({
167
- type: 'click',
168
- slotIndex: slot.index,
169
- button: 'left',
170
- mode: 'normal',
171
- })
172
- }}
173
- >
174
- {slot.item && <ItemCanvas item={slot.item} size={16 * scale} />}
175
- </div>
176
- ))}
177
- </div>
178
- </div>
179
- )
180
- }
@@ -1 +0,0 @@
1
- export { Hotbar } from './Hotbar'