Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports.server = async function (serv, { version, worldFolder, generation = { 'name': 'diamond_square', 'options': { 'worldHeight': 80 } } } = {}) {
const World = require('prismarine-world')(version)
const newSeed = generation.options.seed || Math.floor(Math.random() * Math.pow(2, 31))
let seed
let regionFolder
if (worldFolder) {
regionFolder = worldFolder + '/region'
try {
await fsStat(regionFolder)
} catch (err) {
await fsMkdir(regionFolder)
}
try {
const levelData = await level.readLevel(worldFolder + '/level.dat')
seed = levelData['RandomSeed'][0]
} catch (err) {
seed = newSeed
await level.writeLevel(worldFolder + '/level.dat', { 'RandomSeed': [seed, 0] })
}
} else { seed = newSeed }
generation.options.seed = seed
generation.options.version = version
serv.emit('seed', generation.options.seed)
const generationModule = generations[generation.name] ? generations[generation.name] : require(generation.name)
serv.overworld = new World(generationModule(generation.options), regionFolder)
serv.netherworld = new World(generations['nether'](generation.options))
// serv.endworld = new World(generations["end"]({}));
// WILL BE REMOVED WHEN ACTUALLY IMPLEMENTED
serv.overworld.blockEntityData = {}
let seed
let regionFolder
if (worldFolder) {
regionFolder = worldFolder + '/region'
try {
await fsStat(regionFolder)
} catch (err) {
await fsMkdir(regionFolder)
}
try {
const levelData = await level.readLevel(worldFolder + '/level.dat')
seed = levelData['RandomSeed'][0]
} catch (err) {
seed = newSeed
await level.writeLevel(worldFolder + '/level.dat', { 'RandomSeed': [seed, 0] })
}
} else { seed = newSeed }
generation.options.seed = seed
generation.options.version = version
serv.emit('seed', generation.options.seed)
const generationModule = generations[generation.name] ? generations[generation.name] : require(generation.name)
serv.overworld = new World(generationModule(generation.options), regionFolder)
serv.netherworld = new World(generations['nether'](generation.options))
// serv.endworld = new World(generations["end"]({}));
// WILL BE REMOVED WHEN ACTUALLY IMPLEMENTED
serv.overworld.blockEntityData = {}
serv.netherworld.blockEntityData = {}
serv.overworld.portals = []
serv.netherworld.portals = []
/// ///////////