minecraft-inventory 0.1.9 → 0.1.10

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "minecraft-inventory",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "release": {
@@ -298,7 +298,7 @@ export function InventoryOverlay({
298
298
  lineHeight: 1,
299
299
  }}
300
300
  >
301
- INV 0.1.9
301
+ INV 0.1.10
302
302
  </a>
303
303
  )}
304
304
 
@@ -17,62 +17,76 @@ export function ProgressBar({ definition, properties, backgroundTexture }: Progr
17
17
  const max = definition.getMax(properties)
18
18
  const ratio = max > 0 ? Math.min(1, Math.max(0, value / max)) : 0
19
19
 
20
- const bgUrl = textures.getGuiTextureUrl(backgroundTexture)
21
- const x = definition.x * scale
22
- const y = definition.y * scale
23
- const w = definition.width * scale
24
- const h = definition.height * scale
25
- const srcX = definition.textureX
26
- const srcY = definition.textureY
20
+ if (ratio <= 0) return null
21
+
22
+ // Use standalone sprite image when available (mc-assets 1.20+ format),
23
+ // otherwise fall back to clipping from the background GUI texture.
24
+ const imgUrl = definition.spriteTexture
25
+ ? textures.getGuiTextureUrl(definition.spriteTexture)
26
+ : textures.getGuiTextureUrl(backgroundTexture)
27
+
28
+ const { x, y, width: w, height: h, textureX: srcX, textureY: srcY, direction } = definition
27
29
 
28
- let clipPath: string
29
- let clipWidth = w
30
- let clipHeight = h
30
+ // Compute the visible sub-rectangle of the sprite (unscaled pixels).
31
+ // 'up' fills from bottom, 'left' fills from right — offset into the sprite accordingly.
32
+ let visibleX = 0
33
+ let visibleY = 0
34
+ let visibleW = w
35
+ let visibleH = h
31
36
 
32
- switch (definition.direction) {
37
+ // Round to whole pixels to avoid sub-pixel jitter (vanilla MC uses integer steps).
38
+ switch (direction) {
33
39
  case 'right':
34
- clipWidth = w * ratio
40
+ visibleW = Math.floor(w * ratio)
35
41
  break
36
42
  case 'left':
37
- clipWidth = w * ratio
38
- break
39
- case 'up':
40
- clipHeight = h * ratio
43
+ visibleW = Math.floor(w * ratio)
44
+ visibleX = w - visibleW
41
45
  break
42
46
  case 'down':
43
- clipHeight = h * ratio
47
+ visibleH = Math.floor(h * ratio)
48
+ break
49
+ case 'up':
50
+ visibleH = Math.floor(h * ratio)
51
+ visibleY = h - visibleH
44
52
  break
45
53
  }
46
54
 
47
- if (ratio <= 0) return null
48
-
49
55
  return (
50
56
  <div
51
57
  style={{
52
58
  position: 'absolute',
53
- left: x,
54
- top: y,
55
- width: clipWidth,
56
- height: clipHeight,
59
+ left: (x + visibleX) * scale,
60
+ top: (y + visibleY) * scale,
61
+ width: visibleW * scale,
62
+ height: visibleH * scale,
57
63
  overflow: 'hidden',
58
- imageRendering: 'pixelated',
59
64
  pointerEvents: 'none',
60
65
  }}
61
66
  >
62
- <img
63
- src={bgUrl}
64
- alt=""
65
- aria-hidden
66
- style={{
67
- position: 'absolute',
68
- left: -srcX * scale,
69
- top: -srcY * scale,
70
- imageRendering: 'pixelated',
71
- display: 'block',
72
- maxWidth: 'none',
73
- }}
74
- draggable={false}
75
- />
67
+ {/* Render at 1× then scale via CSS transform, matching InventoryBackground */}
68
+ <div style={{
69
+ width: visibleW,
70
+ height: visibleH,
71
+ overflow: 'hidden',
72
+ transform: `scale(${scale})`,
73
+ transformOrigin: 'top left',
74
+ }}>
75
+ <img
76
+ src={imgUrl}
77
+ alt=""
78
+ aria-hidden
79
+ style={{
80
+ position: 'absolute',
81
+ left: -(srcX + visibleX),
82
+ top: -(srcY + visibleY),
83
+ imageRendering: 'pixelated',
84
+ display: 'block',
85
+ maxWidth: 'none',
86
+ }}
87
+ draggable={false}
88
+ />
89
+ </div>
76
90
  </div>
77
91
  )
78
- }
92
+ }
@@ -395,6 +395,16 @@ export function createMineflayerConnector(bot: MineflayerBot, options?: Mineflay
395
395
  ext._client.on?.('craft_progress_bar' as any, onCraftProgressBar as any)
396
396
  }
