prismarine-world
Advanced tools
Comparing version
module.exports = require('./src/world.js') | ||
module.exports.iterators = require('./src/iterators') |
{ | ||
"name": "prismarine-world", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "The core implementation of the world for prismarine", | ||
@@ -36,11 +36,11 @@ "main": "index.js", | ||
"flatmap": "0.0.3", | ||
"jest": "^26.0.1", | ||
"minecraft-data": "^2.47.0", | ||
"mkdirp": "^0.5.1", | ||
"jest": "^26.0.1", | ||
"prismarine-chunk": "^1.14.0", | ||
"prismarine-provider-anvil": "^2.0.0", | ||
"prismarine-provider-raw": "^1.0.1", | ||
"range": "0.0.3", | ||
"rimraf": "^3.0.2", | ||
"standard": "^14.0.1", | ||
"prismarine-provider-anvil": "^2.0.0", | ||
"prismarine-chunk": "^1.14.0", | ||
"prismarine-provider-raw": "^1.0.1" | ||
"standard": "^16.0.1" | ||
}, | ||
@@ -47,0 +47,0 @@ "dependencies": { |
301
README.md
@@ -11,2 +11,4 @@ # prismarine-world | ||
Provides a minecraft world: an infinite collection of 16x256x26 chunks. | ||
## Usage | ||
@@ -30,301 +32,6 @@ | ||
The API is split in 2 : | ||
* the World which is async | ||
* the World.sync which is sync | ||
Read [API.md](docs/API.md) | ||
The characteristics of the async world is that it will always return something when getting a block, but as a promise. To achieve this it | ||
may load columns from anvil files or other storage. On the other hand the sync world will not always return blocks and may return null, | ||
but it will return the block directly with no promise. | ||
The set operations have similar characteristics : the async world will always set the blocks and return a promise, whereas the sync world will | ||
not always set the blocks, but do the action now and not return a promise. | ||
The 2 world are linked and stay in sync together. | ||
The async world may be more natural for servers (although the sync world can also be used there) | ||
The sync world makes more sense for clients as there is not necessarily somewhere to load more data from (but in some cases this may be incorrect too, think | ||
multi player clients) | ||
### World | ||
#### World([generateChunk,[storageProvider]],[savingInterval]) | ||
Create a world instance, takes an optional `generateChunk(chunkX, chunkZ)` function that will get called when a chunk at | ||
`chunkX` and `chunkZ` need to be generated. Takes a second optional arguments : `storageProvider` containing the regions. | ||
If provided, prismarine-world will first try to load the map from these regions, and then try to generate the world if | ||
the chunk isn't saved. `savingInterval` default to 50ms. | ||
#### World.initialize(iniFunc,length,width,height=256,iniPos=new Vec3(0,0,0)) | ||
Initialize the world with a given blocks cube. Useful to load quickly a schematic. | ||
* `iniFunc` is a function(x,y,z) that returns a prismarine-block | ||
* `length`, `width` and `height` are the size to iterate on | ||
* `iniPos` is the position where to start the iteration | ||
Returns a promise containing an array of `{chunkX,chunkZ}` | ||
#### World.getColumns() | ||
Return all loaded columns | ||
#### World.unloadColumn(chunkX,chunkZ) | ||
Unload column from memory | ||
All the following methods are async and return a promise. | ||
#### World.setColumn(chunkX,chunkZ,chunk) | ||
Set `chunk` at `chunkX` and `chunkZ` | ||
#### World.getColumn(chunkX,chunkZ) | ||
Return the column at `chunkX` and `chunkZ` | ||
#### World.getBlock(pos) | ||
Get the [Block](https://github.com/PrismarineJS/prismarine-block) at [pos](https://github.com/andrewrk/node-vec3) | ||
#### World.setBlock(pos,block) | ||
Set the [Block](https://github.com/PrismarineJS/prismarine-block) at [pos](https://github.com/andrewrk/node-vec3) | ||
#### World.getBlockStateId(pos) | ||
Get the block state at `pos` | ||
#### World.getBlockType(pos) | ||
Get the block type at `pos` | ||
#### World.getBlockData(pos) | ||
Get the block data (metadata) at `pos` | ||
#### World.getBlockLight(pos) | ||
Get the block light at `pos` | ||
#### World.getSkyLight(pos) | ||
Get the block sky light at `pos` | ||
#### World.getBiome(pos) | ||
Get the block biome id at `pos` | ||
#### World.setBlockStateId(pos, stateId) | ||
Set the block state `stateId` at `pos` | ||
#### World.setBlockType(pos, id) | ||
Set the block type `id` at `pos` | ||
#### World.setBlockData(pos, data) | ||
Set the block `data` (metadata) at `pos` | ||
#### World.setBlockLight(pos, light) | ||
Set the block `light` at `pos` | ||
#### World.setSkyLight(pos, light) | ||
Set the block sky `light` at `pos` | ||
#### World.setBiome(pos, biome) | ||
Set the block `biome` id at `pos` | ||
#### World.waitSaving() | ||
Returns a promise that is resolved when all saving is done. | ||
#### World.sync(asyncWorld) | ||
Build a sync world, will delegate all the saving work to the async one | ||
#### World.initialize(iniFunc,length,width,height=256,iniPos=new Vec3(0,0,0)) | ||
Initialize the world with a given blocks cube. Useful to load quickly a schematic. | ||
* `iniFunc` is a function(x,y,z) that returns a prismarine-block | ||
* `length`, `width` and `height` are the size to iterate on | ||
* `iniPos` is the position where to start the iteration | ||
Returns an array of `{chunkX,chunkZ}` | ||
This works only on loaded columns. | ||
#### World.sync.getColumns() | ||
Return all loaded columns | ||
All the following methods are sync. | ||
#### World.sync.unloadColumn(chunkX,chunkZ) | ||
Unload column from memory | ||
#### World.sync.setColumn(chunkX,chunkZ,chunk) | ||
Set `chunk` at `chunkX` and `chunkZ` | ||
#### World.sync.getColumn(chunkX,chunkZ) | ||
Return the column at `chunkX` and `chunkZ` | ||
#### World.sync.getBlock(pos) | ||
Get the [Block](https://github.com/PrismarineJS/prismarine-block) at [pos](https://github.com/andrewrk/node-vec3) | ||
#### World.sync.setBlock(pos,block) | ||
Set the [Block](https://github.com/PrismarineJS/prismarine-block) at [pos](https://github.com/andrewrk/node-vec3) | ||
#### World.sync.getBlockStateId(pos) | ||
Get the block state at `pos` | ||
#### World.sync.getBlockType(pos) | ||
Get the block type at `pos` | ||
#### World.sync.getBlockData(pos) | ||
Get the block data (metadata) at `pos` | ||
#### World.sync.getBlockLight(pos) | ||
Get the block light at `pos` | ||
#### World.sync.getSkyLight(pos) | ||
Get the block sky light at `pos` | ||
#### World.sync.getBiome(pos) | ||
Get the block biome id at `pos` | ||
#### World.sync.setBlockStateId(pos, stateId) | ||
Set the block state `stateId` at `pos` | ||
#### World.sync.setBlockType(pos, id) | ||
Set the block type `id` at `pos` | ||
#### World.sync.setBlockData(pos, data) | ||
Set the block `data` (metadata) at `pos` | ||
#### World.sync.setBlockLight(pos, light) | ||
Set the block `light` at `pos` | ||
#### World.sync.setSkyLight(pos, light) | ||
Set the block sky `light` at `pos` | ||
#### World.sync.setBiome(pos, biome) | ||
Set the block `biome` id at `pos` | ||
## History | ||
### 3.1.1 | ||
* fix world.sync.getChunks() | ||
### 3.1.0 | ||
* implement unload column | ||
### 3.0.0 | ||
* BREAKING: regionFolder is now a provider (for example an Anvil instance) | ||
### 2.3.0 | ||
* add .sync | ||
### 2.2.0 | ||
* add get/set block state id | ||
* perf improvement of saving (thanks @Karang) | ||
### 2.1.0 | ||
* disable saving if savingInterval is 0 | ||
* standardjs | ||
* no gulp | ||
### 2.0.0 | ||
* cross version support | ||
### 1.0.2 | ||
* update dependencies, fix issue with provider anvil | ||
### 1.0.1 | ||
* update to babel6 | ||
### 1.0.0 | ||
* bump dependencies | ||
### 0.5.5 | ||
* bump prismarine-provider-anvil | ||
### 0.5.4 | ||
* fix negative iniPos in initialize | ||
### 0.5.3 | ||
* fix initialize | ||
### 0.5.2 | ||
* bump prismarine-chunk | ||
### 0.5.1 | ||
* fix initialize for iniPos%16 !=0 | ||
### 0.5.0 | ||
* add World.initialize | ||
### 0.4.0 | ||
* use prismarine-provide-anvil 0.1.0 to implement anvil loading and saving | ||
### 0.3.3 | ||
* fix minecraft-chunk bug | ||
### 0.3.2 | ||
* fix getBlockData | ||
### 0.3.1 | ||
* check if the region is available in the anvil files | ||
### 0.3.0 | ||
* Add anvil loading | ||
### 0.2.0 | ||
* Add chunk generation to the API | ||
### 0.1.0 | ||
* First version, basic functionality | ||
Read [HISTORY.md](docs/HISTORY.md) |
@@ -136,4 +136,4 @@ const Vec3 = require('vec3').Vec3 | ||
saveAt (pos) { | ||
var chunkX = Math.floor(pos.x / 16) | ||
var chunkZ = Math.floor(pos.z / 16) | ||
const chunkX = Math.floor(pos.x / 16) | ||
const chunkZ = Math.floor(pos.z / 16) | ||
if (this.storageProvider) { this.queueSaving(chunkX, chunkZ) } | ||
@@ -160,4 +160,4 @@ } | ||
async getColumnAt (pos) { | ||
var chunkX = Math.floor(pos.x / 16) | ||
var chunkZ = Math.floor(pos.z / 16) | ||
const chunkX = Math.floor(pos.x / 16) | ||
const chunkZ = Math.floor(pos.z / 16) | ||
return this.getColumn(chunkX, chunkZ) | ||
@@ -164,0 +164,0 @@ } |
@@ -18,6 +18,6 @@ /* eslint-env jest */ | ||
for (var x = 0; x < 16; x++) { | ||
for (var z = 0; z < 16; z++) { | ||
for (let x = 0; x < 16; x++) { | ||
for (let z = 0; z < 16; z++) { | ||
chunk.setBlockType(new Vec3(x, 50, z), Math.floor(Math.random() * 50)) | ||
for (var y = 0; y < 256; y++) { | ||
for (let y = 0; y < 256; y++) { | ||
chunk.setSkyLight(new Vec3(x, y, z), 15) | ||
@@ -78,6 +78,6 @@ } | ||
for (var x = 0; x < 16; x++) { | ||
for (var z = 0; z < 16; z++) { | ||
for (let x = 0; x < 16; x++) { | ||
for (let z = 0; z < 16; z++) { | ||
chunk.setBlockType(new Vec3(x, 50, z), Math.floor(Math.random() * 50)) | ||
for (var y = 0; y < 256; y++) { | ||
for (let y = 0; y < 256; y++) { | ||
chunk.setSkyLight(new Vec3(x, y, z), 15) | ||
@@ -84,0 +84,0 @@ } |
34433
20.06%17
54.55%675
31.07%36
-89.06%