Skip to content
Permalink
Browse files

Make MapNode handle paramtype2≠leveled properly (#7958)

  • Loading branch information...
numberZero authored and nerzhul committed Dec 11, 2018
1 parent ca141ed commit 3bfb8284b868c580b5ec15e732c1d6b379168c2f
Showing with 20 additions and 18 deletions.
  1. +20 −18 src/mapnode.cpp
@@ -611,49 +611,51 @@ u8 MapNode::getLevel(const NodeDefManager *nodemgr) const
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)
if (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;
if (f.leveled > LEVELED_MAX)
return LEVELED_MAX;
return f.leveled;
}

u8 MapNode::setLevel(const NodeDefManager *nodemgr, s8 level)
{
u8 rest = 0;
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) {
|| f.liquid_type == LIQUID_FLOWING
|| f.liquid_type == LIQUID_SOURCE) {
if (level <= 0) { // liquid can’t exist with zero level
setContent(CONTENT_AIR);
return 0;
}
if (level >= LIQUID_LEVEL_SOURCE) {
rest = level - LIQUID_LEVEL_SOURCE;
setContent(nodemgr->getId(f.liquid_alternative_source));
setParam2(0);
} else {
setContent(nodemgr->getId(f.liquid_alternative_flowing));
setParam2(level & LIQUID_LEVEL_MASK);
setParam2((level & LIQUID_LEVEL_MASK) | (getParam2() & ~LIQUID_LEVEL_MASK));
}
} else if (f.leveled || f.param_type_2 == CPT2_LEVELED) {
if (level > LEVELED_MAX) {
} else if (f.param_type_2 == CPT2_LEVELED) {
if (level < 0) { // zero means default for a leveled nodebox
rest = level;
level = 0;
} else if (level > LEVELED_MAX) {
rest = level - LEVELED_MAX;
level = LEVELED_MAX;
}
setParam2(level & LEVELED_MASK);
setParam2((level & LEVELED_MASK) | (getParam2() & ~LEVELED_MASK));
}
return rest;
}

u8 MapNode::addLevel(const NodeDefManager *nodemgr, s8 add)
{
s8 level = getLevel(nodemgr);
if (add == 0) level = 1;
level += add;
return setLevel(nodemgr, level);
}

0 comments on commit 3bfb828

Please sign in to comment.
You can’t perform that action at this time.