397
397
 
398
+ // If a window is already open when the connector is created (common case:
399
+ // windowOpen event fires → client shows modal → React mounts → connector created),
400
+ // perform the same setup that onWindowOpenInternal would have done so that
401
+ // dynamic slot listeners and currentWindowType are initialised properly.
402
+ // Note: any craft_progress_bar packets received before this point are lost,
403
+ // but the server resends them continuously so the gap is imperceptible.
404
+ if (!hotbarOnly && bot.currentWindow) {
405
+ onWindowOpenInternal()
406
+ }
407
+
398
408
  async function openPlayerInventory() {
399
409
  const vehicle = bot.vehicle
400
410
  let inventoryType = 'player'
@@ -618,4 +628,4 @@ export function createMineflayerConnector(bot: MineflayerBot, options?: Mineflay
618
628
  }
619
629
  },
620
630
  }
621
- }
631
+ }
@@ -27,6 +27,14 @@ import _gui_container_creative_inventory_tab_items from 'mc-assets/dist/other-te
27
27
  import _gui_widgets from 'mc-assets/dist/other-textures/1.15/gui/widgets.png'
28
28
  import _gui_sprites_container_anvil_text_field from 'mc-assets/dist/other-textures/latest/gui/sprites/container/anvil/text_field.png'
29
29
  import _gui_sprites_container_anvil_text_field_disabled from 'mc-assets/dist/other-textures/latest/gui/sprites/container/anvil/text_field_disabled.png'
30
+ import _gui_sprites_container_furnace_lit_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/furnace/lit_progress.png'
31
+ import _gui_sprites_container_furnace_burn_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/furnace/burn_progress.png'
32
+ import _gui_sprites_container_blast_furnace_lit_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/blast_furnace/lit_progress.png'
33
+ import _gui_sprites_container_blast_furnace_burn_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/blast_furnace/burn_progress.png'
34
+ import _gui_sprites_container_smoker_lit_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/smoker/lit_progress.png'
35
+ import _gui_sprites_container_smoker_burn_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/smoker/burn_progress.png'
36
+ import _gui_sprites_container_brewing_stand_brew_progress from 'mc-assets/dist/other-textures/latest/gui/sprites/container/brewing_stand/brew_progress.png'
37
+ import _gui_sprites_container_brewing_stand_fuel_length from 'mc-assets/dist/other-textures/latest/gui/sprites/container/brewing_stand/fuel_length.png'
30
38
 
