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 (
7+ pos [ 0 ] + offset [ 0 ] ,
8+ pos [ 1 ] + offset [ 1 ] ,
9+ 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 ) ;
13+ }
14+ }
15+ }
16+
17+ }
18+
19+
120class ChunkMesher {
221 constructor ( options ) {
322 this . cellSize = 16 ;
@@ -15,6 +34,10 @@ class ChunkMesher {
1534 pz : [ 0 , 0 , 1 ] ,
1635 nz : [ 0 , 0 , - 1 ] ,
1736 } ;
37+ this . customRender = { } ;
38+ for ( const funcName in CustomRender ) {
39+ this . customRender [ funcName ] = CustomRender [ funcName ] . bind ( this )
40+ }
1841 }
1942
2043 getUvForFace ( block , type ) {
@@ -471,8 +494,7 @@ class ChunkMesher {
471494 }
472495 }
473496 } else if (
474- this . chunkTerrain . getBlock ( ...pos ) . name === "water" ||
475- this . chunkTerrain . getBlock ( ...pos ) . name === "lava"
497+ this . chunkTerrain . getBlock ( ...pos ) . name === "lava"
476498 ) {
477499 for ( var l in this . neighbours ) {
478500 const offset = this . neighbours [ l ] ;
@@ -481,11 +503,13 @@ class ChunkMesher {
481503 pos [ 0 ] + offset [ 0 ] ,
482504 pos [ 1 ] + offset [ 1 ] ,
483505 pos [ 2 ] + offset [ 2 ]
484- ) . name !== "water "
506+ ) . name !== "lava "
485507 ) {
486508 this . addFace ( t_positions , t_normals , t_uvs , t_colors , positions , normals , uvs , colors , l , pos ) ;
487509 }
488510 }
511+ } else if ( this . customRender [ this . chunkTerrain . getBlock ( ...pos ) . name ] ) {
512+ this . customRender [ this . chunkTerrain . getBlock ( ...pos ) . name ] ( t_positions , t_normals , t_uvs , t_colors , positions , normals , uvs , colors , pos ) ;
489513 }
490514 }
491515 }
0 commit comments