Skip to content

Commit 05b0aad

Browse files
committed
add water levels
1 parent 8e0383d commit 05b0aad

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

src/client/scripts/World/ChunkMesher.js

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,53 @@
11
const CustomRender = {
2-
water: function(t_positions, t_normals, t_uvs, t_colors, positions, normals, uvs, colors, pos) {
3-
for (var l in this.neighbours) {
4-
const offset = this.neighbours[l];
5-
if (
6-
this.chunkTerrain.getBlock(
2+
water: function (t_positions, t_normals, t_uvs, t_colors, positions, normals, uvs, colors, pos) {
3+
const block = this.chunkTerrain.getBlock(pos[0], pos[1], pos[2]);
4+
const state = block.stateId;
5+
6+
const falling = !!(state & 8);
7+
const level = state - 32;
8+
if (level == 10) {
9+
10+
for (const l in this.neighbours) {
11+
const offset = this.neighbours[l];
12+
if (this.chunkTerrain.getBlock(
713
pos[0] + offset[0],
814
pos[1] + offset[1],
915
pos[2] + offset[2]
10-
).name !== "water"
11-
) {
12-
this.addFace(t_positions, t_normals, t_uvs, t_colors, positions, normals, uvs, colors, l, pos);
16+
).name !== "water")
17+
this.addFace(t_positions, t_normals, t_uvs, t_colors, positions, normals, uvs, colors, l, pos);
18+
19+
}
20+
} else {
21+
for (const side in this.neighbours) {
22+
const offset = this.neighbours[side];
23+
if (this.chunkTerrain.getBlock(
24+
pos[0] + offset[0],
25+
pos[1] + offset[1],
26+
pos[2] + offset[2]
27+
).name === "water")
28+
continue;
29+
const faceVertex = this.genBlockFace(side, block, pos);
30+
switch (side) {
31+
case "py":
32+
for (let i = 0; i < 6; i++) {
33+
faceVertex.pos[3 * i + 1] -= (level - 1) / 9;
34+
}
35+
break;
36+
case "nx":
37+
case "px":
38+
case "nz":
39+
case "pz":
40+
faceVertex.pos[3 * 2 + 1] -= (level - 1) / 9;
41+
faceVertex.pos[3 * 3 + 1] -= (level - 1) / 9;
42+
faceVertex.pos[3 * 5 + 1] -= (level - 1) / 9;
43+
44+
break;
45+
}
46+
this.ambientOcclusion(t_positions, t_normals, t_uvs, t_colors,
47+
positions, normals, uvs, colors, block, pos, faceVertex, side)
48+
this.push(t_positions, t_normals, t_uvs, t_colors,
49+
positions, normals, uvs, colors,
50+
faceVertex, this.chunkTerrain.getBlock(...pos).transparent);
1351
}
1452
}
1553
}

0 commit comments

Comments
 (0)