1+ use std:: ops;
2+
13use super :: { LeavesMode , MapRenderSettings , MeshgenInfo , Vertex , CUBE , FACE_DIR } ;
24use cgmath:: Point3 ;
3- use mt_net:: MapBlock ;
5+ use mt_net:: { MapBlock , TileDef } ;
46
57#[ derive( Clone ) ]
68pub ( super ) struct MeshData {
@@ -21,6 +23,21 @@ impl MeshData {
2123 }
2224}
2325
26+ enum CowTileArray < ' a > {
27+ Borrowed ( & ' a [ TileDef ; 6 ] ) ,
28+ Owned ( [ & ' a TileDef ; 6 ] ) ,
29+ }
30+ impl < ' a > ops:: Index < usize > for CowTileArray < ' a > {
31+ type Output = TileDef ;
32+
33+ fn index ( & self , index : usize ) -> & Self :: Output {
34+ match self {
35+ CowTileArray :: Borrowed ( tiles) => & tiles[ index] ,
36+ CowTileArray :: Owned ( tiles) => tiles[ index] ,
37+ }
38+ }
39+ }
40+
2441pub ( super ) fn create_mesh (
2542 mkinfo : & MeshgenInfo ,
2643 settings : & MapRenderSettings ,
@@ -38,21 +55,24 @@ pub(super) fn create_mesh(
3855 use mt_net:: { DrawType , Param1Type } ;
3956 use std:: array:: from_fn as array;
4057
41- let mut tiles = & def. tiles ;
58+ let mut tiles = CowTileArray :: Borrowed ( & def. tiles ) ;
4259 let mut draw_type = def. draw_type ;
4360
4461 match draw_type {
4562 DrawType :: AllFacesOpt => {
4663 draw_type = match settings. leaves {
4764 LeavesMode :: Opaque => DrawType :: Cube ,
4865 LeavesMode :: Simple => {
49- tiles = & def. special_tiles ;
50-
66+ tiles = CowTileArray :: Borrowed ( & def. special_tiles ) ;
5167 DrawType :: GlassLike
5268 }
5369 LeavesMode :: Fancy => DrawType :: AllFaces ,
5470 } ;
5571 }
72+ DrawType :: Flowing => {
73+ let s = & def. special_tiles ;
74+ tiles = CowTileArray :: Owned ( [ & s[ 1 ] , & s[ 1 ] , & s[ 0 ] , & s[ 0 ] , & s[ 1 ] , & s[ 1 ] ] ) ;
75+ }
5676 DrawType :: None => continue ,
5777 _ => { }
5878 }
@@ -70,8 +90,17 @@ pub(super) fn create_mesh(
7090
7191 let pos: [ i16 ; 3 ] = array ( |i| ( ( index >> ( 4 * i) ) & 0xf ) as i16 ) ;
7292
93+ let alt_content = match draw_type {
94+ DrawType :: Liquid => mkinfo. node_names_to_ids . get ( & def. flowing_alt ) . copied ( ) ,
95+ DrawType :: Flowing => mkinfo. node_names_to_ids . get ( & def. source_alt ) . copied ( ) ,
96+ _ => None ,
97+ } ;
98+
7399 for ( f, face) in CUBE . iter ( ) . enumerate ( ) {
74- if draw_type == DrawType :: Cube || draw_type == DrawType :: Liquid {
100+ if draw_type == DrawType :: Cube
101+ || draw_type == DrawType :: Liquid
102+ || draw_type == DrawType :: Flowing
103+ {
75104 let c = [ 1 , 1 , 0 , 0 , 2 , 2 ] [ f] ;
76105
77106 let mut nblk = block;
@@ -93,7 +122,11 @@ pub(super) fn create_mesh(
93122 if let Some ( ndef) = & mkinfo. nodes [ ncontent as usize ] {
94123 if match draw_type {
95124 DrawType :: Cube => ndef. draw_type == DrawType :: Cube ,
96- DrawType :: Liquid => ndef. draw_type == DrawType :: Cube || ncontent == content,
125+ DrawType :: Liquid | DrawType :: Flowing => {
126+ ndef. draw_type == DrawType :: Cube
127+ || ncontent == content
128+ || Some ( ncontent) == alt_content
129+ }
97130 _ => false ,
98131 } {
99132 continue ;
0 commit comments