From c5fd75de479a883743beb372af30ff1d2be691eb Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Wed, 2 Feb 2022 15:38:15 +0100 Subject: [PATCH] fix water lightning --- src/js/net/minecraft/client/world/Chunk.js | 30 ++++++++++++++++--- src/js/net/minecraft/client/world/World.js | 4 +-- .../net/minecraft/client/world/block/Block.js | 7 +---- .../client/world/block/BlockWater.js | 2 +- .../net/minecraft/util/MetadataChunkBlock.js | 3 +- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/js/net/minecraft/client/world/Chunk.js b/src/js/net/minecraft/client/world/Chunk.js index eb32724..03afa51 100644 --- a/src/js/net/minecraft/client/world/Chunk.js +++ b/src/js/net/minecraft/client/world/Chunk.js @@ -79,7 +79,14 @@ window.Chunk = class { if (y > currentHighestY) { highestY = y; } - while (highestY > 0 && Block.lightOpacity[this.getBlockAt(relX, highestY, relZ)] === 0) { + while (highestY > 0) { + let typeId = this.getBlockAt(relX, highestY, relZ); + let block = Block.getById(typeId); + + if (typeId !== 0 && block.getOpacity() !== 0) { + break; + } + highestY--; } if (highestY === currentHighestY) { @@ -122,7 +129,11 @@ window.Chunk = class { let prevHeight = highestY; while (highestY > 0 && lightLevel > 0) { highestY--; - let opacity = Block.lightOpacity[this.getBlockID(relX, highestY, relZ)]; + + let typeId = this.getBlockID(relX, highestY, relZ); + let block = Block.getById(typeId); + + let opacity = Math.floor(typeId === 0 ? 0 : block.getOpacity() * 255); if (opacity === 0) { opacity = 1; } @@ -130,10 +141,20 @@ window.Chunk = class { if (lightLevel < 0) { lightLevel = 0; } + this.setLightAt(EnumSkyBlock.SKY, relX, highestY, relZ, lightLevel); } - for (; highestY > 0 && Block.lightOpacity[this.getBlockID(relX, highestY - 1, relZ)] === 0; highestY--) { + + while (highestY > 0) { + let typeId = this.getBlockID(relX, highestY - 1, relZ); + let block = Block.getById(typeId); + + if (typeId !== 0 && block.isSolid()) { + break; + } + highestY--; } + if (highestY !== prevHeight) { this.world.updateLight(EnumSkyBlock.SKY, x - 1, highestY, z - 1, x + 1, prevHeight, z + 1); } @@ -168,7 +189,8 @@ window.Chunk = class { //this.data.setNibble(i, j, k, i1); //if (!this.worldObj.worldProvider.field_6478_e) { - if (Block.lightOpacity[byte0] !== 0) { + let block = Block.getById(typeId); + if (typeId !== 0 && block.isSolid()) { if (y >= height) { this.updateHeightMap(x, y + 1, z); } diff --git a/src/js/net/minecraft/client/world/World.js b/src/js/net/minecraft/client/world/World.js index df13ccd..8b7bdc6 100644 --- a/src/js/net/minecraft/client/world/World.js +++ b/src/js/net/minecraft/client/world/World.js @@ -112,7 +112,7 @@ window.World = class { } blockExists(x, y, z) { - if (y < 0 || y >= 128) { + if (y < 0 || y >= World.TOTAL_HEIGHT) { return false; } else { return this.chunkExists(x >> 4, z >> 4); @@ -167,7 +167,7 @@ window.World = class { } getSavedLightValue(sourceType, x, y, z) { - if (!this.chunkExists(x >> 4, z >> 4)) { + if (!this.blockExists(x, y, z)) { return 15; } diff --git a/src/js/net/minecraft/client/world/block/Block.js b/src/js/net/minecraft/client/world/block/Block.js index 212a3a3..8388fd0 100644 --- a/src/js/net/minecraft/client/world/block/Block.js +++ b/src/js/net/minecraft/client/world/block/Block.js @@ -1,9 +1,7 @@ window.Block = class { static blocks = new Map(); - - static lightOpacity = []; - + static create() { Block.STONE = new BlockStone(1, 0); Block.GRASS = new BlockGrass(2, 1); @@ -22,9 +20,6 @@ window.Block = class { // Register block Block.blocks.set(id, this); - Block.lightOpacity[id] = this.isSolid() ? 255 : 0; - - Block.lightOpacity[0] = 0; } getId() { diff --git a/src/js/net/minecraft/client/world/block/BlockWater.js b/src/js/net/minecraft/client/world/block/BlockWater.js index a46be8e..b50cd86 100644 --- a/src/js/net/minecraft/client/world/block/BlockWater.js +++ b/src/js/net/minecraft/client/world/block/BlockWater.js @@ -5,7 +5,7 @@ window.BlockWater = class extends Block { } getOpacity() { - return 0.3; + return 0.93; } isSolid() { diff --git a/src/js/net/minecraft/util/MetadataChunkBlock.js b/src/js/net/minecraft/util/MetadataChunkBlock.js index 4ef99d1..38caeb9 100644 --- a/src/js/net/minecraft/util/MetadataChunkBlock.js +++ b/src/js/net/minecraft/util/MetadataChunkBlock.js @@ -32,7 +32,8 @@ window.MetadataChunkBlock = class { let savedLightValue = world.getSavedLightValue(this.type, x, y, z); let newLevel = 0; let typeId = world.getBlockAt(x, y, z); - let opacity = Block.lightOpacity[typeId]; + let block = Block.getById(typeId); + let opacity = typeId === 0 ? 0 : block.getOpacity() * 255; if (opacity === 0) { opacity = 1;