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/anvil_saver/saver.js
Views: 789
1
/*
2
* This example demonstrates how to save a world with mineflayer and
3
* https://github.com/PrismarineJS/prismarine-provider-anvil
4
*/
5
6
const mineflayer = require('mineflayer')
7
const fs = require('fs')
8
9
if (process.argv.length < 4 || process.argv.length > 6) {
10
console.log('Usage : node saver.js <host> <port> [<name>] [<password>]')
11
process.exit(1)
12
}
13
14
const bot = mineflayer.createBot({
15
host: process.argv[2],
16
port: parseInt(process.argv[3]),
17
username: process.argv[4] ? process.argv[4] : 'saver',
18
password: process.argv[5],
19
storageBuilder: ({ version, worldName }) => {
20
const Anvil = require('prismarine-provider-anvil').Anvil(version)
21
worldName = worldName.replace(/:/g, '_')
22
fs.mkdirSync(worldName)
23
return new Anvil(worldName)
24
}
25
})
26
27
bot.on('spawn', () => {
28
bot.waitForChunksToLoad(() => {
29
console.log('World saved!')
30
})
31
})
32
33