diff --git a/src/js/net/minecraft/client/render/WorldRenderer.js b/src/js/net/minecraft/client/render/WorldRenderer.js index 8a040e6..a8e1544 100644 --- a/src/js/net/minecraft/client/render/WorldRenderer.js +++ b/src/js/net/minecraft/client/render/WorldRenderer.js @@ -103,13 +103,20 @@ window.WorldRenderer = class { renderChunks(cameraChunkX, cameraChunkZ) { let world = this.minecraft.world; - for (let [index, chunk] of world.chunks) { + let renderDistance = WorldRenderer.RENDER_DISTANCE; + for (let x = -renderDistance; x <= renderDistance; x++) { + for (let z = -renderDistance; z <= renderDistance; z++) { + world.getChunkAt(cameraChunkX + x, cameraChunkZ + z); + } + } + + for (let [index, chunk] of world.chunks) { let distanceX = Math.abs(cameraChunkX - chunk.x); let distanceZ = Math.abs(cameraChunkZ - chunk.z); // Is in render distance check - if (distanceX < WorldRenderer.RENDER_DISTANCE && distanceZ < WorldRenderer.RENDER_DISTANCE) { + if (distanceX < renderDistance && distanceZ < renderDistance) { // Make chunk visible chunk.group.visible = true; @@ -152,20 +159,6 @@ window.WorldRenderer = class { if (this.chunkSectionUpdateQueue.length !== 0) { let chunkSection = this.chunkSectionUpdateQueue.shift(); if (chunkSection != null) { - // Load chunk - let chunk = chunkSection.chunk; - if (!chunk.isLoaded()) { - world.loadChunk(chunk); - - // Rebuild neighbor chunks to update transparent blocks - for (let relX = -1; relX <= 1; relX++) { - for (let relZ = -1; relZ <= 1; relZ++) { - let neighborChunk = world.getChunkAt(chunk.x + relX, chunk.z + relZ); - neighborChunk.queueForRebuild(); - } - } - } - // Rebuild chunk chunkSection.rebuild(this); } diff --git a/src/js/net/minecraft/client/world/Chunk.js b/src/js/net/minecraft/client/world/Chunk.js index 4d4787e..b5b1558 100644 --- a/src/js/net/minecraft/client/world/Chunk.js +++ b/src/js/net/minecraft/client/world/Chunk.js @@ -21,10 +21,9 @@ window.Chunk = class { // Create height map this.heightMap = []; - this.initHeightMapAndLight(); } - initHeightMapAndLight() { + generateSkylightMap() { let highest = World.TOTAL_HEIGHT; for (let x = 0; x < 16; x++) { for (let z = 0; z < 16; z++) { @@ -160,6 +159,10 @@ window.Chunk = class { this.getSection(y >> 4).setBlockAt(x, y & 15, z, byte0); + if (!this.loaded) { + return; + } + //if (k1 !== 0 && !this.worldObj.multiplayerWorld) { //Block.blocksList[k1].onBlockRemoval(this.world, l1, j, i2); //} @@ -222,10 +225,6 @@ window.Chunk = class { } } - load() { - this.loaded = true; - } - isLoaded() { return this.loaded; } diff --git a/src/js/net/minecraft/client/world/World.js b/src/js/net/minecraft/client/world/World.js index dc85ced..4f0a126 100644 --- a/src/js/net/minecraft/client/world/World.js +++ b/src/js/net/minecraft/client/world/World.js @@ -20,20 +20,34 @@ window.World = class { } - loadChunk(chunk) { - // Load chunk - chunk.load(); + getChunkAt(x, z) { + let index = x + (z << 16); + let chunk = this.chunks.get(index); + if (typeof chunk === 'undefined') { + let chunk = new Chunk(this, x, z); - // Generate new chunk - this.generator.generateChunk(chunk); + // Generate new chunk + this.generator.generateChunk(chunk); - // Populate chunk - this.generator.populateChunk(chunk.x, chunk.z); + // Init + chunk.generateSkylightMap(); + + // Register + chunk.loaded = true; + this.chunks.set(index, chunk); + this.group.add(chunk.group); + + // Populate chunk + this.generator.populateChunk(chunk.x, chunk.z); + } + return chunk; } getChunkAtBlock(x, y, z) { - let chunk = this.getChunkAt(x >> 4, z >> 4); - return y < 0 || y > World.TOTAL_HEIGHT ? null : chunk.getSection(y >> 4); + if (!this.blockExists(x, y, z)) { + return null; + } + return this.getChunkAt(x >> 4, z >> 4).getSection(y >> 4); } getCollisionBoxes(region) { @@ -58,6 +72,21 @@ window.World = class { return boundingBoxList; } + updateLights() { + // Update lights in queue + let i = 5000; + while (this.lightUpdateQueue.length > 0) { + if (i <= 0) { + return true; + } + this.lightUpdateQueue.shift().updateBlockLightning(this); + i--; + } + return false; + } + + static prev = 0; + updateLight(sourceType, x1, y1, z1, x2, y2, z2, notifyNeighbor = true) { if (this.lightUpdates >= 50) { return; @@ -83,8 +112,13 @@ window.World = class { return; } } - } + + if (World.prev !== this.lightUpdateQueue.length && this.lightUpdateQueue.length % 100 === 0) { + World.prev = this.lightUpdateQueue.length; + console.log(this.lightUpdateQueue.length + " in queue"); + } + this.lightUpdateQueue.push(new MetadataChunkBlock(sourceType, x1, y1, z1, x2, y2, z2)); if (this.lightUpdateQueue.length > 0x186a0) { this.lightUpdateQueue = []; @@ -124,26 +158,6 @@ window.World = class { } } - updateLights() { - if (this.lightUpdateProcesses >= 50) { - return false; - } - this.lightUpdateProcesses++; - - // Update lights in queue - let i = 5000; - while (this.lightUpdateQueue.length > 0) { - if (i <= 0) { - return true; - } - this.lightUpdateQueue.shift().updateBlockLightning(this); - i--; - } - - this.lightUpdateProcesses--; - return false; - } - getHeightAt(x, z) { if (!this.chunkExists(x >> 4, z >> 4)) { return 0; @@ -167,7 +181,7 @@ window.World = class { } getSavedLightValue(sourceType, x, y, z) { - if (y < 0) { + if (!this.chunkExists(x >> 4, z >> 4)) { return 15; } @@ -176,7 +190,7 @@ window.World = class { } setLightAt(sourceType, x, y, z, lightLevel) { - if (y < 0) { + if (!this.chunkExists(x >> 4, z >> 4)) { return; } @@ -215,16 +229,6 @@ window.World = class { return this.getChunkAt(chunkX, chunkZ).getSection(layerY); } - getChunkAt(x, z) { - let index = x + (z << 16); - let chunk = this.chunks.get(index); - if (typeof chunk === 'undefined') { - this.chunks.set(index, chunk = new Chunk(this, x, z)); - this.group.add(chunk.group); - } - return chunk; - } - onBlockChanged(x, y, z) { this.queueForRebuildInRegion(x - 1, y - 1, z - 1, x + 1, y + 1, z + 1); } diff --git a/src/js/net/minecraft/client/world/block/Block.js b/src/js/net/minecraft/client/world/block/Block.js index 7667b2d..212a3a3 100644 --- a/src/js/net/minecraft/client/world/block/Block.js +++ b/src/js/net/minecraft/client/world/block/Block.js @@ -23,6 +23,8 @@ window.Block = class { // Register block Block.blocks.set(id, this); Block.lightOpacity[id] = this.isSolid() ? 255 : 0; + + Block.lightOpacity[0] = 0; } getId() {