mirror of
https://github.com/moparisthebest/minetest
synced 2024-11-15 22:05:07 -05:00
Custom collision boxes node property.
This commit is contained in:
parent
b11e1db809
commit
e5652cb75c
@ -408,7 +408,15 @@ param2 is reserved for the engine when any of these are used:
|
|||||||
0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
|
0 = y+ 1 = z+ 2 = z- 3 = x+ 4 = x- 5 = y-
|
||||||
facedir's two less significant bits are rotation around the axis
|
facedir's two less significant bits are rotation around the axis
|
||||||
paramtype2 == "leveled"
|
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".
|
Nodes can also contain extra data. See "Node Metadata".
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ collisionMoveResult collisionMoveSimple(Environment *env, IGameDef *gamedef,
|
|||||||
continue;
|
continue;
|
||||||
int n_bouncy_value = itemgroup_get(f.groups, "bouncy");
|
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
|
for(std::vector<aabb3f>::iterator
|
||||||
i = nodeboxes.begin();
|
i = nodeboxes.begin();
|
||||||
i != nodeboxes.end(); i++)
|
i != nodeboxes.end(); i++)
|
||||||
|
@ -354,6 +354,15 @@ std::vector<aabb3f> MapNode::getNodeBoxes(INodeDefManager *nodemgr) const
|
|||||||
return transformNodeBox(*this, f.node_box, nodemgr);
|
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
|
std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const
|
||||||
{
|
{
|
||||||
const ContentFeatures &f = nodemgr->get(*this);
|
const ContentFeatures &f = nodemgr->get(*this);
|
||||||
|
@ -217,8 +217,7 @@ struct MapNode
|
|||||||
void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot);
|
void rotateAlongYAxis(INodeDefManager *nodemgr, Rotation rot);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Gets list of node boxes (used for rendering (NDT_NODEBOX)
|
Gets list of node boxes (used for rendering (NDT_NODEBOX))
|
||||||
and collision)
|
|
||||||
*/
|
*/
|
||||||
std::vector<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
|
std::vector<aabb3f> getNodeBoxes(INodeDefManager *nodemgr) const;
|
||||||
|
|
||||||
@ -227,6 +226,11 @@ struct MapNode
|
|||||||
*/
|
*/
|
||||||
std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
|
std::vector<aabb3f> getSelectionBoxes(INodeDefManager *nodemgr) const;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Gets list of collision boxes
|
||||||
|
*/
|
||||||
|
std::vector<aabb3f> getCollisionBoxes(INodeDefManager *nodemgr) const;
|
||||||
|
|
||||||
/* Liquid helpers */
|
/* Liquid helpers */
|
||||||
u8 getMaxLevel(INodeDefManager *nodemgr) const;
|
u8 getMaxLevel(INodeDefManager *nodemgr) const;
|
||||||
u8 getLevel(INodeDefManager *nodemgr) const;
|
u8 getLevel(INodeDefManager *nodemgr) const;
|
||||||
|
@ -233,6 +233,7 @@ void ContentFeatures::reset()
|
|||||||
damage_per_second = 0;
|
damage_per_second = 0;
|
||||||
node_box = NodeBox();
|
node_box = NodeBox();
|
||||||
selection_box = NodeBox();
|
selection_box = NodeBox();
|
||||||
|
collision_box = NodeBox();
|
||||||
waving = 0;
|
waving = 0;
|
||||||
legacy_facedir_simple = false;
|
legacy_facedir_simple = false;
|
||||||
legacy_wallmounted = 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
|
// Stuff below should be moved to correct place in a version that otherwise changes
|
||||||
// the protocol version
|
// the protocol version
|
||||||
os<<serializeString(mesh);
|
os<<serializeString(mesh);
|
||||||
|
collision_box.serialize(os, protocol_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContentFeatures::deSerialize(std::istream &is)
|
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
|
// Stuff below should be moved to correct place in a version that
|
||||||
// otherwise changes the protocol version
|
// otherwise changes the protocol version
|
||||||
mesh = deSerializeString(is);
|
mesh = deSerializeString(is);
|
||||||
|
collision_box.deSerialize(is);
|
||||||
}catch(SerializationError &e) {};
|
}catch(SerializationError &e) {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,6 +244,7 @@ struct ContentFeatures
|
|||||||
u32 damage_per_second;
|
u32 damage_per_second;
|
||||||
NodeBox node_box;
|
NodeBox node_box;
|
||||||
NodeBox selection_box;
|
NodeBox selection_box;
|
||||||
|
NodeBox collision_box;
|
||||||
// Used for waving leaves/plants
|
// Used for waving leaves/plants
|
||||||
u8 waving;
|
u8 waving;
|
||||||
// Compatibility with old maps
|
// Compatibility with old maps
|
||||||
|
@ -432,6 +432,11 @@ ContentFeatures read_content_features(lua_State *L, int index)
|
|||||||
f.selection_box = read_nodebox(L, -1);
|
f.selection_box = read_nodebox(L, -1);
|
||||||
lua_pop(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,
|
f.waving = getintfield_default(L, index,
|
||||||
"waving", f.waving);
|
"waving", f.waving);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user