fix water lightning

This commit is contained in:
LabyStudio
2022-02-02 15:38:15 +01:00
parent 010d883273
commit c5fd75de47
5 changed files with 32 additions and 14 deletions
+26 -4
View File
@@ -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);
}
+2 -2
View File
@@ -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;
}
@@ -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() {
@@ -5,7 +5,7 @@ window.BlockWater = class extends Block {
}
getOpacity() {
return 0.3;
return 0.93;
}
isSolid() {
@@ -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;