+ 3/16.,1/16.,5/16.,5/16., // cannot rotate; stretch
+ 4/16.,1/16.,6/16.,5/16., // for wood texture instead
+ 0/16.,9/16.,16/16.,11/16.,
+ 0/16.,6/16.,16/16.,8/16.,
+ 6/16.,6/16.,8/16.,8/16.,
+ 10/16.,10/16.,12/16.,12/16.};
+ makeCuboid(&collector, bar, &tile_nocrack, 1,
+ c, zrailuv);
+ bar.MinEdge.Y -= BS/2;
+ bar.MaxEdge.Y -= BS/2;
+ makeCuboid(&collector, bar, &tile_nocrack, 1,
+ c, zrailuv);
+ }
+ break;}
+ case NDT_RAILLIKE:
+ {
+ bool is_rail_x [] = { false, false }; /* x-1, x+1 */
+ bool is_rail_z [] = { false, false }; /* z-1, z+1 */
+
+ bool is_rail_z_minus_y [] = { false, false }; /* z-1, z+1; y-1 */
+ bool is_rail_x_minus_y [] = { false, false }; /* x-1, z+1; y-1 */
+ bool is_rail_z_plus_y [] = { false, false }; /* z-1, z+1; y+1 */
+ bool is_rail_x_plus_y [] = { false, false }; /* x-1, x+1; y+1 */
+
+ MapNode n_minus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1,y,z));
+ MapNode n_plus_x = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1,y,z));
+ MapNode n_minus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z-1));
+ MapNode n_plus_z = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x,y,z+1));
+ MapNode n_plus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y+1, z));
+ MapNode n_plus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x+1, y-1, z));
+ MapNode n_minus_x_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y+1, z));
+ MapNode n_minus_x_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x-1, y-1, z));
+ MapNode n_plus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z+1));
+ MapNode n_minus_z_plus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y+1, z-1));
+ MapNode n_plus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z+1));
+ MapNode n_minus_z_minus_y = data->m_vmanip.getNodeNoEx(blockpos_nodes + v3s16(x, y-1, z-1));
+
+ content_t thiscontent = n.getContent();
+ std::string groupname = "connect_to_raillike"; // name of the group that enables connecting to raillike nodes of different kind
+ bool self_connect_to_raillike = ((ItemGroupList) nodedef->get(n).groups)[groupname] != 0;
+
+ if ((nodedef->get(n_minus_x).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_x).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_x.getContent() == thiscontent)
+ is_rail_x[0] = true;
+
+ if ((nodedef->get(n_minus_x_minus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_x_minus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_x_minus_y.getContent() == thiscontent)
+ is_rail_x_minus_y[0] = true;
+
+ if ((nodedef->get(n_minus_x_plus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_x_plus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_x_plus_y.getContent() == thiscontent)
+ is_rail_x_plus_y[0] = true;
+
+ if ((nodedef->get(n_plus_x).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_x).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_x.getContent() == thiscontent)
+ is_rail_x[1] = true;
+
+ if ((nodedef->get(n_plus_x_minus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_x_minus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_x_minus_y.getContent() == thiscontent)
+ is_rail_x_minus_y[1] = true;
+
+ if ((nodedef->get(n_plus_x_plus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_x_plus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_x_plus_y.getContent() == thiscontent)
+ is_rail_x_plus_y[1] = true;
+
+ if ((nodedef->get(n_minus_z).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_z).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_z.getContent() == thiscontent)
+ is_rail_z[0] = true;
+
+ if ((nodedef->get(n_minus_z_minus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_z_minus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_z_minus_y.getContent() == thiscontent)
+ is_rail_z_minus_y[0] = true;
+
+ if ((nodedef->get(n_minus_z_plus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_minus_z_plus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_minus_z_plus_y.getContent() == thiscontent)
+ is_rail_z_plus_y[0] = true;
+
+ if ((nodedef->get(n_plus_z).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_z).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_z.getContent() == thiscontent)
+ is_rail_z[1] = true;
+
+ if ((nodedef->get(n_plus_z_minus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_z_minus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_z_minus_y.getContent() == thiscontent)
+ is_rail_z_minus_y[1] = true;
+
+ if ((nodedef->get(n_plus_z_plus_y).drawtype == NDT_RAILLIKE
+ && ((ItemGroupList) nodedef->get(n_plus_z_plus_y).groups)[groupname] != 0
+ && self_connect_to_raillike)
+ || n_plus_z_plus_y.getContent() == thiscontent)
+ is_rail_z_plus_y[1] = true;
+
+ bool is_rail_x_all[] = {false, false};
+ bool is_rail_z_all[] = {false, false};
+ is_rail_x_all[0]=is_rail_x[0] || is_rail_x_minus_y[0] || is_rail_x_plus_y[0];
+ is_rail_x_all[1]=is_rail_x[1] || is_rail_x_minus_y[1] || is_rail_x_plus_y[1];
+ is_rail_z_all[0]=is_rail_z[0] || is_rail_z_minus_y[0] || is_rail_z_plus_y[0];
+ is_rail_z_all[1]=is_rail_z[1] || is_rail_z_minus_y[1] || is_rail_z_plus_y[1];
+
+ // reasonable default, flat straight unrotated rail
+ bool is_straight = true;
+ int adjacencies = 0;
+ int angle = 0;
+ u8 tileindex = 0;
+
+ // check for sloped rail
+ 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])
+ {
+ adjacencies = 5; //5 means sloped
+ is_straight = true; // sloped is always straight
+ }
+ else
+ {
+ // is really straight, rails on both sides
+ is_straight = (is_rail_x_all[0] && is_rail_x_all[1]) || (is_rail_z_all[0] && is_rail_z_all[1]);
+ adjacencies = is_rail_x_all[0] + is_rail_x_all[1] + is_rail_z_all[0] + is_rail_z_all[1];
+ }
+
+ switch (adjacencies) {
+ case 1:
+ if(is_rail_x_all[0] || is_rail_x_all[1])
+ angle = 90;
+ break;
+ case 2:
+ if(!is_straight)
+ tileindex = 1; // curved
+ if(is_rail_x_all[0] && is_rail_x_all[1])
+ angle = 90;
+ if(is_rail_z_all[0] && is_rail_z_all[1]){
+ if (is_rail_z_plus_y[0])
+ angle = 180;
+ }
+ else if(is_rail_x_all[0] && is_rail_z_all[0])
+ angle = 270;
+ else if(is_rail_x_all[0] && is_rail_z_all[1])
+ angle = 180;
+ else if(is_rail_x_all[1] && is_rail_z_all[1])
+ angle = 90;
+ break;
+ case 3:
+ // here is where the potential to 'switch' a junction is, but not implemented at present
+ tileindex = 2; // t-junction
+ if(!is_rail_x_all[1])
+ angle=180;
+ if(!is_rail_z_all[0])
+ angle=90;
+ if(!is_rail_z_all[1])
+ angle=270;
+ break;
+ case 4:
+ tileindex = 3; // crossing
+ break;
+ case 5: //sloped
+ if(is_rail_z_plus_y[0])
+ angle = 180;
+ if(is_rail_x_plus_y[0])
+ angle = 90;
+ if(is_rail_x_plus_y[1])
+ angle = -90;
+ break;
+ default:
+ break;
+ }
+
+ TileSpec tile = getNodeTileN(n, p, tileindex, data);
+ tile.material_flags &= ~MATERIAL_FLAG_BACKFACE_CULLING;
+ tile.material_flags |= MATERIAL_FLAG_CRACK_OVERLAY;
+
+ u16 l = getInteriorLight(n, 0, nodedef);
+ video::SColor c = MapBlock_LightColor(255, l, f.light_source);
+
+ float d = (float)BS/64;
+
+ char g=-1;
+ 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])
+ g=1; //Object is at a slope