aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRealBadAngel <maciej.kasatkin@o2.pl>2014-10-18 18:46:16 +0200
committerRealBadAngel <maciej.kasatkin@o2.pl>2014-10-19 20:48:21 +0200
commite5652cb75cd891895fab50ce46eb34ab9734d160 (patch)
treef3a58632b605ad4df441dbada879a8ec4170cf0f /src
parentb11e1db809aebc22f26887fffd50bd37f1fb6c3a (diff)
downloadminetest-e5652cb75cd891895fab50ce46eb34ab9734d160.tar.gz
minetest-e5652cb75cd891895fab50ce46eb34ab9734d160.tar.bz2
minetest-e5652cb75cd891895fab50ce46eb34ab9734d160.zip
Custom collision boxes node property.
Diffstat (limited to 'src')
-rw-r--r--src/collision.cpp2
-rw-r--r--src/mapnode.cpp9
-rw-r--r--src/mapnode.h8
-rw-r--r--src/nodedef.cpp3
-rw-r--r--src/nodedef.h1
-rw-r--r--src/script/common/c_content.cpp5
6 files changed, 25 insertions, 3 deletions
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<aabb3f> nodeboxes = n.getNodeBoxes(gamedef->ndef());
+ std::vector<aabb3f> nodeboxes = n.getCollisionBoxes(gamedef->ndef());
for(std::vector<aabb3f>::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<aabb3f> MapNode::getNodeBoxes(INodeDefManager *nodemgr) const
return transformNodeBox(*this, f.node_box, nodemgr);
}
+std::vector<aabb3f> 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<aabb3f> 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<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
@@ -227,6 +226,11 @@ struct MapNode
*/
std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
+ /*
+ Gets list of collision boxes
+ */
+ std::vector<aabb3f> 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<<serializeString(mesh);
+ collision_box.serialize(os, protocol_version);
}
void ContentFeatures::deSerialize(std::istream &is)
@@ -372,6 +374,7 @@ void ContentFeatures::deSerialize(std::istream &is)
// Stuff below should be moved to correct place in a version that
// otherwise changes the protocol version
mesh = deSerializeString(is);
+ collision_box.deSerialize(is);
}catch(SerializationError &e) {};
}
diff --git a/src/nodedef.h b/src/nodedef.h
index 2400f5f73..27d67b481 100644
--- a/src/nodedef.h
+++ b/src/nodedef.h
@@ -244,6 +244,7 @@ struct ContentFeatures
u32 damage_per_second;
NodeBox node_box;
NodeBox selection_box;
+ NodeBox collision_box;
// Used for waving leaves/plants
u8 waving;
// Compatibility with old maps
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index 4737f1993..58d8c473e 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -432,6 +432,11 @@ ContentFeatures read_content_features(lua_State *L, int index)
f.selection_box = read_nodebox(L, -1);
lua_pop(L, 1);
+ lua_getfield(L, index, "collision_box");
+ if(lua_istable(L, -1))
+ f.collision_box = read_nodebox(L, -1);
+ lua_pop(L, 1);
+
f.waving = getintfield_default(L, index,
"waving", f.waving);