|
1 | 1 | 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( |
7 | 13 | pos[0] + offset[0], |
8 | 14 | pos[1] + offset[1], |
9 | 15 | 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); |
13 | 51 | } |
14 | 52 | } |
15 | 53 | } |
|
0 commit comments