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/digAndBuild.js
Views: 789
1
const { Vec3 } = require('vec3')
2
const assert = require('assert')
3
4
module.exports = () => async (bot) => {
5
const Item = require('prismarine-item')(bot.registry)
6
7
await bot.test.setInventorySlot(36, new Item(bot.registry.itemsByName.dirt.id, 1, 0))
8
await bot.test.fly(new Vec3(0, 2, 0))
9
await bot.test.placeBlock(36, bot.entity.position.plus(new Vec3(0, -2, 0)))
10
await bot.test.clearInventory()
11
await bot.creative.stopFlying()
12
await waitForFall()
13
await bot.test.becomeSurvival()
14
// we are bare handed
15
await bot.dig(bot.blockAt(bot.entity.position.plus(new Vec3(0, -1, 0))))
16
// make sure we collected das dirt
17
await bot.test.wait(1000)
18
assert(Item.equal(bot.inventory.slots[36], new Item(bot.registry.itemsByName.dirt.id, 1, 0)))
19
bot.test.sayEverywhere('dirt collect test: pass')
20
21
async function waitForFall () {
22
return new Promise((resolve, reject) => {
23
assert(!bot.entity.onGround, 'waitForFall called when we were already on the ground')
24
const startingPosition = bot.entity.position.clone()
25
bot.on('move', function onMove () {
26
if (bot.entity.onGround) {
27
const distance = startingPosition.distanceTo(bot.entity.position)
28
assert(distance > 0.2, `waitForFall didn't fall very far: ${distance}`)
29
bot.removeListener('move', onMove)
30
resolve()
31
}
32
})
33
})
34
}
35
}
36
37