Skip to content

Commit

Permalink
fix posInChunk thing
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1504 committed Jan 2, 2021
1 parent 52cba3d commit 145f712
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 40 deletions.
47 changes: 27 additions & 20 deletions src/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,9 @@ class World extends EventEmitter {

async setBlock (pos, block) {
const chunk = (await this.getColumnAt(pos))
const oldBlock = chunk.getBlock(pos)
chunk.setBlock(posInChunk(pos), block)
const pInChunk = posInChunk(pos)
const oldBlock = chunk.getBlock(pInChunk)
chunk.setBlock(pInChunk, block)
this.saveAt(pos)
this._emitBlockUpdate(oldBlock, block, pos)
}
Expand Down Expand Up @@ -209,50 +210,56 @@ class World extends EventEmitter {

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

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

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

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

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

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

Expand Down
47 changes: 27 additions & 20 deletions src/worldsync.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,64 +112,71 @@ class WorldSync extends EventEmitter {
setBlock (pos, block) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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)
}

setBlockStateId (pos, stateId) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

setBlockType (pos, blockType) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

setBlockData (pos, data) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

setBlockLight (pos, light) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

setSkyLight (pos, light) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}

setBiome (pos, biome) {
const chunk = this.getColumnAt(pos)
if (!chunk) return
const oldBlock = chunk.getBlock(pos)
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(pos), pos)
this._emitBlockUpdate(oldBlock, chunk.getBlock(pInChunk), pos)
}
}

Expand Down

0 comments on commit 145f712

Please sign in to comment.