CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/test/externalTests/exampleInventory.js
Views: 789
1
const assert = require('assert')
2
3
const tests = [
4
{
5
command: 'list',
6
wantedMessage: 'dirt x 64, stick x 7, iron_ore x 64, diamond_boots x 1'
7
},
8
{
9
command: 'equip off-hand dirt',
10
wantedMessage: 'equipped dirt'
11
},
12
{
13
command: 'list',
14
wantedMessage: 'stick x 7, iron_ore x 64, diamond_boots x 1, dirt x 64'
15
},
16
{
17
command: 'equip hand dirt',
18
wantedMessage: 'equipped dirt'
19
},
20
{
21
command: 'toss 64 dirt',
22
wantedMessage: 'tossed 64 x dirt'
23
},
24
{
25
command: 'craft 1 ladder',
26
wantedMessage: 'I can make ladder'
27
},
28
{
29
command: '',
30
wantedMessage: 'did the recipe for ladder 1 times'
31
},
32
{
33
command: 'equip feet diamond_boots',
34
wantedMessage: 'equipped diamond_boots'
35
},
36
{
37
command: 'toss iron_ore',
38
wantedMessage: 'tossed iron_ore'
39
},
40
{
41
command: 'unequip feet',
42
wantedMessage: 'unequipped'
43
},
44
{ // after tests layout
45
command: 'list',
46
wantedMessage: 'ladder x 3, diamond_boots x 1'
47
}
48
]
49
module.exports = () => async (bot) => {
50
await bot.test.runExample('examples/inventory.js', async (name) => {
51
assert.strictEqual(name, 'inventory')
52
bot.chat('/op inventory') // to counteract spawn protection
53
bot.chat('/clear inventory')
54
bot.chat(`/setblock 52 ${bot.test.groundY} 0 crafting_table`) // to make stone bricks stairs
55
bot.chat('/give inventory dirt 64')
56
bot.chat('/give inventory stick 7')
57
bot.chat('/give inventory iron_ore 64')
58
bot.chat('/give inventory diamond_boots 1')
59
await bot.test.wait(2000)
60
if (bot.registry.isOlderThan('1.9')) {
61
tests.splice(tests.indexOf(tests.find(t => t.command.includes('off-hand'))), 2) // Delete off-hand command and the command after it as they don't work in 1.9
62
}
63
const testFuncs = tests.map(test => makeTest(test.command, test.wantedMessage))
64
for (const test of testFuncs) {
65
await test()
66
await bot.test.wait(100)
67
}
68
// cleanup
69
bot.chat(`/setblock 52 ${bot.test.groundY} 0 air`)
70
71
function makeTest (inStr, outStr) {
72
return () => bot.test.tellAndListen(name, inStr, makeListener(outStr))
73
}
74
})
75
}
76
77
function makeListener (wantedMessage) {
78
return (message) => {
79
if (!message.startsWith(wantedMessage)) {
80
assert.fail(`Unexpected message: ${message}, wanted ${wantedMessage}`) // error
81
}
82
return true // stop listening
83
}
84
}
85
86