flying-squid/src/lib/worldGenerations/nether.js
2018-11-25 16:31:55 +01:00

34 lines
1.1 KiB
JavaScript

const Vec3 = require('vec3').Vec3
const rand = require('random-seed')
function generation ({ version, seed, level = 50 } = {}) {
const Chunk = require('prismarine-chunk')(version)
function generateChunk (chunkX, chunkZ) {
const seedRand = rand.create(seed + ':' + chunkX + ':' + chunkZ)
const chunk = new Chunk()
for (let x = 0; x < 16; x++) {
for (let z = 0; z < 16; z++) {
const bedrockheighttop = 1 + seedRand(4)
const bedrockheightbottom = 1 + seedRand(4)
for (let y = 0; y < 128; y++) { // Nether only goes up to 128
let block
let data
if (y < bedrockheightbottom) block = 7
else if (y < level) block = seedRand(50) === 0 ? 89 : 87
else if (y > 127 - bedrockheighttop) block = 7
const pos = new Vec3(x, y, z)
if (block) chunk.setBlockType(pos, block)
if (data) chunk.setBlockData(pos, data)
// Don't need to set light data in nether
}
}
}
return chunk
}
return generateChunk
}
module.exports = generation