mirror of
https://github.com/minetest/minetest.git
synced 2024-11-27 10:03:45 +01:00
parent
cb159f8d8a
commit
b6b80f55c8
@ -6632,6 +6632,7 @@ Collision info passed to `on_step`:
|
|||||||
type = string, -- "node" or "object",
|
type = string, -- "node" or "object",
|
||||||
axis = string, -- "x", "y" or "z"
|
axis = string, -- "x", "y" or "z"
|
||||||
node_pos = vector, -- if type is "node"
|
node_pos = vector, -- if type is "node"
|
||||||
|
object = ObjectRef, -- if type is "object"
|
||||||
old_velocity = vector,
|
old_velocity = vector,
|
||||||
new_velocity = vector,
|
new_velocity = vector,
|
||||||
},
|
},
|
||||||
|
@ -37,18 +37,30 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct NearbyCollisionInfo {
|
struct NearbyCollisionInfo {
|
||||||
NearbyCollisionInfo(bool is_ul, bool is_obj, int bouncy,
|
// node
|
||||||
const v3s16 &pos, const aabb3f &box) :
|
NearbyCollisionInfo(bool is_ul, int bouncy, const v3s16 &pos,
|
||||||
|
const aabb3f &box) :
|
||||||
is_unloaded(is_ul),
|
is_unloaded(is_ul),
|
||||||
is_object(is_obj),
|
obj(nullptr),
|
||||||
bouncy(bouncy),
|
bouncy(bouncy),
|
||||||
position(pos),
|
position(pos),
|
||||||
box(box)
|
box(box)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
// object
|
||||||
|
NearbyCollisionInfo(ActiveObject *obj, int bouncy,
|
||||||
|
const aabb3f &box) :
|
||||||
|
is_unloaded(false),
|
||||||
|
obj(obj),
|
||||||
|
bouncy(bouncy),
|
||||||
|
box(box)
|
||||||
|
{}
|
||||||
|
|
||||||
|
inline bool isObject() const { return obj != nullptr; }
|
||||||
|
|
||||||
bool is_unloaded;
|
bool is_unloaded;
|
||||||
bool is_step_up = false;
|
bool is_step_up = false;
|
||||||
bool is_object;
|
ActiveObject *obj;
|
||||||
int bouncy;
|
int bouncy;
|
||||||
v3s16 position;
|
v3s16 position;
|
||||||
aabb3f box;
|
aabb3f box;
|
||||||
@ -312,13 +324,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
for (auto box : nodeboxes) {
|
for (auto box : nodeboxes) {
|
||||||
box.MinEdge += posf;
|
box.MinEdge += posf;
|
||||||
box.MaxEdge += posf;
|
box.MaxEdge += posf;
|
||||||
cinfo.emplace_back(false, false, n_bouncy_value, p, box);
|
cinfo.emplace_back(false, n_bouncy_value, p, box);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Collide with unloaded nodes (position invalid) and loaded
|
// Collide with unloaded nodes (position invalid) and loaded
|
||||||
// CONTENT_IGNORE nodes (position valid)
|
// CONTENT_IGNORE nodes (position valid)
|
||||||
aabb3f box = getNodeBox(p, BS);
|
aabb3f box = getNodeBox(p, BS);
|
||||||
cinfo.emplace_back(true, false, 0, p, box);
|
cinfo.emplace_back(true, 0, p, box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -383,12 +395,10 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
iter != objects.end(); ++iter) {
|
iter != objects.end(); ++iter) {
|
||||||
ActiveObject *object = *iter;
|
ActiveObject *object = *iter;
|
||||||
|
|
||||||
if (object) {
|
if (object && object->collideWithObjects()) {
|
||||||
aabb3f object_collisionbox;
|
aabb3f object_collisionbox;
|
||||||
if (object->getCollisionBox(&object_collisionbox) &&
|
if (object->getCollisionBox(&object_collisionbox))
|
||||||
object->collideWithObjects()) {
|
cinfo.emplace_back(object, 0, object_collisionbox);
|
||||||
cinfo.emplace_back(false, true, 0, v3s16(), object_collisionbox);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifndef SERVER
|
#ifndef SERVER
|
||||||
@ -399,7 +409,8 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
v3f lplayer_pos = lplayer->getPosition();
|
v3f lplayer_pos = lplayer->getPosition();
|
||||||
lplayer_collisionbox.MinEdge += lplayer_pos;
|
lplayer_collisionbox.MinEdge += lplayer_pos;
|
||||||
lplayer_collisionbox.MaxEdge += lplayer_pos;
|
lplayer_collisionbox.MaxEdge += lplayer_pos;
|
||||||
cinfo.emplace_back(false, true, 0, v3s16(), lplayer_collisionbox);
|
ActiveObject *obj = (ActiveObject*) lplayer->getCAO();
|
||||||
|
cinfo.emplace_back(obj, 0, lplayer_collisionbox);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -498,12 +509,13 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
is_collision = false;
|
is_collision = false;
|
||||||
|
|
||||||
CollisionInfo info;
|
CollisionInfo info;
|
||||||
if (nearest_info.is_object)
|
if (nearest_info.isObject())
|
||||||
info.type = COLLISION_OBJECT;
|
info.type = COLLISION_OBJECT;
|
||||||
else
|
else
|
||||||
info.type = COLLISION_NODE;
|
info.type = COLLISION_NODE;
|
||||||
|
|
||||||
info.node_p = nearest_info.position;
|
info.node_p = nearest_info.position;
|
||||||
|
info.object = nearest_info.obj;
|
||||||
info.old_speed = *speed_f;
|
info.old_speed = *speed_f;
|
||||||
info.plane = nearest_collided;
|
info.plane = nearest_collided;
|
||||||
|
|
||||||
@ -572,7 +584,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.05f) {
|
if (std::fabs(cbox.MaxEdge.Y - box.MinEdge.Y) < 0.05f) {
|
||||||
result.touching_ground = true;
|
result.touching_ground = true;
|
||||||
|
|
||||||
if (box_info.is_object)
|
if (box_info.isObject())
|
||||||
result.standing_on_object = true;
|
result.standing_on_object = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ struct CollisionInfo
|
|||||||
CollisionType type = COLLISION_NODE;
|
CollisionType type = COLLISION_NODE;
|
||||||
CollisionAxis axis = COLLISION_AXIS_NONE;
|
CollisionAxis axis = COLLISION_AXIS_NONE;
|
||||||
v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE
|
v3s16 node_p = v3s16(-32768,-32768,-32768); // COLLISION_NODE
|
||||||
|
ActiveObject *object = nullptr; // COLLISION_OBJECT
|
||||||
v3f old_speed;
|
v3f old_speed;
|
||||||
v3f new_speed;
|
v3f new_speed;
|
||||||
int plane = -1;
|
int plane = -1;
|
||||||
|
@ -2043,6 +2043,9 @@ void push_collision_move_result(lua_State *L, const collisionMoveResult &res)
|
|||||||
if (c.type == COLLISION_NODE) {
|
if (c.type == COLLISION_NODE) {
|
||||||
push_v3s16(L, c.node_p);
|
push_v3s16(L, c.node_p);
|
||||||
lua_setfield(L, -2, "node_pos");
|
lua_setfield(L, -2, "node_pos");
|
||||||
|
} else if (c.type == COLLISION_OBJECT) {
|
||||||
|
push_objectRef(L, c.object->getId());
|
||||||
|
lua_setfield(L, -2, "object");
|
||||||
}
|
}
|
||||||
|
|
||||||
push_v3f(L, c.old_speed / BS);
|
push_v3f(L, c.old_speed / BS);
|
||||||
|
Loading…
Reference in New Issue
Block a user