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/commandBlock.js
Views: 789
1
const assert = require('assert')
2
const { Vec3 } = require('vec3')
3
const { once, onceWithCleanup } = require('../../lib/promise_utils')
4
5
module.exports = () => async (bot) => {
6
const command = `/say ${Math.floor(Math.random() * 1000)}`
7
const commandBlockPos = new Vec3(1, 5, 1)
8
const commandBlockPosText = commandBlockPos.toArray().join(' ')
9
10
// Put and activate the command block
11
const p = once(bot.world, `blockUpdate:(${commandBlockPos.x}, ${commandBlockPos.y}, ${commandBlockPos.z})`)
12
bot.test.sayEverywhere(`/setblock ${commandBlockPosText} minecraft:command_block`)
13
await p
14
bot.setCommandBlock(commandBlockPos, command, false)
15
16
const [message] = await onceWithCleanup(bot, 'message', {
17
timeout: 5000,
18
checkCondition: (message) => message.json.with[0] === command
19
})
20
assert(message.json.translate === 'advMode.setCommand.success')
21
}
22
23