minecraft-inventory 0.1.9 → 0.1.11
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/cache/blockRenderer.ts +19 -18
- package/src/components/InventoryOverlay/InventoryOverlay.tsx +1 -1
- package/src/components/InventoryWindow/ProgressBar.tsx +53 -39
- package/src/connector/mineflayer.ts +11 -1
- package/src/generated/localTextures.ts +24 -0
- package/src/registry/inventories.ts +26 -9
- package/src/types.ts +2 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
const POOL_SIZE = 8
|
|
7
|
-
const OUTPUT_SIZE =
|
|
7
|
+
const OUTPUT_SIZE = 64
|
|
8
8
|
|
|
9
9
|
const pool: HTMLCanvasElement[] = []
|
|
10
10
|
const inUse = new Set<HTMLCanvasElement>()
|
|
@@ -59,42 +59,43 @@ export function renderBlockIcon(
|
|
|
59
59
|
ctx.imageSmoothingEnabled = false
|
|
60
60
|
ctx.clearRect(0, 0, OUTPUT_SIZE, OUTPUT_SIZE)
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
const
|
|
62
|
+
// Parameters from the original minecraft-inventory-gui renderer
|
|
63
|
+
const A = 0.9 // horizontal compression (makes blocks narrower/taller)
|
|
64
|
+
const K = 0.5 // skew factor
|
|
65
|
+
const s = OUTPUT_SIZE / 2 - 2
|
|
66
|
+
const cubeWidth = 2 * A * s
|
|
67
|
+
const cubeHeight = 2 * K * s + s
|
|
68
|
+
const ox = Math.round((OUTPUT_SIZE - cubeWidth) / 2)
|
|
69
|
+
const topY = Math.round((OUTPUT_SIZE - cubeHeight) / 2)
|
|
70
|
+
const ex = ox
|
|
71
|
+
const ey = topY + K * s
|
|
72
|
+
|
|
65
73
|
const [tx, ty, tw, th] = top
|
|
66
74
|
const [lx, ly, lw, lh] = left
|
|
67
75
|
const [rx, ry, rw, rh] = right
|
|
68
76
|
|
|
69
|
-
// Enable smoothing for isometric transforms (better diagonal edges)
|
|
70
77
|
ctx.imageSmoothingEnabled = true
|
|
71
78
|
ctx.imageSmoothingQuality = 'high'
|
|
72
79
|
|
|
73
|
-
// Isometric cube using affine transforms.
|
|
74
|
-
// Face vertices for a cube centered in OUTPUT_SIZE × OUTPUT_SIZE:
|
|
75
|
-
// Top: (s+ox, oy) → (2s+ox, s/2+oy) → (s+ox, s+oy) → (ox, s/2+oy)
|
|
76
|
-
// Left: (ox, s/2+oy) → (s+ox, s+oy) → (s+ox, 2s+oy) → (ox, 3s/2+oy)
|
|
77
|
-
// Right: (s+ox, s+oy) → (2s+ox, s/2+oy) → (2s+ox, 3s/2+oy) → (s+ox, 2s+oy)
|
|
78
|
-
|
|
79
80
|
// Top face
|
|
80
81
|
ctx.save()
|
|
81
|
-
ctx.setTransform(
|
|
82
|
+
ctx.setTransform(A, -K, A, K, ex, ey)
|
|
82
83
|
ctx.drawImage(image, tx, ty, tw, th, 0, 0, s, s)
|
|
83
84
|
ctx.restore()
|
|
84
85
|
|
|
85
|
-
// Left face (darkened)
|
|
86
|
+
// Left face (lightly darkened)
|
|
86
87
|
ctx.save()
|
|
87
|
-
ctx.setTransform(
|
|
88
|
+
ctx.setTransform(A, K, 0, 1, ex, ey)
|
|
88
89
|
ctx.drawImage(image, lx, ly, lw, lh, 0, 0, s, s)
|
|
89
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.
|
|
90
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.35)'
|
|
90
91
|
ctx.fillRect(0, 0, s, s)
|
|
91
92
|
ctx.restore()
|
|
92
93
|
|
|
93
|
-
// Right face (
|
|
94
|
+
// Right face (darkened — light comes from upper-left)
|
|
94
95
|
ctx.save()
|
|
95
|
-
ctx.setTransform(
|
|
96
|
+
ctx.setTransform(A, -K, 0, 1, A * s + ex, K * s + ey)
|
|
96
97
|
ctx.drawImage(image, rx, ry, rw, rh, 0, 0, s, s)
|
|
97
|
-
ctx.fillStyle = 'rgba(0, 0, 0, 0.
|
|
98
|
+
ctx.fillStyle = 'rgba(0, 0, 0, 0.5)'
|
|
98
99
|
ctx.fillRect(0, 0, s, s)
|
|
99
100
|
ctx.restore()
|
|
100
101
|
|
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
let
|
|
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
|
-
|
|
37
|
+
// Round to whole pixels to avoid sub-pixel jitter (vanilla MC uses integer steps).
|
|
38
|
+
switch (direction) {
|
|
33
39
|
case 'right':
|
|
34
|
-
|
|
40
|
+
visibleW = Math.floor(w * ratio)
|
|
35
41
|
break
|
|
36
42
|
case 'left':
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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:
|
|
56
|
-
height:
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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:
|
|
260
|
-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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
|
}
|