add options to the generation files

This commit is contained in:
Romain Beaumont 2015-10-09 14:17:13 +02:00
parent caf0ece703
commit e5a5973575
5 changed files with 45 additions and 33 deletions

View file

@ -5,5 +5,10 @@
"onlineMode": true, "onlineMode": true,
"logging": true, "logging": true,
"gameMode": 1, "gameMode": 1,
"generation":"diamond_square" "generation": {
"name":"diamond_square",
"options":{
"worldHeight":80
}
}
} }

View file

@ -5,5 +5,5 @@ module.exports=inject;
function inject(serv,settings) function inject(serv,settings)
{ {
serv.gameMode=settings.gameMode; serv.gameMode=settings.gameMode;
serv.spawnPoints=[new vec3(6,138,6),new vec3(3,138,6),new vec3(8,138,6)]; serv.spawnPoints=[new vec3(6,81,6),new vec3(3,81,6),new vec3(8,81,6)];
} }

View file

@ -10,5 +10,5 @@ var generations={
module.exports = inject; module.exports = inject;
function inject(serv,options) { function inject(serv,options) {
serv.world = new World(generations[options["generation"]]); serv.world = new World(generations[options["generation"].name](options["generation"].options));
} }

View file

@ -93,35 +93,39 @@ function DiamondSquare(size, roughness, seed) {
} }
} }
function generation(options) {
var worldHeight=options.worldHeight || 80;
// Selected empirically // Selected empirically
var size = 10000000; var size = 10000000;
var space = new DiamondSquare(size, size/1000, Math.random() * 10000); var space = new DiamondSquare(size, size / 1000, Math.random() * 10000);
function generateSimpleChunk(chunkX, chunkZ) { function generateSimpleChunk(chunkX, chunkZ) {
var chunk = new Chunk(); var chunk = new Chunk();
var worldX = chunkX * 16 + size/2; var worldX = chunkX * 16 + size / 2;
var worldZ = chunkZ * 16 + size/2; var worldZ = chunkZ * 16 + size / 2;
for (var x = 0; x < 16;x++) { for (var x = 0; x < 16; x++) {
for (var z = 0; z < 16; z++) { for (var z = 0; z < 16; z++) {
var level = Math.floor(space.value(worldX + x, worldZ + z) * 138); var level = Math.floor(space.value(worldX + x, worldZ + z) * worldHeight);
for (var y = 0; y < 256; y++) { for (var y = 0; y < 256; y++) {
let block; let block;
if(y == 0) block = 7; if (y == 0) block = 7;
else if(y < level) block = 3; else if (y < level) block = 3;
else if (y == level) block = 2; else if (y == level) block = 2;
else if (y < 20) block = 9; else if (y < 20) block = 9;
if(block) chunk.setBlockType(new Vec3(x, y, z), block); if (block) chunk.setBlockType(new Vec3(x, y, z), block);
chunk.setSkyLight(new Vec3(x, y, z), 15); chunk.setSkyLight(new Vec3(x, y, z), 15);
}
} }
} }
}
return chunk; return chunk;
}
return generateSimpleChunk;
} }
module.exports=generateSimpleChunk; module.exports=generation;

View file

@ -1,19 +1,22 @@
var Chunk = require('prismarine-chunk')(require("../version")); var Chunk = require('prismarine-chunk')(require("../version"));
var Vec3 = require('vec3'); var Vec3 = require('vec3');
function generateSimpleChunk(chunkX, chunkZ) { function generation(options) {
var chunk=new Chunk(); function generateSimpleChunk(chunkX, chunkZ) {
var chunk = new Chunk();
for (var x = 0; x < 16;x++) { for (var x = 0; x < 16; x++) {
for (var z = 0; z < 16; z++) { for (var z = 0; z < 16; z++) {
chunk.setBlockType(new Vec3(x, 50, z), 2); chunk.setBlockType(new Vec3(x, 50, z), 2);
for (var y = 0; y < 256; y++) { for (var y = 0; y < 256; y++) {
chunk.setSkyLight(new Vec3(x, y, z), 15); chunk.setSkyLight(new Vec3(x, y, z), 15);
}
} }
} }
}
return chunk; return chunk;
}
return generateSimpleChunk;
} }
module.exports=generateSimpleChunk; module.exports=generation;