@@ -109,7 +109,7 @@ public static class World
109109 { "jungle_button" , new [ ] { "planks_jungle" } } ,
110110 } ) ;
111111
112- private static Dictionary < string , Func < int , string [ ] > > multiTextureBlocks = new Dictionary < string , Func < int , string [ ] > > ( ) // texture => { data, return final texture}
112+ private static Dictionary < string , Func < int , string [ ] > > specialTextureLoad = new Dictionary < string , Func < int , string [ ] > > ( ) // texture => { data, return final texture}
113113 {
114114 { "planks" , ( int data ) =>
115115 {
@@ -656,6 +656,18 @@ public static class World
656656 }
657657 }
658658 } ,
659+ { "vine" , ( int data ) =>
660+ {
661+ // make green
662+ SystemPlus . Utils . DirectBitmap db = SystemPlus . Utils . DirectBitmap . Load ( textureBasePath + "vine.png" ) ;
663+ for ( int i = 0 ; i < db . Data . Length ; i ++ ) {
664+ System . Drawing . Color c = System . Drawing . Color . FromArgb ( db . Data [ i ] ) ;
665+ db . Data [ i ] = System . Drawing . Color . FromArgb ( c . A , 0 , c . G , 0 ) . ToArgb ( ) ;
666+ }
667+ db . Bitmap . Save ( textureBasePath + "vine.png" ) ;
668+ return new string [ ] { "vine" } ;
669+ }
670+ } ,
659671 // doors
660672 { "iron_door" , ( int data ) =>
661673 {
@@ -792,6 +804,29 @@ public static class World
792804 { "vine" , 19 } ,
793805 } ;
794806
807+ public static readonly bool [ ] RendererIsFullBlockLookUp = new bool [ ]
808+ {
809+ true , // normal
810+ false ,
811+ false ,
812+ false ,
813+ false ,
814+ false ,
815+ false ,
816+ false ,
817+ false ,
818+ false ,
819+ false ,
820+ false ,
821+ false ,
822+ false ,
823+ false ,
824+ false ,
825+ false ,
826+ true , // log
827+ true , // stripped log
828+ false ,
829+ } ;
795830
796831 public delegate void RenderBlock ( Vector3 pos , Vector3i cp /*chunk pos, pre multiplied*/ , int [ ] tex , int data , ref List < Vertex > vertices , ref List < uint > triangles ) ;
797832
@@ -1137,19 +1172,19 @@ public static class World
11371172 int r2 = GetRenderer ( iPos + new Vector3i ( - 1 , 0 , 0 ) + cp ) ;
11381173 int r3 = GetRenderer ( iPos + new Vector3i ( 0 , 0 , 1 ) + cp ) ;
11391174 int r4 = GetRenderer ( iPos + new Vector3i ( 0 , 0 , - 1 ) + cp ) ;
1140- if ( r1 == 7 || r1 == 12 || r1 == 0 ) {
1175+ if ( r1 == 7 || r1 == 12 || IsRendererFullBlock ( r1 ) ) {
11411176 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0.35f , 0.15f , 0f ) , size2 , ref vertices , ref triangles ) ;
11421177 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0.35f , - 0.15f , 0f ) , size2 , ref vertices , ref triangles ) ;
11431178 }
1144- if ( r2 == 7 || r2 == 12 || r2 == 0 ) {
1179+ if ( r2 == 7 || r2 == 12 || IsRendererFullBlock ( r2 ) ) {
11451180 CubeTex ( tex [ 0 ] , pos + new Vector3 ( - 0.35f , 0.15f , 0f ) , size2 , ref vertices , ref triangles ) ;
11461181 CubeTex ( tex [ 0 ] , pos + new Vector3 ( - 0.35f , - 0.15f , 0f ) , size2 , ref vertices , ref triangles ) ;
11471182 }
1148- if ( r3 == 7 || r3 == 12 || r3 == 0 ) {
1183+ if ( r3 == 7 || r3 == 12 || IsRendererFullBlock ( r3 ) ) {
11491184 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , 0.15f , 0.35f ) , size3 , ref vertices , ref triangles ) ;
11501185 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , - 0.15f , 0.35f ) , size3 , ref vertices , ref triangles ) ;
11511186 }
1152- if ( r4 == 7 || r4 == 12 || r4 == 0 ) {
1187+ if ( r4 == 7 || r4 == 12 || IsRendererFullBlock ( r4 ) ) {
11531188 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , 0.15f , - 0.35f ) , size3 , ref vertices , ref triangles ) ;
11541189 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , - 0.15f , - 0.35f ) , size3 , ref vertices , ref triangles ) ;
11551190 }
@@ -1178,13 +1213,13 @@ public static class World
11781213 int r2 = GetRenderer ( iPos + new Vector3i ( - 1 , 0 , 0 ) + cp ) ;
11791214 int r3 = GetRenderer ( iPos + new Vector3i ( 0 , 0 , 1 ) + cp ) ;
11801215 int r4 = GetRenderer ( iPos + new Vector3i ( 0 , 0 , - 1 ) + cp ) ;
1181- if ( r1 == 9 || r1 == 0 )
1216+ if ( r1 == 9 || IsRendererFullBlock ( r1 ) )
11821217 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0.3f , 0f , 0f ) , size2 , ref vertices , ref triangles ) ;
1183- if ( r2 == 9 || r2 == 0 )
1218+ if ( r2 == 9 || IsRendererFullBlock ( r2 ) )
11841219 CubeTex ( tex [ 0 ] , pos + new Vector3 ( - 0.3f , 0f , 0f ) , size2 , ref vertices , ref triangles ) ;
1185- if ( r3 == 9 || r3 == 0 )
1220+ if ( r3 == 9 || IsRendererFullBlock ( r3 ) )
11861221 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , 0f , 0.3f ) , size3 , ref vertices , ref triangles ) ;
1187- if ( r4 == 9 || r4 == 0 )
1222+ if ( r4 == 9 || IsRendererFullBlock ( r4 ) )
11881223 CubeTex ( tex [ 0 ] , pos + new Vector3 ( 0f , 0f , - 0.3f ) , size3 , ref vertices , ref triangles ) ;
11891224 }
11901225 } ,
@@ -1394,15 +1429,15 @@ public static class World
13941429 for ( int p = 0 ; p < 6 ; p ++ ) {
13951430 uint firstVertIndex = ( uint ) vertices . Count ;
13961431 if ( p == 2 || p == 3 ) { // top/bottom
1397- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 0 ] ] + offset , VoxelData . voxelUvs [ 0 ] , texTopBottom ) ) ;
1398- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 1 ] ] + offset , VoxelData . voxelUvs [ 1 ] , texTopBottom ) ) ;
1399- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 2 ] ] + offset , VoxelData . voxelUvs [ 2 ] , texTopBottom ) ) ;
1400- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 3 ] ] + offset , VoxelData . voxelUvs [ 3 ] , texTopBottom ) ) ;
1432+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 0 ] ] + offset ) * mat , VoxelData . voxelUvs [ 0 ] , texTopBottom ) ) ;
1433+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 1 ] ] + offset ) * mat , VoxelData . voxelUvs [ 1 ] , texTopBottom ) ) ;
1434+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 2 ] ] + offset ) * mat , VoxelData . voxelUvs [ 2 ] , texTopBottom ) ) ;
1435+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 3 ] ] + offset ) * mat , VoxelData . voxelUvs [ 3 ] , texTopBottom ) ) ;
14011436 } else {
1402- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 0 ] ] + offset , VoxelData . voxelUvs [ 0 ] , texSide ) ) ;
1403- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 1 ] ] + offset , VoxelData . voxelUvs [ 1 ] , texSide ) ) ;
1404- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 2 ] ] + offset , VoxelData . voxelUvs [ 2 ] , texSide ) ) ;
1405- vertices . Add ( new Vertex ( pos + VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 3 ] ] + offset , VoxelData . voxelUvs [ 3 ] , texSide ) ) ;
1437+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 0 ] ] + offset ) * mat , VoxelData . voxelUvs [ 0 ] , texSide ) ) ;
1438+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 1 ] ] + offset ) * mat , VoxelData . voxelUvs [ 1 ] , texSide ) ) ;
1439+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 2 ] ] + offset ) * mat , VoxelData . voxelUvs [ 2 ] , texSide ) ) ;
1440+ vertices . Add ( new Vertex ( pos + ( VoxelData . voxelVerts [ VoxelData . voxelTris [ p , 3 ] ] + offset ) * mat , VoxelData . voxelUvs [ 3 ] , texSide ) ) ;
14061441 }
14071442 triangles . Add ( firstVertIndex ) ;
14081443 triangles . Add ( firstVertIndex + 1 ) ;
@@ -1419,11 +1454,42 @@ public static class World
14191454 ref vertices , ref triangles ) ;
14201455 }
14211456 } ,
1422- { 19 , ( Vector3 pos , Vector3i cp , int [ ] tex , int data , ref List < Vertex > vertices , ref List < uint > triangles ) => // vine
1457+ { 19 , ( Vector3 pos , Vector3i cp , int [ ] texA , int data , ref List < Vertex > vertices , ref List < uint > triangles ) => // vine
14231458 {
1424- Vector3 offset = new Vector3 ( 0f , 0f , 0f ) ;
1425- Vector3 size = new Vector3 ( 1f , 1f , 1f ) ;
1426- CubeTex ( tex [ 0 ] , pos + offset , size , ref vertices , ref triangles ) ;
1459+ Vector3 offset = new Vector3 ( - 0.5f , - 0.5f , - 0.5f ) ;
1460+
1461+ uint tex = ( uint ) texA [ 0 ] ;
1462+
1463+ int dir = data & 0b_1111 ; // -z, -x, +z, +x
1464+
1465+ bool [ ] vineAt = new bool [ 4 ] ;
1466+ int mask = 0b_0001 ;
1467+ for ( int i = 0 ; i < vineAt . Length ; i ++ ) // get every bit as bool
1468+ {
1469+ vineAt [ i ] = Convert . ToBoolean ( ( dir & mask ) >> i ) ;
1470+ mask <<= i ;
1471+ }
1472+
1473+ for ( int i = 0 ; i < vineAt . Length ; i ++ )
1474+ {
1475+ if ( vineAt [ i ] ) {
1476+ for ( int p = 0 ; p < 2 ; p ++ )
1477+ {
1478+ uint firstVertIndex = ( uint ) vertices . Count ;
1479+ vertices . Add ( new Vertex ( pos + VoxelData . Vine . verts [ i , VoxelData . Vine . tris [ p , 0 ] ] + offset , VoxelData . voxelUvs [ 0 ] , tex ) ) ;
1480+ vertices . Add ( new Vertex ( pos + VoxelData . Vine . verts [ i , VoxelData . Vine . tris [ p , 1 ] ] + offset , VoxelData . voxelUvs [ 1 ] , tex ) ) ;
1481+ vertices . Add ( new Vertex ( pos + VoxelData . Vine . verts [ i , VoxelData . Vine . tris [ p , 2 ] ] + offset , VoxelData . voxelUvs [ 2 ] , tex ) ) ;
1482+ vertices . Add ( new Vertex ( pos + VoxelData . Vine . verts [ i , VoxelData . Vine . tris [ p , 3 ] ] + offset , VoxelData . voxelUvs [ 3 ] , tex ) ) ;
1483+
1484+ triangles . Add ( firstVertIndex ) ;
1485+ triangles . Add ( firstVertIndex + 1 ) ;
1486+ triangles . Add ( firstVertIndex + 2 ) ;
1487+ triangles . Add ( firstVertIndex + 2 ) ;
1488+ triangles . Add ( firstVertIndex + 1 ) ;
1489+ triangles . Add ( firstVertIndex + 3 ) ;
1490+ }
1491+ }
1492+ }
14271493 }
14281494 } ,
14291495 } ;
@@ -1541,6 +1607,14 @@ public static void GetBlockIndex(int x, int y, int z, out int subChunkIndex, out
15411607 }
15421608 }
15431609
1610+ public static bool IsRendererFullBlock ( int renderer )
1611+ {
1612+ if ( renderer < 0 || renderer >= RendererIsFullBlockLookUp . Length )
1613+ return false ;
1614+ else
1615+ return RendererIsFullBlockLookUp [ renderer ] ;
1616+ }
1617+
15441618 public static SubChunk [ ] chunks ;
15451619
15461620 public static void Init ( )
@@ -1582,8 +1656,8 @@ public static void Init()
15821656 if ( texReplacements . ContainsKey ( blockName [ 0 ] ) )
15831657 blockName = texReplacements [ blockName [ 0 ] ] . Cloned ( ) ;
15841658
1585- if ( multiTextureBlocks . ContainsKey ( blockName [ 0 ] ) )
1586- blockName = multiTextureBlocks [ blockName [ 0 ] ] . Invoke ( paletteBlock . data ) ;
1659+ if ( specialTextureLoad . ContainsKey ( blockName [ 0 ] ) )
1660+ blockName = specialTextureLoad [ blockName [ 0 ] ] . Invoke ( paletteBlock . data ) ;
15871661
15881662 for ( int i = 0 ; i < blockName . Length ; i ++ ) {
15891663 if ( blockName [ i ] . Contains ( "." ) )
0 commit comments