]> git.lizzy.rs Git - minetest.git/blob - src/content_mapblock.cpp
Migrate to STL containers/algorithms.
[minetest.git] / src / content_mapblock.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "content_mapblock.h"
21
22 #include "main.h" // For g_settings
23 #include "mapblock_mesh.h" // For MapBlock_LightColor() and MeshCollector
24 #include "settings.h"
25 #include "nodedef.h"
26 #include "tile.h"
27 #include "gamedef.h"
28 #include "util/numeric.h"
29 #include "util/directiontables.h"
30
31 // Create a cuboid.
32 //  collector - the MeshCollector for the resulting polygons
33 //  box       - the position and size of the box
34 //  tiles     - the tiles (materials) to use (for all 6 faces)
35 //  tilecount - number of entries in tiles, 1<=tilecount<=6
36 //  c         - vertex colour - used for all
37 //  txc       - texture coordinates - this is a list of texture coordinates
38 //              for the opposite corners of each face - therefore, there
39 //              should be (2+2)*6=24 values in the list. Alternatively, pass
40 //              NULL to use the entire texture for each face. The order of
41 //              the faces in the list is up-down-right-left-back-front
42 //              (compatible with ContentFeatures). If you specified 0,0,1,1
43 //              for each face, that would be the same as passing NULL.
44 void makeCuboid(MeshCollector *collector, const aabb3f &box,
45         const TileSpec *tiles, int tilecount,
46         video::SColor &c, const f32* txc)
47 {
48         assert(tilecount >= 1 && tilecount <= 6);
49
50         v3f min = box.MinEdge;
51         v3f max = box.MaxEdge;
52
53         if(txc == NULL)
54         {
55                 static const f32 txc_default[24] = {
56                         0,0,1,1,
57                         0,0,1,1,
58                         0,0,1,1,
59                         0,0,1,1,
60                         0,0,1,1,
61                         0,0,1,1
62                 };
63                 txc = txc_default;
64         }
65
66         video::S3DVertex vertices[24] =
67         {
68                 // up
69                 video::S3DVertex(min.X,max.Y,max.Z, 0,1,0, c, txc[0],txc[1]),
70                 video::S3DVertex(max.X,max.Y,max.Z, 0,1,0, c, txc[2],txc[1]),
71                 video::S3DVertex(max.X,max.Y,min.Z, 0,1,0, c, txc[2],txc[3]),
72                 video::S3DVertex(min.X,max.Y,min.Z, 0,1,0, c, txc[0],txc[3]),
73                 // down
74                 video::S3DVertex(min.X,min.Y,min.Z, 0,-1,0, c, txc[4],txc[5]),
75                 video::S3DVertex(max.X,min.Y,min.Z, 0,-1,0, c, txc[6],txc[5]),
76                 video::S3DVertex(max.X,min.Y,max.Z, 0,-1,0, c, txc[6],txc[7]),
77                 video::S3DVertex(min.X,min.Y,max.Z, 0,-1,0, c, txc[4],txc[7]),
78                 // right
79                 video::S3DVertex(max.X,max.Y,min.Z, 1,0,0, c, txc[ 8],txc[9]),
80                 video::S3DVertex(max.X,max.Y,max.Z, 1,0,0, c, txc[10],txc[9]),
81                 video::S3DVertex(max.X,min.Y,max.Z, 1,0,0, c, txc[10],txc[11]),
82                 video::S3DVertex(max.X,min.Y,min.Z, 1,0,0, c, txc[ 8],txc[11]),
83                 // left
84                 video::S3DVertex(min.X,max.Y,max.Z, -1,0,0, c, txc[12],txc[13]),
85                 video::S3DVertex(min.X,max.Y,min.Z, -1,0,0, c, txc[14],txc[13]),
86                 video::S3DVertex(min.X,min.Y,min.Z, -1,0,0, c, txc[14],txc[15]),
87                 video::S3DVertex(min.X,min.Y,max.Z, -1,0,0, c, txc[12],txc[15]),
88                 // back
89                 video::S3DVertex(max.X,max.Y,max.Z, 0,0,1, c, txc[16],txc[17]),
90                 video::S3DVertex(min.X,max.Y,max.Z, 0,0,1, c, txc[18],txc[17]),
91                 video::S3DVertex(min.X,min.Y,max.Z, 0,0,1, c, txc[18],txc[19]),
92                 video::S3DVertex(max.X,min.Y,max.Z, 0,0,1, c, txc[16],txc[19]),
93                 // front
94                 video::S3DVertex(min.X,max.Y,min.Z, 0,0,-1, c, txc[20],txc[21]),
95                 video::S3DVertex(max.X,max.Y,min.Z, 0,0,-1, c, txc[22],txc[21]),
96                 video::S3DVertex(max.X,min.Y,min.Z, 0,0,-1, c, txc[22],txc[23]),
97                 video::S3DVertex(min.X,min.Y,min.Z, 0,0,-1, c, txc[20],txc[23]),
98         };
99
100         for(s32 j=0; j<24; j++)
101         {
102                 int tileindex = MYMIN(j/4, tilecount-1);
103                 vertices[j].TCoords *= tiles[tileindex].texture.size;
104                 vertices[j].TCoords += tiles[tileindex].texture.pos;
105         }
106
107         u16 indices[] = {0,1,2,2,3,0};
108
109         // Add to mesh collector
110         for(s32 j=0; j<24; j+=4)
111         {
112                 int tileindex = MYMIN(j/4, tilecount-1);
113                 collector->append(tiles[tileindex],
114                                 vertices+j, 4, indices, 6);
115         }
116 }
117
118 void mapblock_mesh_generate_special(MeshMakeData *data,
119                 MeshCollector &collector)
120 {
121         INodeDefManager *nodedef = data->m_gamedef->ndef();
122
123         // 0ms
124         //TimeTaker timer("mapblock_mesh_generate_special()");
125
126         /*
127                 Some settings
128         */
129         bool new_style_water = g_settings->getBool("new_style_water");
130         
131         float node_liquid_level = 1.0;
132         if(new_style_water)
133                 node_liquid_level = 0.85;
134         
135         v3s16 blockpos_nodes = data->m_blockpos*MAP_BLOCKSIZE;
136
137         for(s16 z=0; z<MAP_BLOCKSIZE; z++)
138         for(s16 y=0; y<MAP_BLOCKSIZE; y++)
139         for(s16 x=0; x<MAP_BLOCKSIZE; x++)
140         {
141                 v3s16 p(x,y,z);
142
143                 MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes+p);
144                 const ContentFeatures &f = nodedef->get(n);
145
146                 // Only solidness=0 stuff is drawn here
147                 if(f.solidness != 0)
148                         continue;
149                 
150                 switch(f.drawtype){
151                 default:
152                         infostream<<"Got "<<f.drawtype<<std::endl;
153                         assert(0);
154                         break;
155                 case NDT_AIRLIKE:
156                         break;
157                 case NDT_LIQUID:
158                 {
159                         /*
160                                 Add water sources to mesh if using new style
161                         */
162                         TileSpec tile_liquid = f.special_tiles[0];
163                         AtlasPointer &pa_liquid = tile_liquid.texture;
164
165                         bool top_is_air = false;
166                         MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
167                         if(n.getContent() == CONTENT_AIR)
168                                 top_is_air = true;
169                         
170                         if(top_is_air == false)
171                                 continue;
172
173                         u16 l = getInteriorLight(n, 0, data);
174                         video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
175                         
176                         video::S3DVertex vertices[4] =
177                         {
178                                 video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
179                                                 pa_liquid.x0(), pa_liquid.y1()),
180                                 video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
181                                                 pa_liquid.x1(), pa_liquid.y1()),
182                                 video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
183                                                 pa_liquid.x1(), pa_liquid.y0()),
184                                 video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
185                                                 pa_liquid.x0(), pa_liquid.y0()),
186                         };
187
188                         v3f offset(p.X, p.Y + (-0.5+node_liquid_level)*BS, p.Z);
189                         for(s32 i=0; i<4; i++)
190                         {
191                                 vertices[i].Pos += offset;
192                         }
193
194                         u16 indices[] = {0,1,2,2,3,0};
195                         // Add to mesh collector
196                         collector.append(tile_liquid, vertices, 4, indices, 6);
197                 break;}
198                 case NDT_FLOWINGLIQUID:
199                 {
200                         /*
201                                 Add flowing liquid to mesh
202                         */
203                         TileSpec tile_liquid = f.special_tiles[0];
204                         TileSpec tile_liquid_bfculled = f.special_tiles[1];
205                         AtlasPointer &pa_liquid = tile_liquid.texture;
206
207                         bool top_is_same_liquid = false;
208                         MapNode ntop = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y+1,z));
209                         content_t c_flowing = nodedef->getId(f.liquid_alternative_flowing);
210                         content_t c_source = nodedef->getId(f.liquid_alternative_source);
211                         if(ntop.getContent() == c_flowing || ntop.getContent() == c_source)
212                                 top_is_same_liquid = true;
213                         
214                         u16 l = 0;
215                         // If this liquid emits light and doesn't contain light, draw
216                         // it at what it emits, for an increased effect
217                         u8 light_source = nodedef->get(n).light_source;
218                         if(light_source != 0){
219                                 //l = decode_light(undiminish_light(light_source));
220                                 l = decode_light(light_source);
221                                 l = l | (l<<8);
222                         }
223                         // Use the light of the node on top if possible
224                         else if(nodedef->get(ntop).param_type == CPT_LIGHT)
225                                 l = getInteriorLight(ntop, 0, data);
226                         // Otherwise use the light of this node (the liquid)
227                         else
228                                 l = getInteriorLight(n, 0, data);
229                         video::SColor c = MapBlock_LightColor(f.alpha, l, decode_light(f.light_source));
230                         
231                         // Neighbor liquid levels (key = relative position)
232                         // Includes current node
233                         std::map<v3s16, f32> neighbor_levels;
234                         std::map<v3s16, content_t> neighbor_contents;
235                         std::map<v3s16, u8> neighbor_flags;
236                         const u8 neighborflag_top_is_same_liquid = 0x01;
237                         v3s16 neighbor_dirs[9] = {
238                                 v3s16(0,0,0),
239                                 v3s16(0,0,1),
240                                 v3s16(0,0,-1),
241                                 v3s16(1,0,0),
242                                 v3s16(-1,0,0),
243                                 v3s16(1,0,1),
244                                 v3s16(-1,0,-1),
245                                 v3s16(1,0,-1),
246                                 v3s16(-1,0,1),
247                         };
248                         for(u32 i=0; i<9; i++)
249                         {
250                                 content_t content = CONTENT_AIR;
251                                 float level = -0.5 * BS;
252                                 u8 flags = 0;
253                                 // Check neighbor
254                                 v3s16 p2 = p + neighbor_dirs[i];
255                                 MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
256                                 if(n2.getContent() != CONTENT_IGNORE)
257                                 {
258                                         content = n2.getContent();
259
260                                         if(n2.getContent() == c_source)
261                                                 level = (-0.5+node_liquid_level) * BS;
262                                         else if(n2.getContent() == c_flowing)
263                                                 level = (-0.5 + ((float)(n2.param2&LIQUID_LEVEL_MASK)
264                                                                 + 0.5) / (float)LIQUID_LEVEL_SOURCE * node_liquid_level) * BS;
265
266                                         // Check node above neighbor.
267                                         // NOTE: This doesn't get executed if neighbor
268                                         //       doesn't exist
269                                         p2.Y += 1;
270                                         n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
271                                         if(n2.getContent() == c_source ||
272                                                         n2.getContent() == c_flowing)
273                                                 flags |= neighborflag_top_is_same_liquid;
274                                 }
275                                 
276                                 neighbor_levels[neighbor_dirs[i]] = level;
277                                 neighbor_contents[neighbor_dirs[i]] = content;
278                                 neighbor_flags[neighbor_dirs[i]] = flags;
279                         }
280
281                         // Corner heights (average between four liquids)
282                         f32 corner_levels[4];
283                         
284                         v3s16 halfdirs[4] = {
285                                 v3s16(0,0,0),
286                                 v3s16(1,0,0),
287                                 v3s16(1,0,1),
288                                 v3s16(0,0,1),
289                         };
290                         for(u32 i=0; i<4; i++)
291                         {
292                                 v3s16 cornerdir = halfdirs[i];
293                                 float cornerlevel = 0;
294                                 u32 valid_count = 0;
295                                 u32 air_count = 0;
296                                 for(u32 j=0; j<4; j++)
297                                 {
298                                         v3s16 neighbordir = cornerdir - halfdirs[j];
299                                         content_t content = neighbor_contents[neighbordir];
300                                         // If top is liquid, draw starting from top of node
301                                         if(neighbor_flags[neighbordir] &
302                                                         neighborflag_top_is_same_liquid)
303                                         {
304                                                 cornerlevel = 0.5*BS;
305                                                 valid_count = 1;
306                                                 break;
307                                         }
308                                         // Source is always the same height
309                                         else if(content == c_source)
310                                         {
311                                                 cornerlevel = (-0.5+node_liquid_level)*BS;
312                                                 valid_count = 1;
313                                                 break;
314                                         }
315                                         // Flowing liquid has level information
316                                         else if(content == c_flowing)
317                                         {
318                                                 cornerlevel += neighbor_levels[neighbordir];
319                                                 valid_count++;
320                                         }
321                                         else if(content == CONTENT_AIR)
322                                         {
323                                                 air_count++;
324                                         }
325                                 }
326                                 if(air_count >= 2)
327                                         cornerlevel = -0.5*BS+0.1;
328                                 else if(valid_count > 0)
329                                         cornerlevel /= valid_count;
330                                 corner_levels[i] = cornerlevel;
331                         }
332
333                         /*
334                                 Generate sides
335                         */
336
337                         v3s16 side_dirs[4] = {
338                                 v3s16(1,0,0),
339                                 v3s16(-1,0,0),
340                                 v3s16(0,0,1),
341                                 v3s16(0,0,-1),
342                         };
343                         s16 side_corners[4][2] = {
344                                 {1, 2},
345                                 {3, 0},
346                                 {2, 3},
347                                 {0, 1},
348                         };
349                         for(u32 i=0; i<4; i++)
350                         {
351                                 v3s16 dir = side_dirs[i];
352
353                                 /*
354                                         If our topside is liquid and neighbor's topside
355                                         is liquid, don't draw side face
356                                 */
357                                 if(top_is_same_liquid &&
358                                                 neighbor_flags[dir] & neighborflag_top_is_same_liquid)
359                                         continue;
360
361                                 content_t neighbor_content = neighbor_contents[dir];
362                                 const ContentFeatures &n_feat = nodedef->get(neighbor_content);
363                                 
364                                 // Don't draw face if neighbor is blocking the view
365                                 if(n_feat.solidness == 2)
366                                         continue;
367                                 
368                                 bool neighbor_is_same_liquid = (neighbor_content == c_source
369                                                 || neighbor_content == c_flowing);
370                                 
371                                 // Don't draw any faces if neighbor same is liquid and top is
372                                 // same liquid
373                                 if(neighbor_is_same_liquid == true
374                                                 && top_is_same_liquid == false)
375                                         continue;
376
377                                 // Use backface culled material if neighbor doesn't have a
378                                 // solidness of 0
379                                 const TileSpec *current_tile = &tile_liquid;
380                                 if(n_feat.solidness != 0 || n_feat.visual_solidness != 0)
381                                         current_tile = &tile_liquid_bfculled;
382                                 
383                                 video::S3DVertex vertices[4] =
384                                 {
385                                         video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
386                                                         pa_liquid.x0(), pa_liquid.y1()),
387                                         video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
388                                                         pa_liquid.x1(), pa_liquid.y1()),
389                                         video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
390                                                         pa_liquid.x1(), pa_liquid.y0()),
391                                         video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
392                                                         pa_liquid.x0(), pa_liquid.y0()),
393                                 };
394                                 
395                                 /*
396                                         If our topside is liquid, set upper border of face
397                                         at upper border of node
398                                 */
399                                 if(top_is_same_liquid)
400                                 {
401                                         vertices[2].Pos.Y = 0.5*BS;
402                                         vertices[3].Pos.Y = 0.5*BS;
403                                 }
404                                 /*
405                                         Otherwise upper position of face is corner levels
406                                 */
407                                 else
408                                 {
409                                         vertices[2].Pos.Y = corner_levels[side_corners[i][0]];
410                                         vertices[3].Pos.Y = corner_levels[side_corners[i][1]];
411                                 }
412                                 
413                                 /*
414                                         If neighbor is liquid, lower border of face is corner
415                                         liquid levels
416                                 */
417                                 if(neighbor_is_same_liquid)
418                                 {
419                                         vertices[0].Pos.Y = corner_levels[side_corners[i][1]];
420                                         vertices[1].Pos.Y = corner_levels[side_corners[i][0]];
421                                 }
422                                 /*
423                                         If neighbor is not liquid, lower border of face is
424                                         lower border of node
425                                 */
426                                 else
427                                 {
428                                         vertices[0].Pos.Y = -0.5*BS;
429                                         vertices[1].Pos.Y = -0.5*BS;
430                                 }
431                                 
432                                 for(s32 j=0; j<4; j++)
433                                 {
434                                         if(dir == v3s16(0,0,1))
435                                                 vertices[j].Pos.rotateXZBy(0);
436                                         if(dir == v3s16(0,0,-1))
437                                                 vertices[j].Pos.rotateXZBy(180);
438                                         if(dir == v3s16(-1,0,0))
439                                                 vertices[j].Pos.rotateXZBy(90);
440                                         if(dir == v3s16(1,0,-0))
441                                                 vertices[j].Pos.rotateXZBy(-90);
442                                                 
443                                         // Do this to not cause glitches when two liquids are
444                                         // side-by-side
445                                         /*if(neighbor_is_same_liquid == false){
446                                                 vertices[j].Pos.X *= 0.98;
447                                                 vertices[j].Pos.Z *= 0.98;
448                                         }*/
449
450                                         vertices[j].Pos += intToFloat(p, BS);
451                                 }
452
453                                 u16 indices[] = {0,1,2,2,3,0};
454                                 // Add to mesh collector
455                                 collector.append(*current_tile, vertices, 4, indices, 6);
456                         }
457                         
458                         /*
459                                 Generate top side, if appropriate
460                         */
461                         
462                         if(top_is_same_liquid == false)
463                         {
464                                 video::S3DVertex vertices[4] =
465                                 {
466                                         video::S3DVertex(-BS/2,0,BS/2, 0,0,0, c,
467                                                         pa_liquid.x0(), pa_liquid.y1()),
468                                         video::S3DVertex(BS/2,0,BS/2, 0,0,0, c,
469                                                         pa_liquid.x1(), pa_liquid.y1()),
470                                         video::S3DVertex(BS/2,0,-BS/2, 0,0,0, c,
471                                                         pa_liquid.x1(), pa_liquid.y0()),
472                                         video::S3DVertex(-BS/2,0,-BS/2, 0,0,0, c,
473                                                         pa_liquid.x0(), pa_liquid.y0()),
474                                 };
475                                 
476                                 // To get backface culling right, the vertices need to go
477                                 // clockwise around the front of the face. And we happened to
478                                 // calculate corner levels in exact reverse order.
479                                 s32 corner_resolve[4] = {3,2,1,0};
480
481                                 for(s32 i=0; i<4; i++)
482                                 {
483                                         //vertices[i].Pos.Y += liquid_level;
484                                         //vertices[i].Pos.Y += neighbor_levels[v3s16(0,0,0)];
485                                         s32 j = corner_resolve[i];
486                                         vertices[i].Pos.Y += corner_levels[j];
487                                         vertices[i].Pos += intToFloat(p, BS);
488                                 }
489                                 
490                                 // Default downwards-flowing texture animation goes from 
491                                 // -Z towards +Z, thus the direction is +Z.
492                                 // Rotate texture to make animation go in flow direction
493                                 // Positive if liquid moves towards +Z
494                                 int dz = (corner_levels[side_corners[3][0]] +
495                                                 corner_levels[side_corners[3][1]]) -
496                                                 (corner_levels[side_corners[2][0]] +
497                                                 corner_levels[side_corners[2][1]]);
498                                 // Positive if liquid moves towards +X
499                                 int dx = (corner_levels[side_corners[1][0]] +
500                                                 corner_levels[side_corners[1][1]]) -
501                                                 (corner_levels[side_corners[0][0]] +
502                                                 corner_levels[side_corners[0][1]]);
503                                 // -X
504                                 if(-dx >= abs(dz))
505                                 {
506                                         v2f t = vertices[0].TCoords;
507                                         vertices[0].TCoords = vertices[1].TCoords;
508                                         vertices[1].TCoords = vertices[2].TCoords;
509                                         vertices[2].TCoords = vertices[3].TCoords;
510                                         vertices[3].TCoords = t;
511                                 }
512                                 // +X
513                                 if(dx >= abs(dz))
514                                 {
515                                         v2f t = vertices[0].TCoords;
516                                         vertices[0].TCoords = vertices[3].TCoords;
517                                         vertices[3].TCoords = vertices[2].TCoords;
518                                         vertices[2].TCoords = vertices[1].TCoords;
519                                         vertices[1].TCoords = t;
520                                 }
521                                 // -Z
522                                 if(-dz >= abs(dx))
523                                 {
524                                         v2f t = vertices[0].TCoords;
525                                         vertices[0].TCoords = vertices[3].TCoords;
526                                         vertices[3].TCoords = vertices[2].TCoords;
527                                         vertices[2].TCoords = vertices[1].TCoords;
528                                         vertices[1].TCoords = t;
529                                         t = vertices[0].TCoords;
530                                         vertices[0].TCoords = vertices[3].TCoords;
531                                         vertices[3].TCoords = vertices[2].TCoords;
532                                         vertices[2].TCoords = vertices[1].TCoords;
533                                         vertices[1].TCoords = t;
534                                 }
535
536                                 u16 indices[] = {0,1,2,2,3,0};
537                                 // Add to mesh collector
538                                 collector.append(tile_liquid, vertices, 4, indices, 6);
539                         }
540                 break;}
541                 case NDT_GLASSLIKE:
542                 {
543                         TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
544                         AtlasPointer ap = tile.texture;
545
546                         u16 l = getInteriorLight(n, 1, data);
547                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
548
549                         for(u32 j=0; j<6; j++)
550                         {
551                                 // Check this neighbor
552                                 v3s16 n2p = blockpos_nodes + p + g_6dirs[j];
553                                 MapNode n2 = data->m_vmanip.getNodeNoEx(n2p);
554                                 // Don't make face if neighbor is of same type
555                                 if(n2.getContent() == n.getContent())
556                                         continue;
557
558                                 // The face at Z+
559                                 video::S3DVertex vertices[4] =
560                                 {
561                                         video::S3DVertex(-BS/2,-BS/2,BS/2, 0,0,0, c,
562                                                 ap.x0(), ap.y1()),
563                                         video::S3DVertex(BS/2,-BS/2,BS/2, 0,0,0, c,
564                                                 ap.x1(), ap.y1()),
565                                         video::S3DVertex(BS/2,BS/2,BS/2, 0,0,0, c,
566                                                 ap.x1(), ap.y0()),
567                                         video::S3DVertex(-BS/2,BS/2,BS/2, 0,0,0, c,
568                                                 ap.x0(), ap.y0()),
569                                 };
570                                 
571                                 // Rotations in the g_6dirs format
572                                 if(j == 0) // Z+
573                                         for(u16 i=0; i<4; i++)
574                                                 vertices[i].Pos.rotateXZBy(0);
575                                 else if(j == 1) // Y+
576                                         for(u16 i=0; i<4; i++)
577                                                 vertices[i].Pos.rotateYZBy(-90);
578                                 else if(j == 2) // X+
579                                         for(u16 i=0; i<4; i++)
580                                                 vertices[i].Pos.rotateXZBy(-90);
581                                 else if(j == 3) // Z-
582                                         for(u16 i=0; i<4; i++)
583                                                 vertices[i].Pos.rotateXZBy(180);
584                                 else if(j == 4) // Y-
585                                         for(u16 i=0; i<4; i++)
586                                                 vertices[i].Pos.rotateYZBy(90);
587                                 else if(j == 5) // X-
588                                         for(u16 i=0; i<4; i++)
589                                                 vertices[i].Pos.rotateXZBy(90);
590
591                                 for(u16 i=0; i<4; i++){
592                                         vertices[i].Pos += intToFloat(p, BS);
593                                 }
594
595                                 u16 indices[] = {0,1,2,2,3,0};
596                                 // Add to mesh collector
597                                 collector.append(tile, vertices, 4, indices, 6);
598                         }
599                 break;}
600                 case NDT_ALLFACES:
601                 {
602                         TileSpec tile_leaves = getNodeTile(n, p,
603                                         v3s16(0,0,0), data);
604                         AtlasPointer pa_leaves = tile_leaves.texture;
605
606                         u16 l = getInteriorLight(n, 1, data);
607                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
608
609                         v3f pos = intToFloat(p, BS);
610                         aabb3f box(-BS/2,-BS/2,-BS/2,BS/2,BS/2,BS/2);
611                         box.MinEdge += pos;
612                         box.MaxEdge += pos;
613                         makeCuboid(&collector, box, &tile_leaves, 1, c, NULL);
614                 break;}
615                 case NDT_ALLFACES_OPTIONAL:
616                         // This is always pre-converted to something else
617                         assert(0);
618                         break;
619                 case NDT_TORCHLIKE:
620                 {
621                         v3s16 dir = n.getWallMountedDir(nodedef);
622                         
623                         u8 tileindex = 0;
624                         if(dir == v3s16(0,-1,0)){
625                                 tileindex = 0; // floor
626                         } else if(dir == v3s16(0,1,0)){
627                                 tileindex = 1; // ceiling
628                         // For backwards compatibility
629                         } else if(dir == v3s16(0,0,0)){
630                                 tileindex = 0; // floor
631                         } else {
632                                 tileindex = 2; // side
633                         }
634
635                         TileSpec tile = getNodeTileN(n, p, tileindex, data);
636                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
637                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
638
639                         AtlasPointer ap = tile.texture;
640
641                         u16 l = getInteriorLight(n, 1, data);
642                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
643
644                         // Wall at X+ of node
645                         video::S3DVertex vertices[4] =
646                         {
647                                 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c,
648                                                 ap.x0(), ap.y1()),
649                                 video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c,
650                                                 ap.x1(), ap.y1()),
651                                 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c,
652                                                 ap.x1(), ap.y0()),
653                                 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c,
654                                                 ap.x0(), ap.y0()),
655                         };
656
657                         for(s32 i=0; i<4; i++)
658                         {
659                                 if(dir == v3s16(1,0,0))
660                                         vertices[i].Pos.rotateXZBy(0);
661                                 if(dir == v3s16(-1,0,0))
662                                         vertices[i].Pos.rotateXZBy(180);
663                                 if(dir == v3s16(0,0,1))
664                                         vertices[i].Pos.rotateXZBy(90);
665                                 if(dir == v3s16(0,0,-1))
666                                         vertices[i].Pos.rotateXZBy(-90);
667                                 if(dir == v3s16(0,-1,0))
668                                         vertices[i].Pos.rotateXZBy(45);
669                                 if(dir == v3s16(0,1,0))
670                                         vertices[i].Pos.rotateXZBy(-45);
671
672                                 vertices[i].Pos += intToFloat(p, BS);
673                         }
674
675                         u16 indices[] = {0,1,2,2,3,0};
676                         // Add to mesh collector
677                         collector.append(tile, vertices, 4, indices, 6);
678                 break;}
679                 case NDT_SIGNLIKE:
680                 {
681                         TileSpec tile = getNodeTileN(n, p, 0, data);
682                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
683                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
684                         AtlasPointer ap = tile.texture;
685
686                         u16 l = getInteriorLight(n, 0, data);
687                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
688                                 
689                         float d = (float)BS/16;
690                         // Wall at X+ of node
691                         video::S3DVertex vertices[4] =
692                         {
693                                 video::S3DVertex(BS/2-d,BS/2,BS/2, 0,0,0, c,
694                                                 ap.x0(), ap.y0()),
695                                 video::S3DVertex(BS/2-d,BS/2,-BS/2, 0,0,0, c,
696                                                 ap.x1(), ap.y0()),
697                                 video::S3DVertex(BS/2-d,-BS/2,-BS/2, 0,0,0, c,
698                                                 ap.x1(), ap.y1()),
699                                 video::S3DVertex(BS/2-d,-BS/2,BS/2, 0,0,0, c,
700                                                 ap.x0(), ap.y1()),
701                         };
702
703                         v3s16 dir = n.getWallMountedDir(nodedef);
704
705                         for(s32 i=0; i<4; i++)
706                         {
707                                 if(dir == v3s16(1,0,0))
708                                         vertices[i].Pos.rotateXZBy(0);
709                                 if(dir == v3s16(-1,0,0))
710                                         vertices[i].Pos.rotateXZBy(180);
711                                 if(dir == v3s16(0,0,1))
712                                         vertices[i].Pos.rotateXZBy(90);
713                                 if(dir == v3s16(0,0,-1))
714                                         vertices[i].Pos.rotateXZBy(-90);
715                                 if(dir == v3s16(0,-1,0))
716                                         vertices[i].Pos.rotateXYBy(-90);
717                                 if(dir == v3s16(0,1,0))
718                                         vertices[i].Pos.rotateXYBy(90);
719
720                                 vertices[i].Pos += intToFloat(p, BS);
721                         }
722
723                         u16 indices[] = {0,1,2,2,3,0};
724                         // Add to mesh collector
725                         collector.append(tile, vertices, 4, indices, 6);
726                 break;}
727                 case NDT_PLANTLIKE:
728                 {
729                         TileSpec tile = getNodeTileN(n, p, 0, data);
730                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
731                         AtlasPointer ap = tile.texture;
732                         
733                         u16 l = getInteriorLight(n, 1, data);
734                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
735
736                         for(u32 j=0; j<2; j++)
737                         {
738                                 video::S3DVertex vertices[4] =
739                                 {
740                                         video::S3DVertex(-BS/2*f.visual_scale,-BS/2,0, 0,0,0, c,
741                                                 ap.x0(), ap.y1()),
742                                         video::S3DVertex( BS/2*f.visual_scale,-BS/2,0, 0,0,0, c,
743                                                 ap.x1(), ap.y1()),
744                                         video::S3DVertex( BS/2*f.visual_scale,
745                                                 -BS/2 + f.visual_scale*BS,0, 0,0,0, c,
746                                                 ap.x1(), ap.y0()),
747                                         video::S3DVertex(-BS/2*f.visual_scale,
748                                                 -BS/2 + f.visual_scale*BS,0, 0,0,0, c,
749                                                 ap.x0(), ap.y0()),
750                                 };
751
752                                 if(j == 0)
753                                 {
754                                         for(u16 i=0; i<4; i++)
755                                                 vertices[i].Pos.rotateXZBy(45);
756                                 }
757                                 else if(j == 1)
758                                 {
759                                         for(u16 i=0; i<4; i++)
760                                                 vertices[i].Pos.rotateXZBy(-45);
761                                 }
762
763                                 for(u16 i=0; i<4; i++)
764                                 {
765                                         vertices[i].Pos *= f.visual_scale;
766                                         vertices[i].Pos += intToFloat(p, BS);
767                                 }
768
769                                 u16 indices[] = {0,1,2,2,3,0};
770                                 // Add to mesh collector
771                                 collector.append(tile, vertices, 4, indices, 6);
772                         }
773                 break;}
774                 case NDT_FENCELIKE:
775                 {
776                         TileSpec tile = getNodeTile(n, p, v3s16(0,0,0), data);
777                         TileSpec tile_nocrack = tile;
778                         tile_nocrack.material_flags &= ~MATERIAL_FLAG_CRACK;
779                         
780                         // A hack to put wood the right way around in the posts
781                         ITextureSource *tsrc = data->m_gamedef->tsrc();
782                         TileSpec tile_rot = tile;
783                         tile_rot.texture = tsrc->getTexture(tsrc->getTextureName(
784                                         tile.texture.id) + "^[transformR90");
785                                         
786                         u16 l = getInteriorLight(n, 1, data);
787                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
788
789                         const f32 post_rad=(f32)BS/8;
790                         const f32 bar_rad=(f32)BS/16;
791                         const f32 bar_len=(f32)(BS/2)-post_rad;
792
793                         v3f pos = intToFloat(p, BS);
794
795                         // The post - always present
796                         aabb3f post(-post_rad,-BS/2,-post_rad,post_rad,BS/2,post_rad);
797                         post.MinEdge += pos;
798                         post.MaxEdge += pos;
799                         f32 postuv[24]={
800                                         6/16.,6/16.,10/16.,10/16.,
801                                         6/16.,6/16.,10/16.,10/16.,
802                                         0/16.,0,4/16.,1,
803                                         4/16.,0,8/16.,1,
804                                         8/16.,0,12/16.,1,
805                                         12/16.,0,16/16.,1};
806                         makeCuboid(&collector, post, &tile_rot, 1, c, postuv);
807
808                         // Now a section of fence, +X, if there's a post there
809                         v3s16 p2 = p;
810                         p2.X++;
811                         MapNode n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
812                         const ContentFeatures *f2 = &nodedef->get(n2);
813                         if(f2->drawtype == NDT_FENCELIKE)
814                         {
815                                 aabb3f bar(-bar_len+BS/2,-bar_rad+BS/4,-bar_rad,
816                                                 bar_len+BS/2,bar_rad+BS/4,bar_rad);
817                                 bar.MinEdge += pos;
818                                 bar.MaxEdge += pos;
819                                 f32 xrailuv[24]={
820                                         0/16.,2/16.,16/16.,4/16.,
821                                         0/16.,4/16.,16/16.,6/16.,
822                                         6/16.,6/16.,8/16.,8/16.,
823                                         10/16.,10/16.,12/16.,12/16.,
824                                         0/16.,8/16.,16/16.,10/16.,
825                                         0/16.,14/16.,16/16.,16/16.};
826                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
827                                                 c, xrailuv);
828                                 bar.MinEdge.Y -= BS/2;
829                                 bar.MaxEdge.Y -= BS/2;
830                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
831                                                 c, xrailuv);
832                         }
833
834                         // Now a section of fence, +Z, if there's a post there
835                         p2 = p;
836                         p2.Z++;
837                         n2 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p2);
838                         f2 = &nodedef->get(n2);
839                         if(f2->drawtype == NDT_FENCELIKE)
840                         {
841                                 aabb3f bar(-bar_rad,-bar_rad+BS/4,-bar_len+BS/2,
842                                                 bar_rad,bar_rad+BS/4,bar_len+BS/2);
843                                 bar.MinEdge += pos;
844                                 bar.MaxEdge += pos;
845                                 f32 zrailuv[24]={
846                                         3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
847                                         4/16.,1/16.,6/16.,5/16., // for wood texture instead
848                                         0/16.,9/16.,16/16.,11/16.,
849                                         0/16.,6/16.,16/16.,8/16.,
850                                         6/16.,6/16.,8/16.,8/16.,
851                                         10/16.,10/16.,12/16.,12/16.};
852                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
853                                                 c, zrailuv);
854                                 bar.MinEdge.Y -= BS/2;
855                                 bar.MaxEdge.Y -= BS/2;
856                                 makeCuboid(&collector, bar, &tile_nocrack, 1,
857                                                 c, zrailuv);
858                         }
859                 break;}
860                 case NDT_RAILLIKE:
861                 {
862                         bool is_rail_x [] = { false, false };  /* x-1, x+1 */
863                         bool is_rail_z [] = { false, false };  /* z-1, z+1 */
864
865                         bool is_rail_z_minus_y [] = { false, false };  /* z-1, z+1; y-1 */
866                         bool is_rail_x_minus_y [] = { false, false };  /* x-1, z+1; y-1 */
867                         bool is_rail_z_plus_y [] = { false, false };  /* z-1, z+1; y+1 */
868                         bool is_rail_x_plus_y [] = { false, false };  /* x-1, x+1; y+1 */
869
870                         MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
871                         MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
872                         MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
873                         MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
874                         MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
875                         MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
876                         MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
877                         MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
878                         MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
879                         MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
880                         MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
881                         MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
882                         
883                         content_t thiscontent = n.getContent();
884                         if(n_minus_x.getContent() == thiscontent)
885                                 is_rail_x[0] = true;
886                         if (n_minus_x_minus_y.getContent() == thiscontent)
887                                 is_rail_x_minus_y[0] = true;
888                         if(n_minus_x_plus_y.getContent() == thiscontent)
889                                 is_rail_x_plus_y[0] = true;
890
891                         if(n_plus_x.getContent() == thiscontent)
892                                 is_rail_x[1] = true;
893                         if (n_plus_x_minus_y.getContent() == thiscontent)
894                                 is_rail_x_minus_y[1] = true;
895                         if(n_plus_x_plus_y.getContent() == thiscontent)
896                                 is_rail_x_plus_y[1] = true;
897
898                         if(n_minus_z.getContent() == thiscontent)
899                                 is_rail_z[0] = true;
900                         if (n_minus_z_minus_y.getContent() == thiscontent)
901                                 is_rail_z_minus_y[0] = true;
902                         if(n_minus_z_plus_y.getContent() == thiscontent)
903                                 is_rail_z_plus_y[0] = true;
904
905                         if(n_plus_z.getContent() == thiscontent)
906                                 is_rail_z[1] = true;
907                         if (n_plus_z_minus_y.getContent() == thiscontent)
908                                 is_rail_z_minus_y[1] = true;
909                         if(n_plus_z_plus_y.getContent() == thiscontent)
910                                 is_rail_z_plus_y[1] = true;
911
912                         bool is_rail_x_all[] = {false, false};
913                         bool is_rail_z_all[] = {false, false};
914                         is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
915                         is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
916                         is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
917                         is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
918
919                         // reasonable default, flat straight unrotated rail
920                         bool is_straight = true;
921                         int adjacencies = 0;
922                         int angle = 0;
923                         u8 tileindex = 0;
924
925                         // check for sloped rail
926                         if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
927                         {
928                                 adjacencies = 5; //5 means sloped
929                                 is_straight = true; // sloped is always straight
930                         }
931                         else
932                         {
933                                 // is really straight, rails on both sides
934                                 is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
935                                 adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
936                         }
937
938                         switch (adjacencies) {
939                         case 1:
940                                 if(is_rail_x_all[0] || is_rail_x_all[1])
941                                         angle = 90;
942                                 break;
943                         case 2:
944                                 if(!is_straight)
945                                         tileindex = 1; // curved
946                                 if(is_rail_x_all[0] && is_rail_x_all[1])
947                                         angle = 90;
948                                 if(is_rail_z_all[0] && is_rail_z_all[1]){
949                                         if (n_minus_z_plus_y.getContent() == thiscontent) angle = 180;
950                                 }
951                                 else if(is_rail_x_all[0] && is_rail_z_all[0])
952                                         angle = 270;
953                                 else if(is_rail_x_all[0] && is_rail_z_all[1])
954                                         angle = 180;
955                                 else if(is_rail_x_all[1] && is_rail_z_all[1])
956                                         angle = 90;
957                                 break;
958                         case 3:
959                                 // here is where the potential to 'switch' a junction is, but not implemented at present
960                                 tileindex = 2; // t-junction
961                                 if(!is_rail_x_all[1])
962                                         angle=180;
963                                 if(!is_rail_z_all[0])
964                                         angle=90;
965                                 if(!is_rail_z_all[1])
966                                         angle=270;
967                                 break;
968                         case 4:
969                                 tileindex = 3; // crossing
970                                 break;
971                         case 5: //sloped
972                                 if(is_rail_z_plus_y[0])
973                                         angle = 180;
974                                 if(is_rail_x_plus_y[0])
975                                         angle = 90;
976                                 if(is_rail_x_plus_y[1])
977                                         angle = -90;
978                                 break;
979                         default:
980                                 break;
981                         }
982
983                         TileSpec tile = getNodeTileN(n, p, tileindex, data);
984                         tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
985                         tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
986
987                         AtlasPointer ap = tile.texture;
988                         
989                         u16 l = getInteriorLight(n, 0, data);
990                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
991
992                         float d = (float)BS/64;
993                         
994                         char g=-1;
995                         if (is_rail_x_plus_y[0] || is_rail_x_plus_y[1] || is_rail_z_plus_y[0] || is_rail_z_plus_y[1])
996                                 g=1; //Object is at a slope
997
998                         video::S3DVertex vertices[4] =
999                         {
1000                                         video::S3DVertex(-BS/2,-BS/2+d,-BS/2, 0,0,0, c,
1001                                                         ap.x0(), ap.y1()),
1002                                         video::S3DVertex(BS/2,-BS/2+d,-BS/2, 0,0,0, c,
1003                                                         ap.x1(), ap.y1()),
1004                                         video::S3DVertex(BS/2,g*BS/2+d,BS/2, 0,0,0, c,
1005                                                         ap.x1(), ap.y0()),
1006                                         video::S3DVertex(-BS/2,g*BS/2+d,BS/2, 0,0,0, c,
1007                                                         ap.x0(), ap.y0()),
1008                         };
1009
1010                         for(s32 i=0; i<4; i++)
1011                         {
1012                                 if(angle != 0)
1013                                         vertices[i].Pos.rotateXZBy(angle);
1014                                 vertices[i].Pos += intToFloat(p, BS);
1015                         }
1016
1017                         u16 indices[] = {0,1,2,2,3,0};
1018                         collector.append(tile, vertices, 4, indices, 6);
1019                 break;}
1020                 case NDT_NODEBOX:
1021                 {
1022                         static const v3s16 tile_dirs[6] = {
1023                                 v3s16(0, 1, 0),
1024                                 v3s16(0, -1, 0),
1025                                 v3s16(1, 0, 0),
1026                                 v3s16(-1, 0, 0),
1027                                 v3s16(0, 0, 1),
1028                                 v3s16(0, 0, -1)
1029                         };
1030
1031                         TileSpec tiles[6];
1032                         for(int i = 0; i < 6; i++)
1033                         {
1034                                 // Handles facedir rotation for textures
1035                                 tiles[i] = getNodeTile(n, p, tile_dirs[i], data);
1036                         }
1037
1038                         u16 l = getInteriorLight(n, 0, data);
1039                         video::SColor c = MapBlock_LightColor(255, l, decode_light(f.light_source));
1040
1041                         v3f pos = intToFloat(p, BS);
1042
1043                         std::vector<aabb3f> boxes = n.getNodeBoxes(nodedef);
1044                         for(std::vector<aabb3f>::iterator
1045                                         i = boxes.begin();
1046                                         i != boxes.end(); i++)
1047                         {
1048                                 aabb3f box = *i;
1049                                 box.MinEdge += pos;
1050                                 box.MaxEdge += pos;
1051
1052                                 // Compute texture coords
1053                                 f32 tx1 = (i->MinEdge.X/BS)+0.5;
1054                                 f32 ty1 = (i->MinEdge.Y/BS)+0.5;
1055                                 f32 tz1 = (i->MinEdge.Z/BS)+0.5;
1056                                 f32 tx2 = (i->MaxEdge.X/BS)+0.5;
1057                                 f32 ty2 = (i->MaxEdge.Y/BS)+0.5;
1058                                 f32 tz2 = (i->MaxEdge.Z/BS)+0.5;
1059                                 f32 txc[24] = {
1060                                         // up
1061                                         tx1, 1-tz2, tx2, 1-tz1,
1062                                         // down
1063                                         tx1, tz1, tx2, tz2,
1064                                         // right
1065                                         tz1, 1-ty2, tz2, 1-ty1,
1066                                         // left
1067                                         1-tz2, 1-ty2, 1-tz1, 1-ty1,
1068                                         // back
1069                                         1-tx2, 1-ty2, 1-tx1, 1-ty1,
1070                                         // front
1071                                         tx1, 1-ty2, tx2, 1-ty1,
1072                                 };
1073
1074                                 makeCuboid(&collector, box, tiles, 6, c, txc);
1075                         }
1076                 break;}
1077                 }
1078         }
1079 }
1080