🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

prismarine-world

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prismarine-world - npm Package Compare versions

Comparing version

to
3.4.0

examples/simple.js

112

docs/API.md

@@ -29,2 +29,22 @@ # API

#### "blockUpdate" (oldBlock, newBlock)
Fires when a block updates. Both `oldBlock` and `newBlock` provided for
comparison.
Note that `oldBlock` may be `null`.
#### "blockUpdate:(x, y, z)" (oldBlock, newBlock)
Fires for a specific point. Both `oldBlock` and `newBlock` provided for
comparison.
Note that `oldBlock` may be `null`.
#### "chunkColumnLoad" (point)
#### "chunkColumnUnload" (point)
Fires when a chunk has updated. `point` is the coordinates to the corner
of the chunk with the smallest x, y, and z values.
### World.initialize(iniFunc,length,width,height=256,iniPos=new Vec3(0,0,0))

@@ -131,88 +151,4 @@

### World.initialize(iniFunc,length,width,height=256,iniPos=new Vec3(0,0,0))
It exposes the same methods as World but all methods are sync.
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`
## Iterators

@@ -222,5 +158,5 @@

### ManathanIterator (x, y, maxDistance)
### ManhattanIterator (x, y, maxDistance)
2D spiral iterator, useful to iterate on columns that are centered on bot position
2D rectangular spiral iterator, useful to iterate on columns that are centered on bot position

@@ -248,2 +184,2 @@ #### next()

return null or the next position (Vec3)
return null or the next position (Vec3)
## History
### 3.4.0
* add block update events
### 3.3.1

@@ -4,0 +8,0 @@

{
"name": "prismarine-world",
"version": "3.3.1",
"version": "3.4.0",
"description": "The core implementation of the world for prismarine",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,3 +5,4 @@ const { Vec3 } = require('vec3')

// columns that are centered on bot position
class ManathanIterator {
// https://en.wikipedia.org/wiki/Taxicab_geometry
class ManhattanIterator {
constructor (x, y, maxDistance) {

@@ -208,3 +209,4 @@ this.maxDistance = maxDistance

module.exports = {
ManathanIterator,
ManhattanIterator,
ManathanIterator: ManhattanIterator, // backward compatibility
OctahedronIterator,

@@ -211,0 +213,0 @@ RaycastIterator,

@@ -103,2 +103,7 @@ const { Vec3 } = require('vec3')

_emitBlockUpdate (oldBlock, newBlock, position) {
this.emit('blockUpdate', oldBlock, newBlock)
this.emit(`blockUpdate:${position}`, oldBlock, newBlock)
}
setLoadedColumn (chunkX, chunkZ, chunk, save = true) {

@@ -108,2 +113,5 @@ const key = columnKeyXZ(chunkX, chunkZ)

const columnCorner = new Vec3(chunkX * 16, 0, chunkZ * 16)
this.emit('chunkColumnLoad', columnCorner)
if (this.storageProvider && save) { this.queueSaving(chunkX, chunkZ) }

@@ -120,2 +128,4 @@ }

delete this.columns[key]
const columnCorner = new Vec3(chunkX * 16, 0, chunkZ * 16)
this.emit('chunkColumnUnload', columnCorner)
}

@@ -189,4 +199,8 @@

async setBlock (pos, block) {
(await this.getColumnAt(pos)).setBlock(posInChunk(pos), block)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlock(pInChunk, block)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, block, pos)
}

@@ -223,29 +237,53 @@

async setBlockStateId (pos, stateId) {
(await this.getColumnAt(pos)).setBlockStateId(posInChunk(pos), stateId)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockStateId(pInChunk, stateId)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
async setBlockType (pos, blockType) {
(await this.getColumnAt(pos)).setBlockType(posInChunk(pos), blockType)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockType(pInChunk, blockType)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
async setBlockData (pos, data) {
(await this.getColumnAt(pos)).setBlockData(posInChunk(pos), data)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockData(pInChunk, data)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
async setBlockLight (pos, light) {
(await this.getColumnAt(pos)).setBlockLight(posInChunk(pos), light)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockLight(pInChunk, light)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
async setSkyLight (pos, light) {
(await this.getColumnAt(pos)).setSkyLight(posInChunk(pos), light)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setSkyLight(pInChunk, light)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
async setBiome (pos, biome) {
(await this.getColumnAt(pos)).setBiome(posInChunk(pos), biome)
const chunk = (await this.getColumnAt(pos))
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBiome(pInChunk, biome)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -252,0 +290,0 @@ }

@@ -60,4 +60,11 @@ const { Vec3 } = require('vec3')

_emitBlockUpdate (oldBlock, newBlock, position) {
this.emit('blockUpdate', oldBlock, newBlock)
if (position) this.emit(`blockUpdate:${position}`, oldBlock, newBlock)
}
unloadColumn (chunkX, chunkZ) {
this.async.unloadColumn(chunkX, chunkZ)
const columnCorner = new Vec3(chunkX * 16, 0, chunkZ * 16)
this.emit('chunkColumnUnload', columnCorner)
}

@@ -78,3 +85,5 @@

setColumn (chunkX, chunkZ, chunk, save = true) {
return this.async.setLoadedColumn(chunkX, chunkZ, chunk, save)
this.async.setLoadedColumn(chunkX, chunkZ, chunk, save)
const columnCorner = new Vec3(chunkX * 16, 0, chunkZ * 16)
this.emit('chunkColumnLoad', columnCorner)
}

@@ -129,4 +138,7 @@

if (!chunk) return
chunk.setBlock(posInChunk(pos), block)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlock(pInChunk, block)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, block)
}

@@ -137,4 +149,7 @@

if (!chunk) return
chunk.setBlockStateId(posInChunk(pos), stateId)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockStateId(pInChunk, stateId)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -145,4 +160,7 @@

if (!chunk) return
chunk.setBlockType(posInChunk(pos), blockType)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockType(pInChunk, blockType)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -153,4 +171,7 @@

if (!chunk) return
chunk.setBlockData(posInChunk(pos), data)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockData(pInChunk, data)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -161,4 +182,7 @@

if (!chunk) return
chunk.setBlockLight(posInChunk(pos), light)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlockLight(pInChunk, light)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -169,4 +193,7 @@

if (!chunk) return
chunk.setSkyLight(posInChunk(pos), light)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setSkyLight(pInChunk, light)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -177,4 +204,7 @@

if (!chunk) return
chunk.setBiome(posInChunk(pos), biome)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBiome(pInChunk, biome)
this.async.saveAt(pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

@@ -181,0 +211,0 @@ }