Skip to content

Commit e5652cb

Browse files
committedOct 19, 2014
Custom collision boxes node property.
1 parent b11e1db commit e5652cb

File tree

7 files changed

+35
-5
lines changed

7 files changed

+35
-5
lines changed
 

‎doc/lua_api.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,16 @@ param2 is reserved for the engine when any of these are used:
408408
0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
409409
facedir's two less significant bits are rotation around the axis
410410
paramtype2 == "leveled"
411-
^ The drawn node level is read from param2, like flowingliquid
412-
411+
collision_box = {
412+
type = "fixed",
413+
fixed = {
414+
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
415+
},
416+
},
417+
^ defines list of collision boxes for the node. If empty, collision boxes
418+
will be the same as nodeboxes, in case of any other nodes will be full cube
419+
as in the example above.
420+
413421
Nodes can also contain extra data. See "Node Metadata".
414422

415423
Node drawtypes

‎src/collision.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
259259
continue;
260260
int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
261261

262-
std::vector<aabb3f> nodeboxes = n.getNodeBoxes(gamedef->ndef());
262+
std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(gamedef->ndef());
263263
for(std::vector<aabb3f>::iterator
264264
i = nodeboxes.begin();
265265
i != nodeboxes.end(); i++)

‎src/mapnode.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,15 @@ std::vector<aabb3f> MapNode::getNodeBoxes(INodeDefManager *nodemgr) const
354354
return transformNodeBox(*this, f.node_box, nodemgr);
355355
}
356356

357+
std::vector<aabb3f> MapNode::getCollisionBoxes(INodeDefManager *nodemgr) const
358+
{
359+
const ContentFeatures &f = nodemgr->get(*this);
360+
if (f.collision_box.fixed.empty())
361+
return transformNodeBox(*this, f.node_box, nodemgr);
362+
else
363+
return transformNodeBox(*this, f.collision_box, nodemgr);
364+
}
365+
357366
std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const
358367
{
359368
const ContentFeatures &f = nodemgr->get(*this);

‎src/mapnode.h

+6-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ struct MapNode
217217
void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot);
218218

219219
/*
220-
Gets list of node boxes (used for rendering (NDT_NODEBOX)
221-
and collision)
220+
Gets list of node boxes (used for rendering (NDT_NODEBOX))
222221
*/
223222
std::vector<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
224223

@@ -227,6 +226,11 @@ struct MapNode
227226
*/
228227
std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
229228

229+
/*
230+
Gets list of collision boxes
231+
*/
232+
std::vector<aabb3f> getCollisionBoxes(INodeDefManager *nodemgr) const;
233+
230234
/* Liquid helpers */
231235
u8 getMaxLevel(INodeDefManager *nodemgr) const;
232236
u8 getLevel(INodeDefManager *nodemgr) const;

‎src/nodedef.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ void ContentFeatures::reset()
233233
damage_per_second = 0;
234234
node_box = NodeBox();
235235
selection_box = NodeBox();
236+
collision_box = NodeBox();
236237
waving = 0;
237238
legacy_facedir_simple = false;
238239
legacy_wallmounted = false;
@@ -303,6 +304,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version)
303304
// Stuff below should be moved to correct place in a version that otherwise changes
304305
// the protocol version
305306
os<<serializeString(mesh);
307+
collision_box.serialize(os, protocol_version);
306308
}
307309

308310
void ContentFeatures::deSerialize(std::istream &is)
@@ -372,6 +374,7 @@ void ContentFeatures::deSerialize(std::istream &is)
372374
// Stuff below should be moved to correct place in a version that
373375
// otherwise changes the protocol version
374376
mesh = deSerializeString(is);
377+
collision_box.deSerialize(is);
375378
}catch(SerializationError &e) {};
376379
}
377380

‎src/nodedef.h

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ struct ContentFeatures
244244
u32 damage_per_second;
245245
NodeBox node_box;
246246
NodeBox selection_box;
247+
NodeBox collision_box;
247248
// Used for waving leaves/plants
248249
u8 waving;
249250
// Compatibility with old maps

‎src/script/common/c_content.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ ContentFeatures read_content_features(lua_State *L, int index)
432432
f.selection_box = read_nodebox(L, -1);
433433
lua_pop(L, 1);
434434

435+
lua_getfield(L, index, "collision_box");
436+
if(lua_istable(L, -1))
437+
f.collision_box = read_nodebox(L, -1);
438+
lua_pop(L, 1);
439+
435440
f.waving = getintfield_default(L, index,
436441
"waving", f.waving);
437442

0 commit comments

Comments
 (0)
Please sign in to comment.