disable light updates on chunk load

This commit is contained in:
LabyStudio
2022-02-01 12:53:33 +01:00
parent a0e6d00bf5
commit b4b6f4a762
2 changed files with 16 additions and 16 deletions
+2
View File
@@ -99,6 +99,7 @@ window.Minecraft = class {
if (button === 0) { if (button === 0) {
if (hitResult != null) { if (hitResult != null) {
this.world.setBlockAt(hitResult.x, hitResult.y, hitResult.z, 0); this.world.setBlockAt(hitResult.x, hitResult.y, hitResult.z, 0);
this.world.updateBlockLightAt(hitResult.x, hitResult.y, hitResult.z);
} }
} }
@@ -124,6 +125,7 @@ window.Minecraft = class {
// Don't place blocks if the player is standing there // Don't place blocks if the player is standing there
if (!placedBoundingBox.intersects(this.player.boundingBox)) { if (!placedBoundingBox.intersects(this.player.boundingBox)) {
this.world.setBlockAt(x, y, z, this.pickedBlock); this.world.setBlockAt(x, y, z, this.pickedBlock);
this.world.updateBlockLightAt(x, y, z);
} }
} }
} }
+14 -16
View File
@@ -15,22 +15,22 @@ window.World = class {
onTick() { onTick() {
// Handle 128 light updates per tick // Handle 128 light updates per tick
for (let i = 0; i < 128; i++) { for (let i = 0; i < 128; i++) {
// Light updates // Light updates
if (this.lightUpdateQueue.length !== 0) { if (this.lightUpdateQueue.length !== 0) {
// Get next position to update // Get next position to update
let positionIndex = this.lightUpdateQueue.shift(); let positionIndex = this.lightUpdateQueue.shift();
if (positionIndex != null) { if (positionIndex != null) {
let z = positionIndex >> 16; let z = positionIndex >> 16;
let x = positionIndex - (z << 16); let x = positionIndex - (z << 16);
this.updateBlockLightsAtXZ(x, z); this.updateBlockLightsAtXZ(x, z);
} else { } else {
break; break;
} }
} }
} }
} }
loadChunk(chunk) { loadChunk(chunk) {
@@ -85,8 +85,6 @@ window.World = class {
let chunkSection = this.getChunkAtBlock(x, y, z); let chunkSection = this.getChunkAtBlock(x, y, z);
if (chunkSection != null) { if (chunkSection != null) {
chunkSection.setBlockAt(x & 15, y & 15, z & 15, type); chunkSection.setBlockAt(x & 15, y & 15, z & 15, type);
this.updateBlockLightAt(x, y, z);
} }
this.onBlockChanged(x, y, z); this.onBlockChanged(x, y, z);