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/consume.js
Views: 789
1
const assert = require('assert')
2
3
module.exports = () => async (bot) => {
4
const Item = require('prismarine-item')(bot.registry)
5
6
await bot.test.setInventorySlot(36, new Item(bot.registry.itemsByName.bread.id, 5, 0))
7
await bot.test.becomeSurvival()
8
// Cannot consume if bot.food === 20
9
await assert.rejects(bot.consume, (err) => {
10
if (!err) {
11
// log the conditions that made this not throw
12
console.log({ a: bot.game.gameMode !== 'creative', b: !['potion', 'milk_bucket', 'enchanted_golden_apple', 'golden_apple'].includes(bot.heldItem.name), c: bot.food === 20 })
13
}
14
assert.notStrictEqual(err, undefined)
15
return true
16
})
17
18
await bot.test.becomeSurvival()
19
20
while (bot.food > 0) {
21
if (bot.supportFeature('effectAreNotPrefixed')) bot.test.sayEverywhere('/effect give @s hunger 1 255')
22
else if (bot.supportFeature('effectAreMinecraftPrefixed')) bot.test.sayEverywhere(`/effect ${bot.username} minecraft:hunger 1 255`)
23
await bot.test.wait(500)
24
}
25
26
assert.ok(!bot.usingHeldItem)
27
while (bot.food < 20) {
28
const consume = bot.consume()
29
assert.ok(bot.usingHeldItem)
30
await consume
31
assert.ok(!bot.usingHeldItem)
32
await bot.test.wait(100)
33
}
34
}
35
36