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/examples/block_entity.js
Views: 789
1
/*
2
* This example demonstrates how easy it is to create a bot
3
* that fetches monster spawners mob type
4
*/
5
const mineflayer = require('mineflayer')
6
7
if (process.argv.length < 4 || process.argv.length > 6) {
8
console.log('Usage : node block_entity.js <host> <port> [<name>] [<password>]')
9
process.exit(1)
10
}
11
12
const bot = mineflayer.createBot({
13
host: process.argv[2],
14
port: parseInt(process.argv[3]),
15
username: process.argv[4] ? process.argv[4] : 'block_entity',
16
password: process.argv[5]
17
})
18
19
bot.on('message', (cm) => {
20
if (cm.toString().includes('spawner')) {
21
spawner()
22
}
23
})
24
25
function spawner () {
26
let blockName
27
if (bot.supportFeature('mobSpawner')) {
28
blockName = bot.registry.blocksByName.mob_spawner.id
29
} else if (bot.supportFeature('spawner')) {
30
blockName = bot.registry.blocksByName.spawner.id
31
}
32
const block = bot.findBlock({
33
matching: blockName,
34
point: bot.entity.position
35
})
36
37
if (!block) {
38
return bot.chat('Monster spawner not found')
39
}
40
41
bot.chat(`Entity type: ${block.blockEntity.SpawnData.id}`)
42
bot.chat(`Delay: ${block.blockEntity.Delay}`)
43
console.log(block.blockEntity)
44
}
45
46