mirror of
https://github.com/danbulant/flying-squid
synced 2026-06-17 05:21:22 +00:00
34 lines
1.1 KiB
JavaScript
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
|