fix water render issues

This commit is contained in:
LabyStudio
2022-05-05 00:04:07 +02:00
parent d846613ca9
commit a3a4d44386
4 changed files with 30 additions and 20 deletions
@@ -53,30 +53,39 @@ export default class ChunkSection {
this.group.clear();
let ambientOcclusion = this.world.minecraft.settings.ambientOcclusion;
// Start drawing chunk section
let tessellator = renderer.blockRenderer.tessellator;
tessellator.startDrawing();
for (let x = 0; x < ChunkSection.SIZE; x++) {
for (let y = 0; y < ChunkSection.SIZE; y++) {
for (let z = 0; z < ChunkSection.SIZE; z++) {
let typeId = this.getBlockAt(x, y, z);
// Two render phases for solid and translucent
for (let i = 0; i < 2; i++) {
let isTranslucentRenderPhase = i === 1;
if (typeId !== 0) {
let absoluteX = this.x * ChunkSection.SIZE + x;
let absoluteY = this.y * ChunkSection.SIZE + y;
let absoluteZ = this.z * ChunkSection.SIZE + z;
// Start drawing chunk section
tessellator.startDrawing();
let block = Block.getById(typeId);
renderer.blockRenderer.renderBlock(this.world, block, ambientOcclusion, absoluteX, absoluteY, absoluteZ);
for (let x = 0; x < ChunkSection.SIZE; x++) {
for (let y = 0; y < ChunkSection.SIZE; y++) {
for (let z = 0; z < ChunkSection.SIZE; z++) {
let typeId = this.getBlockAt(x, y, z);
if (typeId !== 0) {
let absoluteX = this.x * ChunkSection.SIZE + x;
let absoluteY = this.y * ChunkSection.SIZE + y;
let absoluteZ = this.z * ChunkSection.SIZE + z;
let block = Block.getById(typeId);
if (block.isTranslucent() !== isTranslucentRenderPhase) {
continue;
}
renderer.blockRenderer.renderBlock(this.world, block, ambientOcclusion, absoluteX, absoluteY, absoluteZ);
}
}
}
}
}
// Draw chunk section
tessellator.draw(this.group);
// Draw chunk section
tessellator.draw(this.group);
}
}
getBlockAt(x, y, z) {
+2 -2
View File
@@ -301,9 +301,9 @@ export default class World {
return typeId !== 0 && Block.getById(typeId).isSolid();
}
isTransparentBlockAt(x, y, z) {
isTranslucentBlockAt(x, y, z) {
let typeId = this.getBlockAt(x, y, z);
return typeId === 0 || Block.getById(typeId).isTransparent();
return typeId === 0 || Block.getById(typeId).isTranslucent();
}
setBlockAt(x, y, z, type) {
@@ -39,7 +39,7 @@ export default class Block {
return 0.0;
}
isTransparent() {
isTranslucent() {
return this.getTransparency() > 0.0;
}
@@ -1,4 +1,5 @@
import Block from "../Block.js";
import EnumBlockFace from "../../../../util/EnumBlockFace.js";
export default class BlockWater extends Block {
@@ -28,7 +29,7 @@ export default class BlockWater extends Block {
shouldRenderFace(world, x, y, z, face) {
let typeId = world.getBlockAtFace(x, y, z, face);
return typeId === 0 || typeId !== this.id && Block.getById(typeId).isTransparent();
return typeId === 0 || typeId !== this.id || typeId !== this.id && face === EnumBlockFace.TOP;
}
getBoundingBox(world, x, y, z) {