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/auto_totem.js
Views: 788
1
/*
2
* This script will automatically set if a totem is in the inventory or the off-hand.
3
* It checks for a totem every tick.
4
*/
5
const mineflayer = require('mineflayer')
6
7
if (process.argv.length < 4 || process.argv.length > 6) {
8
console.log('Usage : node auto_totem.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] : 'totem',
16
password: process.argv[5]
17
})
18
19
bot.on('spawn', () => {
20
const totemId = bot.registry.itemsByName.totem_of_undying.id // Get the correct id
21
if (bot.registry.itemsByName.totem_of_undying) {
22
setInterval(() => {
23
const totem = bot.inventory.findInventoryItem(totemId, null)
24
if (totem) {
25
bot.equip(totem, 'off-hand')
26
}
27
}, 50)
28
}
29
})
30
31