diff options
Diffstat (limited to 'src/mapnode.cpp')
-rw-r--r-- | src/mapnode.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 33644cf5c..4707978cb 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -25,6 +25,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "content_mapnode.h" // For mapnode_translate_*_internal #include "serialization.h" // For ser_ver_supported #include "util/serialize.h" +#include "log.h" #include <string> #include <sstream> @@ -359,9 +360,23 @@ std::vector<aabb3f> MapNode::getSelectionBoxes(INodeDefManager *nodemgr) const return transformNodeBox(*this, f.selection_box, nodemgr); } +u8 MapNode::getMaxLevel(INodeDefManager *nodemgr) const +{ + const ContentFeatures &f = nodemgr->get(*this); + // todo: after update in all games leave only if (f.param_type_2 == + if( f.liquid_type == LIQUID_SOURCE + || f.liquid_type == LIQUID_FLOWING + || f.param_type_2 == CPT2_FLOWINGLIQUID) + return LIQUID_LEVEL_MAX; + if(f.leveled || f.param_type_2 == CPT2_LEVELED) + return LEVELED_MAX; + return 0; +} + u8 MapNode::getLevel(INodeDefManager *nodemgr) const { const ContentFeatures &f = nodemgr->get(*this); + // todo: after update in all games leave only if (f.param_type_2 == if(f.liquid_type == LIQUID_SOURCE) return LIQUID_LEVEL_SOURCE; if (f.param_type_2 == CPT2_FLOWINGLIQUID) @@ -377,6 +392,37 @@ u8 MapNode::getLevel(INodeDefManager *nodemgr) const return 0; } +u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add) +{ + s8 level = getLevel(nodemgr); + u8 rest = 0; + if (add == 0) level = 1; + level += add; + if (level < 1) { + setContent(CONTENT_AIR); + return 0; + } + const ContentFeatures &f = nodemgr->get(*this); + if ( f.param_type_2 == CPT2_FLOWINGLIQUID + || f.liquid_type == LIQUID_FLOWING + || f.liquid_type == LIQUID_SOURCE) { + if (level >= LIQUID_LEVEL_MAX) { + rest = level - LIQUID_LEVEL_MAX; + setContent(nodemgr->getId(f.liquid_alternative_source)); + } else { + setContent(nodemgr->getId(f.liquid_alternative_flowing)); + setParam2(level & LIQUID_LEVEL_MASK); + } + } else if (f.leveled || f.param_type_2 == CPT2_LEVELED) { + if (level > LEVELED_MAX) { + rest = level - LEVELED_MAX; + level = LEVELED_MAX; + } + setParam2(level & LEVELED_MASK); + } + return rest; +} + u32 MapNode::serializedLength(u8 version) { if(!ser_ver_supported(version)) |