31
39
  /**
32
40
  * Versioned texture path → bundled asset URL (or undefined for remote fallback).
@@ -59,6 +67,14 @@ export const bundledTextureMap: Record<string, string | undefined> = {
59
67
  '1.15/textures/gui/widgets.png': _gui_widgets,
60
68
  '1.21.11/textures/gui/sprites/container/anvil/text_field.png': _gui_sprites_container_anvil_text_field,
61
69
  '1.21.11/textures/gui/sprites/container/anvil/text_field_disabled.png': _gui_sprites_container_anvil_text_field_disabled,
70
+ '1.21.11/textures/gui/sprites/container/furnace/lit_progress.png': _gui_sprites_container_furnace_lit_progress,
71
+ '1.21.11/textures/gui/sprites/container/furnace/burn_progress.png': _gui_sprites_container_furnace_burn_progress,
72
+ '1.21.11/textures/gui/sprites/container/blast_furnace/lit_progress.png': _gui_sprites_container_blast_furnace_lit_progress,
73
+ '1.21.11/textures/gui/sprites/container/blast_furnace/burn_progress.png': _gui_sprites_container_blast_furnace_burn_progress,
74
+ '1.21.11/textures/gui/sprites/container/smoker/lit_progress.png': _gui_sprites_container_smoker_lit_progress,
75
+ '1.21.11/textures/gui/sprites/container/smoker/burn_progress.png': _gui_sprites_container_smoker_burn_progress,
76
+ '1.21.11/textures/gui/sprites/container/brewing_stand/brew_progress.png': _gui_sprites_container_brewing_stand_brew_progress,
77
+ '1.21.11/textures/gui/sprites/container/brewing_stand/fuel_length.png': _gui_sprites_container_brewing_stand_fuel_length,
62
78
  }
63
79
 
64
80
 
@@ -92,6 +108,14 @@ export const allTexturePaths: readonly string[] = [
92
108
  'gui/widgets.png',
93
109
  'gui/sprites/container/anvil/text_field.png',
94
110
  'gui/sprites/container/anvil/text_field_disabled.png',
111
+ 'gui/sprites/container/furnace/lit_progress.png',
112
+ 'gui/sprites/container/furnace/burn_progress.png',
113
+ 'gui/sprites/container/blast_furnace/lit_progress.png',
114
+ 'gui/sprites/container/blast_furnace/burn_progress.png',
115
+ 'gui/sprites/container/smoker/lit_progress.png',
116
+ 'gui/sprites/container/smoker/burn_progress.png',
117
+ 'gui/sprites/container/brewing_stand/brew_progress.png',
118
+ 'gui/sprites/container/brewing_stand/fuel_length.png',
95
119
  ]
96
120
 
97
121
  /**
@@ -256,8 +256,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
256
256
  id: 'fire',
257
257
  x: 56, y: 36, width: 14, height: 14,
258
258
  direction: 'up',
259
- textureX: 176, textureY: 0,
260
- emptyTextureX: 176, emptyTextureY: 12,
259
+ textureX: 0, textureY: 0,
260
+ spriteTexture: '1.21.11/textures/gui/sprites/container/furnace/lit_progress.png',
261
261
  getValue: (p) => p.litTime ?? 0,
262
262
  getMax: (p) => p.litDuration || 200,
263
263
  },
@@ -265,7 +265,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
265
265
  id: 'arrow',
266
266
  x: 79, y: 34, width: 24, height: 16,
267
267
  direction: 'right',
268
- textureX: 176, textureY: 14,
268
+ textureX: 0, textureY: 0,
269
+ spriteTexture: '1.21.11/textures/gui/sprites/container/furnace/burn_progress.png',
269
270
  getValue: (p) => p.cookingProgress ?? 0,
270
271
  getMax: (p) => p.totalCookTime || 200,
271
272
  },
@@ -295,7 +296,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
295
296
  id: 'fire',
296
297
  x: 56, y: 36, width: 14, height: 14,
297
298
  direction: 'up',
298
- textureX: 176, textureY: 0,
299
+ textureX: 0, textureY: 0,
300
+ spriteTexture: '1.21.11/textures/gui/sprites/container/blast_furnace/lit_progress.png',
299
301
  getValue: (p) => p.litTime ?? 0,
300
302
  getMax: (p) => p.litDuration || 200,
301
303
  },
@@ -303,7 +305,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
303
305
  id: 'arrow',
304
306
  x: 79, y: 34, width: 24, height: 16,
305
307
  direction: 'right',
306
- textureX: 176, textureY: 14,
308
+ textureX: 0, textureY: 0,
309
+ spriteTexture: '1.21.11/textures/gui/sprites/container/blast_furnace/burn_progress.png',
307
310
  getValue: (p) => p.cookingProgress ?? 0,
308
311
  getMax: (p) => p.totalCookTime || 200,
309
312
  },
@@ -333,7 +336,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
333
336
  id: 'fire',
334
337
  x: 56, y: 36, width: 14, height: 14,
335
338
  direction: 'up',
336
- textureX: 176, textureY: 0,
339
+ textureX: 0, textureY: 0,
340
+ spriteTexture: '1.21.11/textures/gui/sprites/container/smoker/lit_progress.png',
337
341
  getValue: (p) => p.litTime ?? 0,
338
342
  getMax: (p) => p.litDuration || 200,
339
343
  },
@@ -341,7 +345,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
341
345
  id: 'arrow',
342
346
  x: 79, y: 34, width: 24, height: 16,
343
347
  direction: 'right',
344
- textureX: 176, textureY: 14,
348
+ textureX: 0, textureY: 0,
349
+ spriteTexture: '1.21.11/textures/gui/sprites/container/smoker/burn_progress.png',
345
350
  getValue: (p) => p.cookingProgress ?? 0,
346
351
  getMax: (p) => p.totalCookTime || 200,
347
352
  },
@@ -369,7 +374,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
369
374
  id: 'brew_arrow',
370
375
  x: 97, y: 16, width: 9, height: 28,
371
376
  direction: 'down',
372
- textureX: 176, textureY: 0,
377
+ textureX: 0, textureY: 0,
378
+ spriteTexture: '1.21.11/textures/gui/sprites/container/brewing_stand/brew_progress.png',
373
379
  getValue: (p) => 400 - (p.brewTime ?? 400),
374
380
  getMax: () => 400,
375
381
  },
@@ -377,7 +383,8 @@ export const inventoryDefinitions = makeInventoryDefinitions({
377
383
  id: 'fuel',
378
384
  x: 18, y: 44, width: 18, height: 4,
379
385
  direction: 'right',
380
- textureX: 176, textureY: 29,
386
+ textureX: 0, textureY: 0,
387
+ spriteTexture: '1.21.11/textures/gui/sprites/container/brewing_stand/fuel_length.png',
381
388
  getValue: (p) => p.fuelLevel ?? 0,
382
389
  getMax: () => 20,
383
390
  },
@@ -715,4 +722,14 @@ export const registryExtraTextures: string[] = [
715
722
  // Anvil rename input field sprites (used by AnvilInput component)
716
723
  '1.21.11/textures/gui/sprites/container/anvil/text_field.png',
717
724
  '1.21.11/textures/gui/sprites/container/anvil/text_field_disabled.png',
725
+ // Furnace / blast furnace / smoker progress bar sprites
726
+ '1.21.11/textures/gui/sprites/container/furnace/lit_progress.png',
727
+ '1.21.11/textures/gui/sprites/container/furnace/burn_progress.png',
728
+ '1.21.11/textures/gui/sprites/container/blast_furnace/lit_progress.png',
729
+ '1.21.11/textures/gui/sprites/container/blast_furnace/burn_progress.png',
730
+ '1.21.11/textures/gui/sprites/container/smoker/lit_progress.png',
731
+ '1.21.11/textures/gui/sprites/container/smoker/burn_progress.png',
732
+ // Brewing stand progress bar sprites
733
+ '1.21.11/textures/gui/sprites/container/brewing_stand/brew_progress.png',
734
+ '1.21.11/textures/gui/sprites/container/brewing_stand/fuel_length.png',
718
735
  ]
package/src/types.ts CHANGED
@@ -149,6 +149,8 @@ export interface ProgressBar {
149
149
  textureY: number
150
150
  emptyTextureX?: number
151
151
  emptyTextureY?: number
152
+ /** Standalone sprite image path (mc-assets 1.20+ format). When set, used instead of clipping from the background texture. */
153
+ spriteTexture?: string
152
154
  getValue: (props: Record<string, number>) => number
153
155
  getMax: (props: Record<string, number>) => number
154
156
  }