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,9 +53,13 @@ export default class ChunkSection {
this.group.clear(); this.group.clear();
let ambientOcclusion = this.world.minecraft.settings.ambientOcclusion; let ambientOcclusion = this.world.minecraft.settings.ambientOcclusion;
let tessellator = renderer.blockRenderer.tessellator;
// Two render phases for solid and translucent
for (let i = 0; i < 2; i++) {
let isTranslucentRenderPhase = i === 1;
// Start drawing chunk section // Start drawing chunk section
let tessellator = renderer.blockRenderer.tessellator;
tessellator.startDrawing(); tessellator.startDrawing();
for (let x = 0; x < ChunkSection.SIZE; x++) { for (let x = 0; x < ChunkSection.SIZE; x++) {
@@ -69,6 +73,10 @@ export default class ChunkSection {
let absoluteZ = this.z * ChunkSection.SIZE + z; let absoluteZ = this.z * ChunkSection.SIZE + z;
let block = Block.getById(typeId); let block = Block.getById(typeId);
if (block.isTranslucent() !== isTranslucentRenderPhase) {
continue;
}
renderer.blockRenderer.renderBlock(this.world, block, ambientOcclusion, absoluteX, absoluteY, absoluteZ); renderer.blockRenderer.renderBlock(this.world, block, ambientOcclusion, absoluteX, absoluteY, absoluteZ);
} }
} }
@@ -78,6 +86,7 @@ export default class ChunkSection {
// Draw chunk section // Draw chunk section
tessellator.draw(this.group); tessellator.draw(this.group);
} }
}
getBlockAt(x, y, z) { getBlockAt(x, y, z) {
let index = y << 8 | z << 4 | x; let index = y << 8 | z << 4 | x;
+2 -2
View File
@@ -301,9 +301,9 @@ export default class World {
return typeId !== 0 && Block.getById(typeId).isSolid(); return typeId !== 0 && Block.getById(typeId).isSolid();
} }
isTransparentBlockAt(x, y, z) { isTranslucentBlockAt(x, y, z) {
let typeId = this.getBlockAt(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) { setBlockAt(x, y, z, type) {
@@ -39,7 +39,7 @@ export default class Block {
return 0.0; return 0.0;
} }
isTransparent() { isTranslucent() {
return this.getTransparency() > 0.0; return this.getTransparency() > 0.0;
} }
@@ -1,4 +1,5 @@
import Block from "../Block.js"; import Block from "../Block.js";
import EnumBlockFace from "../../../../util/EnumBlockFace.js";
export default class BlockWater extends Block { export default class BlockWater extends Block {
@@ -28,7 +29,7 @@ export default class BlockWater extends Block {
shouldRenderFace(world, x, y, z, face) { shouldRenderFace(world, x, y, z, face) {
let typeId = world.getBlockAtFace(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) { getBoundingBox(world, x, y, z) {