prismarine-windows 2.7.0 → 2.9.0
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/HISTORY.md +8 -0
- package/index.js +3 -0
- package/lib/Window.js +32 -48
- package/package.json +1 -1
- package/test/test.js +16 -5
package/HISTORY.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
### 2.9.0
|
|
2
|
+
* [Add Crafter into windows list for 1.20.3+ (#105)](https://github.com/PrismarineJS/prismarine-windows/commit/e081bc34c8282ef2a380e3f09d5f57f19703fab7) (thanks @wgaylord)
|
|
3
|
+
|
|
4
|
+
### 2.8.0
|
|
5
|
+
* [Export changedSlots computation to mineflayer (#102)](https://github.com/PrismarineJS/prismarine-windows/commit/98c3d66ae6aca733bb234d487686e2e534d1924d) (thanks @kaduvert)
|
|
6
|
+
* [Ensure numberClick with same slots doesn't do anything (#103)](https://github.com/PrismarineJS/prismarine-windows/commit/50e6bfbdb9c3bc26f06ea45760527b2da53eb1f3) (thanks @kaduvert)
|
|
7
|
+
* [Fix broken behaviour with craftingResultSlots (#101)](https://github.com/PrismarineJS/prismarine-windows/commit/51cc06e0f7dd39ddbb617962dfc1bb659fc172ce) (thanks @kaduvert)
|
|
8
|
+
|
|
1
9
|
### 2.7.0
|
|
2
10
|
* [More click modes (with tests!) (#74)](https://github.com/PrismarineJS/prismarine-windows/commit/9f19fb357b2a96e09060fa5c2393b9041cc869fe) (thanks @kaduvert)
|
|
3
11
|
* [Add command gh workflow allowing to use release command in comments (#98)](https://github.com/PrismarineJS/prismarine-windows/commit/6ddc90092d63f3838136d83e583d7c1d7ace3ae2) (thanks @rom1504)
|
package/index.js
CHANGED
|
@@ -16,6 +16,9 @@ function loader (registryOrVersion) {
|
|
|
16
16
|
windows['minecraft:generic_9x5'] = { type: protocolId++, inventory: { start: 5 * 9, end: 5 * 9 + 35 }, slots: 5 * 9 + 36, craft: -1, requireConfirmation: true }
|
|
17
17
|
windows['minecraft:generic_9x6'] = { type: protocolId++, inventory: { start: 6 * 9, end: 6 * 9 + 35 }, slots: 6 * 9 + 36, craft: -1, requireConfirmation: true }
|
|
18
18
|
windows['minecraft:generic_3x3'] = { type: protocolId++, inventory: { start: 3 * 3, end: 3 * 3 + 35 }, slots: 3 * 3 + 36, craft: -1, requireConfirmation: true }
|
|
19
|
+
if (registry.version['>=']('1.20.3')) {
|
|
20
|
+
windows['minecraft:crafter_3x3'] = { type: protocolId++, inventory: { start: 10, end: 45 }, slots: 46, craft: -1, requireConfirmation: true }
|
|
21
|
+
}
|
|
19
22
|
windows['minecraft:anvil'] = { type: protocolId++, inventory: { start: 3, end: 38 }, slots: 39, craft: 2, requireConfirmation: true }
|
|
20
23
|
windows['minecraft:beacon'] = { type: protocolId++, inventory: { start: 1, end: 36 }, slots: 37, craft: -1, requireConfirmation: true }
|
|
21
24
|
windows['minecraft:blast_furnace'] = { type: protocolId++, inventory: { start: 3, end: 38 }, slots: 39, craft: 2, requireConfirmation: true }
|
package/lib/Window.js
CHANGED
|
@@ -31,49 +31,35 @@ module.exports = (Item, registry) => {
|
|
|
31
31
|
(this.type === 'minecraft:inventory' && slot === 45)),
|
|
32
32
|
'invalid operation')
|
|
33
33
|
|
|
34
|
-
// can not use structuredClone because of
|
|
35
|
-
// potentially incompatible node versions
|
|
36
|
-
const oldSlots = JSON.parse(JSON.stringify(this.slots))
|
|
37
|
-
|
|
38
34
|
switch (click.mode) {
|
|
39
35
|
case 0:
|
|
40
36
|
assert.ok(mouseButton <= 1, 'invalid operation')
|
|
41
|
-
this.mouseClick(click)
|
|
42
|
-
break
|
|
37
|
+
return this.mouseClick(click)
|
|
43
38
|
|
|
44
39
|
case 1:
|
|
45
40
|
assert.ok(mouseButton <= 1, 'invalid operation')
|
|
46
|
-
this.shiftClick(click)
|
|
47
|
-
break
|
|
41
|
+
return this.shiftClick(click)
|
|
48
42
|
|
|
49
43
|
case 2:
|
|
50
44
|
assert.ok(mouseButton <= 8, 'invalid operation')
|
|
51
|
-
this.numberClick(click)
|
|
52
|
-
break
|
|
45
|
+
return this.numberClick(click)
|
|
53
46
|
|
|
54
47
|
case 3:
|
|
55
48
|
assert.ok(mouseButton === 2, 'invalid operation')
|
|
56
|
-
this.middleClick(click, gamemode)
|
|
57
|
-
break
|
|
49
|
+
return this.middleClick(click, gamemode)
|
|
58
50
|
|
|
59
51
|
case 4:
|
|
60
52
|
assert.ok(mouseButton <= 1, 'invalid operation')
|
|
61
|
-
this.dropClick(click)
|
|
62
|
-
break
|
|
53
|
+
return this.dropClick(click)
|
|
63
54
|
|
|
64
55
|
case 5:
|
|
65
56
|
assert.ok([1, 5, 9, 2, 6, 10].includes(mouseButton), 'invalid operation')
|
|
66
|
-
this.dragClick(click, gamemode)
|
|
67
|
-
break
|
|
57
|
+
return this.dragClick(click, gamemode)
|
|
68
58
|
|
|
69
59
|
case 6:
|
|
70
60
|
assert.ok(mouseButton === 0, 'invalid operation')
|
|
71
|
-
this.doubleClick(click)
|
|
72
|
-
break
|
|
61
|
+
return this.doubleClick(click)
|
|
73
62
|
}
|
|
74
|
-
|
|
75
|
-
// this is required to satisfy mc versions >= 1.17
|
|
76
|
-
return this.getChangedSlotsAsNotch(oldSlots, this.slots)
|
|
77
63
|
}
|
|
78
64
|
|
|
79
65
|
mouseClick (click) {
|
|
@@ -85,7 +71,11 @@ module.exports = (Item, registry) => {
|
|
|
85
71
|
if (item && this.selectedItem) {
|
|
86
72
|
if (Item.equal(item, this.selectedItem, false)) {
|
|
87
73
|
if (click.slot === this.craftingResultSlot) {
|
|
88
|
-
|
|
74
|
+
const maxTransferrable = this.selectedItem.stackSize - this.selectedItem.count
|
|
75
|
+
if (item.count > maxTransferrable) {
|
|
76
|
+
this.selectedItem.count += maxTransferrable
|
|
77
|
+
item.count -= maxTransferrable
|
|
78
|
+
} else if (item.count <= maxTransferrable) {
|
|
89
79
|
this.selectedItem.count += item.count
|
|
90
80
|
this.updateSlot(item.slot, null)
|
|
91
81
|
}
|
|
@@ -95,8 +85,12 @@ module.exports = (Item, registry) => {
|
|
|
95
85
|
} else {
|
|
96
86
|
this.swapSelectedItem(click.slot, item)
|
|
97
87
|
}
|
|
88
|
+
|
|
89
|
+
return [click.slot]
|
|
98
90
|
} else if (this.selectedItem || item) {
|
|
99
91
|
this.swapSelectedItem(click.slot, item)
|
|
92
|
+
|
|
93
|
+
return [click.slot]
|
|
100
94
|
}
|
|
101
95
|
} else if (click.mouseButton === 1) { // right click
|
|
102
96
|
if (this.selectedItem) {
|
|
@@ -111,15 +105,17 @@ module.exports = (Item, registry) => {
|
|
|
111
105
|
this.updateSlot(click.slot, item)
|
|
112
106
|
this.fillSlotWithSelectedItem(item, false)
|
|
113
107
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
108
|
+
|
|
109
|
+
return [click.slot]
|
|
110
|
+
} else if (item && click.slot !== this.craftingResultSlot) {
|
|
111
|
+
this.splitSlot(item)
|
|
112
|
+
|
|
113
|
+
return [click.slot]
|
|
120
114
|
}
|
|
121
115
|
}
|
|
122
116
|
}
|
|
117
|
+
|
|
118
|
+
return []
|
|
123
119
|
}
|
|
124
120
|
|
|
125
121
|
shiftClick (click) {
|
|
@@ -149,9 +145,10 @@ module.exports = (Item, registry) => {
|
|
|
149
145
|
const { item } = click
|
|
150
146
|
const hotbarSlot = this.hotbarStart + click.mouseButton
|
|
151
147
|
const itemAtHotbarSlot = this.slots[hotbarSlot]
|
|
148
|
+
if (Item.equal(item, itemAtHotbarSlot) && item?.slot === hotbarSlot) return
|
|
152
149
|
if (item) {
|
|
153
150
|
if (itemAtHotbarSlot) {
|
|
154
|
-
if (this.type === 'minecraft:inventory' || registry.version['>=']('1.9')) {
|
|
151
|
+
if ((this.type === 'minecraft:inventory' || registry.version['>=']('1.9')) && click.slot !== this.craftingResultSlot) {
|
|
155
152
|
this.updateSlot(click.slot, itemAtHotbarSlot)
|
|
156
153
|
this.updateSlot(hotbarSlot, item)
|
|
157
154
|
} else {
|
|
@@ -179,19 +176,23 @@ module.exports = (Item, registry) => {
|
|
|
179
176
|
}
|
|
180
177
|
|
|
181
178
|
middleClick (click, gamemode) {
|
|
182
|
-
if (this.selectedItem) return
|
|
179
|
+
if (this.selectedItem) return []
|
|
183
180
|
const { item } = click
|
|
184
181
|
if (gamemode === 1 && item) {
|
|
185
182
|
this.selectedItem = new Item(item.type, item.stackSize, item.metadata, item.nbt)
|
|
186
183
|
}
|
|
184
|
+
return []
|
|
187
185
|
}
|
|
188
186
|
|
|
189
187
|
dropClick (click) {
|
|
190
|
-
|
|
188
|
+
const { item } = click
|
|
189
|
+
if (this.selectedItem || item === null) return []
|
|
191
190
|
if (click.mouseButton === 0) {
|
|
192
191
|
if (--click.item.count === 0) this.updateSlot(click.slot, null)
|
|
192
|
+
return [click.slot]
|
|
193
193
|
} else if (click.mouseButton === 1) {
|
|
194
194
|
this.updateSlot(click.slot, null)
|
|
195
|
+
return [click.slot]
|
|
195
196
|
}
|
|
196
197
|
}
|
|
197
198
|
|
|
@@ -435,23 +436,6 @@ module.exports = (Item, registry) => {
|
|
|
435
436
|
return this.requiresConfirmation
|
|
436
437
|
}
|
|
437
438
|
|
|
438
|
-
getChangedSlotsAsNotch (slots1, slots2) {
|
|
439
|
-
assert.equal(slots1.length, slots2.length)
|
|
440
|
-
|
|
441
|
-
const changedSlots = []
|
|
442
|
-
|
|
443
|
-
for (let i = 0; i < slots2.length; i++) {
|
|
444
|
-
if (!Item.equal(slots1[i], slots2[i])) {
|
|
445
|
-
changedSlots.push({
|
|
446
|
-
location: i,
|
|
447
|
-
item: Item.toNotch(slots2[i])
|
|
448
|
-
})
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
return changedSlots
|
|
453
|
-
}
|
|
454
|
-
|
|
455
439
|
clear (blockId, count) {
|
|
456
440
|
let clearedCount = 0
|
|
457
441
|
|
package/package.json
CHANGED
package/test/test.js
CHANGED
|
@@ -289,6 +289,19 @@ describe('mode 2 | number click', () => {
|
|
|
289
289
|
testWindow.assertSlot(-9).isNotEmpty().hasCount(64).hasType(secondItem)
|
|
290
290
|
}
|
|
291
291
|
})
|
|
292
|
+
|
|
293
|
+
it('same slot click does nothing', () => {
|
|
294
|
+
testWindow = createTestWindow('chest')
|
|
295
|
+
.prepareSlot(62, 64, firstItem)
|
|
296
|
+
|
|
297
|
+
// slot 62 = hotbarEnd
|
|
298
|
+
// mouseButton 8 = hotbarEnd
|
|
299
|
+
// slot 0 = windowStart
|
|
300
|
+
testWindow.executeClick(2, 8, 62)
|
|
301
|
+
|
|
302
|
+
// no asserts, test would fail regardless
|
|
303
|
+
// if something did change
|
|
304
|
+
})
|
|
292
305
|
})
|
|
293
306
|
})
|
|
294
307
|
|
|
@@ -348,9 +361,7 @@ it('returning changed slots works', () => {
|
|
|
348
361
|
testWindow.assertSlot(0).isEmpty()
|
|
349
362
|
testWindow.assertSelectedItem().isNotEmpty()
|
|
350
363
|
|
|
351
|
-
assert.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
// selectedItem isn't included in changedSlots
|
|
355
|
-
)
|
|
364
|
+
assert.equal(changedSlots.length, 1)
|
|
365
|
+
assert.equal(changedSlots[0], 0)
|
|
366
|
+
// selectedItem isn't included in changedSlots
|
|
356
367
|
})
|