+ }
+ }
+ }
+
+ if (result.type == POINTEDTHING_NODE) {
+ f32 d = 0.001 * BS;
+ MapNode n = map.getNodeNoEx(pointed_pos);
+ v3f npf = intToFloat(pointed_pos, BS);
+ std::vector<aabb3f> boxes;
+ n.getSelectionBoxes(nodedef, &boxes);
+ f32 face_min_distance = 1000 * BS;
+ for (std::vector<aabb3f>::const_iterator
+ i = boxes.begin();
+ i != boxes.end(); ++i) {
+ aabb3f box = *i;
+ box.MinEdge += npf;
+ box.MaxEdge += npf;
+ for (u16 j = 0; j < 6; j++) {
+ v3s16 facedir = g_6dirs[j];
+ aabb3f facebox = box;
+ if (facedir.X > 0) {
+ facebox.MinEdge.X = facebox.MaxEdge.X - d;
+ } else if (facedir.X < 0) {
+ facebox.MaxEdge.X = facebox.MinEdge.X + d;
+ } else if (facedir.Y > 0) {
+ facebox.MinEdge.Y = facebox.MaxEdge.Y - d;
+ } else if (facedir.Y < 0) {
+ facebox.MaxEdge.Y = facebox.MinEdge.Y + d;
+ } else if (facedir.Z > 0) {
+ facebox.MinEdge.Z = facebox.MaxEdge.Z - d;
+ } else if (facedir.Z < 0) {
+ facebox.MaxEdge.Z = facebox.MinEdge.Z + d;
+ }
+ v3f centerpoint = facebox.getCenter();
+ f32 distance = (centerpoint - camera_position).getLength();
+ if (distance >= face_min_distance)
+ continue;
+ if (!facebox.intersectsWithLine(shootline))
+ continue;
+ result.node_abovesurface = pointed_pos + facedir;
+ face_min_distance = distance;
+ }
+ }
+ selectionboxes->clear();
+ for (std::vector<aabb3f>::const_iterator
+ i = boxes.begin();
+ i != boxes.end(); ++i) {
+ aabb3f box = *i;
+ box.MinEdge += v3f(-d, -d, -d);
+ box.MaxEdge += v3f(d, d, d);
+ selectionboxes->push_back(box);
+ }
+ hud->setSelectionPos(intToFloat(pointed_pos, BS), camera_offset);
+ result.node_undersurface = pointed_pos;
+ }