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