Skip to content

Commit

Permalink
use new prismarine-provider-anvil to read/write the seed, use a world…
Browse files Browse the repository at this point in the history
…Folder option instead of regionFolder option, fix #178
  • Loading branch information
rom1504 committed Jan 14, 2016
1 parent 19b4c98 commit 40aab30
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion config/default-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"online-mode": true,
"logging": true,
"gameMode": 1,
"regionFolder":"world/region",
"worldFolder":"world",
"generation": {
"name": "diamond_square",
"options":{
Expand Down
2 changes: 1 addition & 1 deletion doc/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Options is an object containing the following properties:
}
```
* modpe: defaults to false, wether or not modpe should be enabled.
* regionFolder : the region folder of the saved world
* worldFolder : the world folder of the saved world (containing region, level.dat,...)
* plugins
* view-distance
* player-list-text : an object with keys header and footer, displayed on the player list
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@
"mkdirp": "0.5.1",
"moment": "^2.10.6",
"node-dir": "~0.1.9",
"node-promise-es6": "^0.3.0",
"node-uuid": "^1.4.3",
"prismarine-block": "0.1.0",
"prismarine-chunk": "0.2.1",
"prismarine-entity": "0.2.0",
"prismarine-item": "0.0.0",
"prismarine-provider-anvil": "^0.2.0",
"prismarine-windows": "0.0.0",
"prismarine-world": "0.4.0",
"prismarine-world-sync": "0.1.0",
Expand Down
23 changes: 21 additions & 2 deletions src/lib/plugins/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,28 @@ const World = require('prismarine-world');
const WorldSync = require("prismarine-world-sync");

const generations=require("flying-squid").generations;
import {fs} from 'node-promise-es6';
import {level} from 'prismarine-provider-anvil';

module.exports.server=function(serv,{regionFolder,generation={"name":"diamond_square","options":{"worldHeight":80}}}={}) {
generation.options.seed=generation.options.seed || Math.random()*Math.pow(2, 32);
module.exports.server=async function(serv,{worldFolder,generation={"name":"diamond_square","options":{"worldHeight":80}}}={}) {
const regionFolder=worldFolder+"/region";
try {
const stats = await fs.stat(regionFolder);
}
catch(err) {
await fs.mkdir(regionFolder);
}

let seed;
try {
const levelData=await level.readLevel(worldFolder+"/level.dat");
seed=levelData["RandomSeed"][0];
}
catch(err){
seed=generation.options.seed || Math.floor(Math.random()*Math.pow(2, 31));
await level.writeLevel(worldFolder+"/level.dat",{"RandomSeed":[seed,0]});
}
generation.options.seed=seed;
serv.emit("seed",generation.options.seed);
serv.overworld = new World(generations[generation.name](generation.options), regionFolder);
serv.netherworld = new World(generations["nether"]({}));
Expand Down
File renamed without changes.

0 comments on commit 40aab30

Please sign in to comment.