fix water lightning
This commit is contained in:
@@ -79,7 +79,14 @@ window.Chunk = class {
|
|||||||
if (y > currentHighestY) {
|
if (y > currentHighestY) {
|
||||||
highestY = y;
|
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--;
|
highestY--;
|
||||||
}
|
}
|
||||||
if (highestY === currentHighestY) {
|
if (highestY === currentHighestY) {
|
||||||
@@ -122,7 +129,11 @@ window.Chunk = class {
|
|||||||
let prevHeight = highestY;
|
let prevHeight = highestY;
|
||||||
while (highestY > 0 && lightLevel > 0) {
|
while (highestY > 0 && lightLevel > 0) {
|
||||||
highestY--;
|
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) {
|
if (opacity === 0) {
|
||||||
opacity = 1;
|
opacity = 1;
|
||||||
}
|
}
|
||||||
@@ -130,10 +141,20 @@ window.Chunk = class {
|
|||||||
if (lightLevel < 0) {
|
if (lightLevel < 0) {
|
||||||
lightLevel = 0;
|
lightLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setLightAt(EnumSkyBlock.SKY, relX, highestY, relZ, lightLevel);
|
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) {
|
if (highestY !== prevHeight) {
|
||||||
this.world.updateLight(EnumSkyBlock.SKY, x - 1, highestY, z - 1, x + 1, prevHeight, z + 1);
|
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);
|
//this.data.setNibble(i, j, k, i1);
|
||||||
//if (!this.worldObj.worldProvider.field_6478_e) {
|
//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) {
|
if (y >= height) {
|
||||||
this.updateHeightMap(x, y + 1, z);
|
this.updateHeightMap(x, y + 1, z);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ window.World = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
blockExists(x, y, z) {
|
blockExists(x, y, z) {
|
||||||
if (y < 0 || y >= 128) {
|
if (y < 0 || y >= World.TOTAL_HEIGHT) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return this.chunkExists(x >> 4, z >> 4);
|
return this.chunkExists(x >> 4, z >> 4);
|
||||||
@@ -167,7 +167,7 @@ window.World = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getSavedLightValue(sourceType, x, y, z) {
|
getSavedLightValue(sourceType, x, y, z) {
|
||||||
if (!this.chunkExists(x >> 4, z >> 4)) {
|
if (!this.blockExists(x, y, z)) {
|
||||||
return 15;
|
return 15;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
window.Block = class {
|
window.Block = class {
|
||||||
|
|
||||||
static blocks = new Map();
|
static blocks = new Map();
|
||||||
|
|
||||||
static lightOpacity = [];
|
|
||||||
|
|
||||||
static create() {
|
static create() {
|
||||||
Block.STONE = new BlockStone(1, 0);
|
Block.STONE = new BlockStone(1, 0);
|
||||||
Block.GRASS = new BlockGrass(2, 1);
|
Block.GRASS = new BlockGrass(2, 1);
|
||||||
@@ -22,9 +20,6 @@ window.Block = class {
|
|||||||
|
|
||||||
// Register block
|
// Register block
|
||||||
Block.blocks.set(id, this);
|
Block.blocks.set(id, this);
|
||||||
Block.lightOpacity[id] = this.isSolid() ? 255 : 0;
|
|
||||||
|
|
||||||
Block.lightOpacity[0] = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getId() {
|
getId() {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ window.BlockWater = class extends Block {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getOpacity() {
|
getOpacity() {
|
||||||
return 0.3;
|
return 0.93;
|
||||||
}
|
}
|
||||||
|
|
||||||
isSolid() {
|
isSolid() {
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ window.MetadataChunkBlock = class {
|
|||||||
let savedLightValue = world.getSavedLightValue(this.type, x, y, z);
|
let savedLightValue = world.getSavedLightValue(this.type, x, y, z);
|
||||||
let newLevel = 0;
|
let newLevel = 0;
|
||||||
let typeId = world.getBlockAt(x, y, z);
|
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) {
|
if (opacity === 0) {
|
||||||
opacity = 1;
|
opacity = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user