From a3a4d4438687aa0cb263a11c848e0c9ade4c4379 Mon Sep 17 00:00:00 2001 From: LabyStudio Date: Thu, 5 May 2022 00:04:07 +0200 Subject: [PATCH] fix water render issues --- .../minecraft/client/world/ChunkSection.js | 41 +++++++++++-------- src/js/net/minecraft/client/world/World.js | 4 +- .../net/minecraft/client/world/block/Block.js | 2 +- .../client/world/block/type/BlockWater.js | 3 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/js/net/minecraft/client/world/ChunkSection.js b/src/js/net/minecraft/client/world/ChunkSection.js index 13b40c0..73edd3f 100644 --- a/src/js/net/minecraft/client/world/ChunkSection.js +++ b/src/js/net/minecraft/client/world/ChunkSection.js @@ -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) { diff --git a/src/js/net/minecraft/client/world/World.js b/src/js/net/minecraft/client/world/World.js index 4222e13..9e48afe 100644 --- a/src/js/net/minecraft/client/world/World.js +++ b/src/js/net/minecraft/client/world/World.js @@ -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) { diff --git a/src/js/net/minecraft/client/world/block/Block.js b/src/js/net/minecraft/client/world/block/Block.js index 4205206..4636959 100644 --- a/src/js/net/minecraft/client/world/block/Block.js +++ b/src/js/net/minecraft/client/world/block/Block.js @@ -39,7 +39,7 @@ export default class Block { return 0.0; } - isTransparent() { + isTranslucent() { return this.getTransparency() > 0.0; } diff --git a/src/js/net/minecraft/client/world/block/type/BlockWater.js b/src/js/net/minecraft/client/world/block/type/BlockWater.js index 57dabf9..f8736f4 100644 --- a/src/js/net/minecraft/client/world/block/type/BlockWater.js +++ b/src/js/net/minecraft/client/world/block/type/BlockWater.js @@ -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) {