summaryrefslogtreecommitdiff
path: root/src/mapnode.cpp
diff options
context:
space:
mode:
authorproller <proller@github.com>2013-07-13 21:48:14 +0400
committerproller <proller@github.com>2013-07-13 22:13:24 +0400
commit9733dd5b5e5516e18775665db132b2446492716c (patch)
treecb665ab99ebab101c563076a9e31a94a2ce293d4 /src/mapnode.cpp
parenta70993d6d20b4668556a8792ecd952d84a7e6939 (diff)
downloadminetest-9733dd5b5e5516e18775665db132b2446492716c.tar.gz
minetest-9733dd5b5e5516e18775665db132b2446492716c.tar.bz2
minetest-9733dd5b5e5516e18775665db132b2446492716c.zip
Leveled nodebox
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r--src/mapnode.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp
index f93231187..33644cf5c 100644
--- a/src/mapnode.cpp
+++ b/src/mapnode.cpp
@@ -163,7 +163,7 @@ static std::vector<aabb3f> transformNodeBox(const MapNode &n,
const NodeBox &nodebox, INodeDefManager *nodemgr)
{
std::vector<aabb3f> boxes;
- if(nodebox.type == NODEBOX_FIXED)
+ if(nodebox.type == NODEBOX_FIXED || nodebox.type == NODEBOX_LEVELED)
{
const std::vector<aabb3f> &fixed = nodebox.fixed;
int facedir = n.getFaceDir(nodemgr);
@@ -174,6 +174,11 @@ static std::vector<aabb3f> transformNodeBox(const MapNode &n,
i != fixed.end(); i++)
{
aabb3f box = *i;
+
+ if (nodebox.type == NODEBOX_LEVELED) {
+ box.MaxEdge.Y = -BS/2 + BS*((float)1/LEVELED_MAX) * n.getLevel(nodemgr);
+ }
+
switch (axisdir)
{
case 0:
@@ -354,6 +359,24 @@ std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const
return transformNodeBox(*this, f.selection_box, nodemgr);
}
+u8 MapNode::getLevel(INodeDefManager *nodemgr) const
+{
+ const ContentFeatures &f = nodemgr->get(*this);
+ if(f.liquid_type == LIQUID_SOURCE)
+ return LIQUID_LEVEL_SOURCE;
+ if (f.param_type_2 == CPT2_FLOWINGLIQUID)
+ return getParam2() & LIQUID_LEVEL_MASK;
+ if(f.liquid_type == LIQUID_FLOWING) // can remove if all param_type_2 setted
+ return getParam2() & LIQUID_LEVEL_MASK;
+ if(f.leveled || f.param_type_2 == CPT2_LEVELED) {
+ u8 level = getParam2() & LEVELED_MASK;
+ if(level) return level;
+ if(f.leveled > LEVELED_MAX) return LEVELED_MAX;
+ return f.leveled; //default
+ }
+ return 0;
+}
+
u32 MapNode::serializedLength(u8 version)
{
if(!ser_ver_supported(version))