From: RealBadAngel Date: Sat, 18 Oct 2014 16:46:16 +0000 (+0200) Subject: Custom collision boxes node property. X-Git-Tag: 0.4.11~226 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e5652cb75cd891895fab50ce46eb34ab9734d160;p=oweals%2Fminetest.git Custom collision boxes node property. --- diff --git a/doc/lua_api.txt b/doc/lua_api.txt index 8f77366f7..ff2143cc8 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -408,8 +408,16 @@ param2 is reserved for the engine when any of these are used: 0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y- facedir's two less significant bits are rotation around the axis paramtype2 == "leveled" - ^ The drawn node level is read from param2, like flowingliquid - + collision_box = { + type = "fixed", + fixed = { + {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, + }, + }, + ^ defines list of collision boxes for the node. If empty, collision boxes + will be the same as nodeboxes, in case of any other nodes will be full cube + as in the example above. + Nodes can also contain extra data. See "Node Metadata". Node drawtypes diff --git a/src/collision.cpp b/src/collision.cpp index 76696e90d..edbee40b9 100644 --- a/src/collision.cpp +++ b/src/collision.cpp @@ -259,7 +259,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef, continue; int n_bouncy_value = itemgroup_get(f.groups, "bouncy"); - std::vector nodeboxes = n.getNodeBoxes(gamedef->ndef()); + std::vector nodeboxes = n.getCollisionBoxes(gamedef->ndef()); for(std::vector::iterator i = nodeboxes.begin(); i != nodeboxes.end(); i++) diff --git a/src/mapnode.cpp b/src/mapnode.cpp index d52677be0..786224240 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -354,6 +354,15 @@ std::vector MapNode::getNodeBoxes(INodeDefManager *nodemgr) const return transformNodeBox(*this, f.node_box, nodemgr); } +std::vector MapNode::getCollisionBoxes(INodeDefManager *nodemgr) const +{ + const ContentFeatures &f = nodemgr->get(*this); + if (f.collision_box.fixed.empty()) + return transformNodeBox(*this, f.node_box, nodemgr); + else + return transformNodeBox(*this, f.collision_box, nodemgr); +} + std::vector MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const { const ContentFeatures &f = nodemgr->get(*this); diff --git a/src/mapnode.h b/src/mapnode.h index f19885d87..d0b949e6f 100644 --- a/src/mapnode.h +++ b/src/mapnode.h @@ -217,8 +217,7 @@ struct MapNode void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot); /* - Gets list of node boxes (used for rendering (NDT_NODEBOX) - and collision) + Gets list of node boxes (used for rendering (NDT_NODEBOX)) */ std::vector getNodeBoxes(INodeDefManager *nodemgr) const; @@ -227,6 +226,11 @@ struct MapNode */ std::vector getSelectionBoxes(INodeDefManager *nodemgr) const; + /* + Gets list of collision boxes + */ + std::vector getCollisionBoxes(INodeDefManager *nodemgr) const; + /* Liquid helpers */ u8 getMaxLevel(INodeDefManager *nodemgr) const; u8 getLevel(INodeDefManager *nodemgr) const; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index ef61d0722..5735ef914 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -233,6 +233,7 @@ void ContentFeatures::reset() damage_per_second = 0; node_box = NodeBox(); selection_box = NodeBox(); + collision_box = NodeBox(); waving = 0; legacy_facedir_simple = false; legacy_wallmounted = false; @@ -303,6 +304,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) // Stuff below should be moved to correct place in a version that otherwise changes // the protocol version os<