diff --git a/prismarine-viewer/viewer/lib/viewer.ts b/prismarine-viewer/viewer/lib/viewer.ts index 1b11ac63d..9cb7eb3db 100644 --- a/prismarine-viewer/viewer/lib/viewer.ts +++ b/prismarine-viewer/viewer/lib/viewer.ts @@ -77,8 +77,8 @@ export class Viewer { // this.primitives.clear() } - addColumn (x, z, chunk) { - this.world.addColumn(x, z, chunk) + addColumn (x, z, chunk, isLightUpdate = false) { + this.world.addColumn(x, z, chunk, isLightUpdate) } removeColumn (x: string, z: string) { @@ -148,9 +148,9 @@ export class Viewer { // this.updatePrimitive(p) }) - emitter.on('loadChunk', ({ x, z, chunk, worldConfig }) => { + emitter.on('loadChunk', ({ x, z, chunk, worldConfig, isLightUpdate }) => { this.world.worldConfig = worldConfig - this.addColumn(x, z, chunk) + this.addColumn(x, z, chunk, isLightUpdate) }) // todo remove and use other architecture instead so data flow is clear emitter.on('blockEntities', (blockEntities) => { diff --git a/prismarine-viewer/viewer/lib/worldDataEmitter.ts b/prismarine-viewer/viewer/lib/worldDataEmitter.ts index fa916c514..6743e3372 100644 --- a/prismarine-viewer/viewer/lib/worldDataEmitter.ts +++ b/prismarine-viewer/viewer/lib/worldDataEmitter.ts @@ -75,7 +75,7 @@ export class WorldDataEmitter extends EventEmitter { bot._client.on('update_light', ({ chunkX, chunkZ }) => { const chunkPos = new Vec3(chunkX * 16, 0, chunkZ * 16) - this.loadChunk(chunkPos) + this.loadChunk(chunkPos, true) }) this.emitter.on('listening', () => { @@ -128,7 +128,7 @@ export class WorldDataEmitter extends EventEmitter { } } - async loadChunk (pos: ChunkPos) { + async loadChunk (pos: ChunkPos, isLightUpdate = false) { const [botX, botZ] = chunkPos(this.lastPos) const dx = Math.abs(botX - Math.floor(pos.x / 16)) const dz = Math.abs(botZ - Math.floor(pos.z / 16)) @@ -143,7 +143,7 @@ export class WorldDataEmitter extends EventEmitter { worldHeight: column['worldHeight'] ?? 256, } //@ts-ignore - this.emitter.emit('loadChunk', { x: pos.x, z: pos.z, chunk, blockEntities: column.blockEntities, worldConfig }) + this.emitter.emit('loadChunk', { x: pos.x, z: pos.z, chunk, blockEntities: column.blockEntities, worldConfig, isLightUpdate }) this.loadedChunks[`${pos.x},${pos.z}`] = true } } else { diff --git a/prismarine-viewer/viewer/lib/worldrendererCommon.ts b/prismarine-viewer/viewer/lib/worldrendererCommon.ts index ae2a91d3b..439839773 100644 --- a/prismarine-viewer/viewer/lib/worldrendererCommon.ts +++ b/prismarine-viewer/viewer/lib/worldrendererCommon.ts @@ -211,7 +211,7 @@ export abstract class WorldRendererCommon } - addColumn (x, z, chunk) { + addColumn (x: number, z: number, chunk: any, isLightUpdate: boolean) { if (this.workers.length === 0) throw new Error('workers not initialized yet') this.initialChunksLoad = false this.loadedChunks[`${x},${z}`] = true @@ -222,10 +222,12 @@ export abstract class WorldRendererCommon for (let y = this.worldConfig.minY; y < this.worldConfig.worldHeight; y += 16) { const loc = new Vec3(x, y, z) this.setSectionDirty(loc) - this.setSectionDirty(loc.offset(-16, 0, 0)) - this.setSectionDirty(loc.offset(16, 0, 0)) - this.setSectionDirty(loc.offset(0, 0, -16)) - this.setSectionDirty(loc.offset(0, 0, 16)) + if (!isLightUpdate || this.mesherConfig.smoothLighting) { + this.setSectionDirty(loc.offset(-16, 0, 0)) + this.setSectionDirty(loc.offset(16, 0, 0)) + this.setSectionDirty(loc.offset(0, 0, -16)) + this.setSectionDirty(loc.offset(0, 0, 16)) + } } } diff --git a/src/watchOptions.ts b/src/watchOptions.ts index 1493e7d18..009463be2 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -44,7 +44,8 @@ export const watchOptionsAfterViewerInit = () => { viewer.entities.setVisible(o.renderEntities) }) - viewer.world.mesherConfig.smoothLighting = options.smoothLighting + // viewer.world.mesherConfig.smoothLighting = options.smoothLighting + viewer.world.mesherConfig.smoothLighting = false // todo not supported for now subscribeKey(options, 'smoothLighting', () => { viewer.world.mesherConfig.smoothLighting = options.smoothLighting; (viewer.world as WorldRendererThree).rerenderAllChunks()