+ std::vector<NearbyCollisionInfo> cinfo;
+ {
+ //TimeTaker tt2("collisionMoveSimple collect boxes");
+ ScopeProfiler sp2(g_profiler, "collisionMoveSimple collect boxes avg", SPT_AVG);
+
+ v3f newpos_f = *pos_f + *speed_f * dtime;
+ v3f minpos_f(
+ MYMIN(pos_f->X, newpos_f.X),
+ MYMIN(pos_f->Y, newpos_f.Y) + 0.01f * BS, // bias rounding, player often at +/-n.5
+ MYMIN(pos_f->Z, newpos_f.Z)
+ );
+ v3f maxpos_f(
+ MYMAX(pos_f->X, newpos_f.X),
+ MYMAX(pos_f->Y, newpos_f.Y),
+ MYMAX(pos_f->Z, newpos_f.Z)
+ );
+ v3s16 min = floatToInt(minpos_f + box_0.MinEdge, BS) - v3s16(1, 1, 1);
+ v3s16 max = floatToInt(maxpos_f + box_0.MaxEdge, BS) + v3s16(1, 1, 1);
+
+ bool any_position_valid = false;
+
+ v3s16 p;
+ for (p.X = min.X; p.X <= max.X; p.X++)
+ for (p.Y = min.Y; p.Y <= max.Y; p.Y++)
+ for (p.Z = min.Z; p.Z <= max.Z; p.Z++) {
+ bool is_position_valid;
+ MapNode n = map->getNodeNoEx(p, &is_position_valid);
+
+ if (is_position_valid && n.getContent() != CONTENT_IGNORE) {
+ // Object collides into walkable nodes
+
+ any_position_valid = true;
+ const NodeDefManager *nodedef = gamedef->getNodeDefManager();
+ const ContentFeatures &f = nodedef->get(n);
+
+ if (!f.walkable)
+ continue;
+
+ int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
+
+ int neighbors = 0;
+ if (f.drawtype == NDT_NODEBOX &&
+ f.node_box.type == NODEBOX_CONNECTED) {
+ v3s16 p2 = p;
+
+ p2.Y++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 1, &neighbors);
+
+ p2 = p;
+ p2.Y--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 2, &neighbors);
+
+ p2 = p;
+ p2.Z--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 4, &neighbors);
+
+ p2 = p;
+ p2.X--;
+ getNeighborConnectingFace(p2, nodedef, map, n, 8, &neighbors);
+
+ p2 = p;
+ p2.Z++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 16, &neighbors);
+
+ p2 = p;
+ p2.X++;
+ getNeighborConnectingFace(p2, nodedef, map, n, 32, &neighbors);
+ }
+ std::vector<aabb3f> nodeboxes;
+ n.getCollisionBoxes(gamedef->ndef(), &nodeboxes, neighbors);
+
+ // Calculate float position only once
+ v3f posf = intToFloat(p, BS);
+ for (auto box : nodeboxes) {
+ box.MinEdge += posf;
+ box.MaxEdge += posf;
+ cinfo.emplace_back(false, false, n_bouncy_value, p, box);
+ }
+ } else {
+ // Collide with unloaded nodes (position invalid) and loaded
+ // CONTENT_IGNORE nodes (position valid)
+ aabb3f box = getNodeBox(p, BS);
+ cinfo.emplace_back(true, false, 0, p, box);
+ }
+ }
+
+ // Do not move if world has not loaded yet, since custom node boxes
+ // are not available for collision detection.
+ // This also intentionally occurs in the case of the object being positioned
+ // solely on loaded CONTENT_IGNORE nodes, no matter where they come from.
+ if (!any_position_valid) {
+ *speed_f = v3f(0, 0, 0);
+ return result;
+ }
+
+ } // tt2
+
+ if(collideWithObjects)
+ {
+ ScopeProfiler sp2(g_profiler, "collisionMoveSimple objects avg", SPT_AVG);
+ //TimeTaker tt3("collisionMoveSimple collect object boxes");
+
+ /* add object boxes to cinfo */
+
+ std::vector<ActiveObject*> objects;
+#ifndef SERVER
+ ClientEnvironment *c_env = dynamic_cast<ClientEnvironment*>(env);
+ if (c_env != 0) {
+ f32 distance = speed_f->getLength();
+ std::vector<DistanceSortedActiveObject> clientobjects;
+ c_env->getActiveObjects(*pos_f, distance * 1.5f, clientobjects);
+ for (auto &clientobject : clientobjects) {
+ if (!self || (self != clientobject.obj)) {
+ objects.push_back((ActiveObject*) clientobject.obj);
+ }
+ }
+ }
+ else
+#endif
+ {
+ ServerEnvironment *s_env = dynamic_cast<ServerEnvironment*>(env);
+ if (s_env != NULL) {
+ f32 distance = speed_f->getLength();
+ std::vector<u16> s_objects;
+ s_env->getObjectsInsideRadius(s_objects, *pos_f, distance * 1.5f);
+ for (u16 obj_id : s_objects) {
+ ServerActiveObject *current = s_env->getActiveObject(obj_id);
+ if (!self || (self != current)) {
+ objects.push_back((ActiveObject*)current);
+ }
+ }
+ }
+ }
+
+ for (std::vector<ActiveObject*>::const_iterator iter = objects.begin();
+ iter != objects.end(); ++iter) {
+ ActiveObject *object = *iter;
+
+ if (object) {
+ aabb3f object_collisionbox;
+ if (object->getCollisionBox(&object_collisionbox) &&
+ object->collideWithObjects()) {
+ cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox);
+ }
+ }
+ }
+ } //tt3