minetest.registered_nodes[bcn.name].walkable or
(minetest.get_node_group(self.node.name, "float") ~= 0 and minetest.registered_nodes[bcn.name].liquidtype ~= "none")
then
- if minetest.registered_nodes[bcn.name].buildable_to and (minetest.get_node_group(self.node.name, "float") == 0 or minetest.registered_nodes[bcn.name].liquidtype == "none") then
+ if minetest.registered_nodes[bcn.name].leveled and bcn.name == self.node.name then
+ local addlevel = self.node.level
+ if addlevel == nil or addlevel <= 0 then addlevel = minetest.registered_nodes[bcn.name].leveled end
+ if minetest.env:add_node_level(bcp, addlevel) == 0 then
+ self.object:remove()
+ return
+ end
+ elseif minetest.registered_nodes[bcn.name].buildable_to and (minetest.get_node_group(self.node.name, "float") == 0 or minetest.registered_nodes[bcn.name].liquidtype == "none") then
minetest.remove_node(bcp)
return
end
-- Note: walkable is in the node definition, not in item groups
if minetest.registered_nodes[n_bottom.name] and
(minetest.get_node_group(n.name, "float") == 0 or minetest.registered_nodes[n_bottom.name].liquidtype == "none") and
+ (n.name ~= n_bottom.name or (minetest.registered_nodes[n_bottom.name].leveled and minetest.env:get_node_level(p_bottom) < minetest.env:get_node_max_level(p_bottom))) and
(not minetest.registered_nodes[n_bottom.name].walkable or
minetest.registered_nodes[n_bottom.name].buildable_to) then
if delay then
minetest.after(0.1, nodeupdate_single, {x=p.x, y=p.y, z=p.z}, false)
else
+ n.level = minetest.env:get_node_level(p)
minetest.remove_node(p)
spawn_falling_node(p, n)
nodeupdate(p)
^ get max available level for leveled node
minetest.get_node_level(pos)
^ get level of leveled node (water, snow)
+minetest.set_node_level(pos, level)
+^ set level of leveled node, default level = 1, if totallevel > maxlevel returns rest (total-max).
minetest.add_node_level(pos, level)
^ increase level of leveled node by level, default level = 1, if totallevel > maxlevel returns rest (total-max). can be negative for decreasing
minetest.get_heat(pos)
}
}
if (allow) {
- n.setContent(ndef->getId(ndef->get(n).freezemelt));
+ n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
}
}
float heat = map->getHeat(env, p);
if (heat >= 1 && (heat >= 40 || ((myrand_range(heat, 40)) >= 20))) {
- n.setContent(ndef->getId(ndef->get(n).freezemelt));
- if (!n.getLevel(ndef))
- n.addLevel(ndef);
+ n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
env->getScriptIface()->node_falling_update(p);
}
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n) {
ServerMap *map = &env->getServerMap();
INodeDefManager *ndef = env->getGameDef()->ndef();
- n.setContent(ndef->getId(ndef->get(n).freezemelt));
- if (!n.getLevel(ndef))
- n.addLevel(ndef);
+ n.freezeMelt(ndef);
map->addNodeWithEvent(p, n);
env->getScriptIface()->node_falling_update(p);
}
};
+/* too buggy, later via liquid flow code
class LiquidMeltAround : public LiquidMeltHot {
public:
LiquidMeltAround(ServerEnvironment *env, INodeDefManager *nodemgr)
virtual u32 getTriggerChance()
{ return 60; }
};
-
+*/
void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
env->addActiveBlockModifier(new GrowGrassABM());
env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
env->addActiveBlockModifier(new LiquidDropABM(env, nodedef));
env->addActiveBlockModifier(new LiquidMeltHot(env, nodedef));
- env->addActiveBlockModifier(new LiquidMeltAround(env, nodedef));
+ //env->addActiveBlockModifier(new LiquidMeltAround(env, nodedef));
if (g_settings->getBool("weather")) {
env->addActiveBlockModifier(new LiquidFreeze(env, nodedef));
env->addActiveBlockModifier(new LiquidMeltWeather(env, nodedef));
if (liquid_kind == CONTENT_IGNORE)
liquid_kind = nb.n.getContent();
if (nb.n.getContent() == liquid_kind) {
- liquid_levels[i] = LIQUID_LEVEL_SOURCE;
+ liquid_levels[i] = nb.n.getLevel(nodemgr); //LIQUID_LEVEL_SOURCE;
nb.l = 1;
nb.i = (nb.n.param2 & LIQUID_INFINITY_MASK);
}
liquid_kind = nodemgr->getId(
nodemgr->get(nb.n).liquid_alternative_source);
if (nb.n.getContent() == liquid_kind_flowing) {
- liquid_levels[i] = (nb.n.param2 & LIQUID_LEVEL_MASK);
+ liquid_levels[i] = nb.n.getLevel(nodemgr); //(nb.n.param2 & LIQUID_LEVEL_MASK);
nb.l = 1;
}
break;
<< (int)liquid_levels_want[D_BOTTOM]<<std::endl;
*/
- u8 changed = 0;
+ //u8 changed = 0;
for (u16 i = 0; i < 7; i++) {
if (liquid_levels_want[i] < 0 || !neighbors[i].l)
continue;
new_node_content = liquid_kind_flowing;
else
new_node_content = CONTENT_AIR;
-
+
// last level must flow down on stairs
if (liquid_levels_want[i] != liquid_levels[i] &&
liquid_levels[D_TOP] <= 0 && !neighbors[D_BOTTOM].l &&
check if anything has changed.
if not, just continue with the next node.
*/
+ /*
if (
new_node_content == n0.getContent()
&& (nodemgr->get(n0.getContent()).liquid_type != LIQUID_FLOWING ||
- ((n0.param2 & LIQUID_LEVEL_MASK) == (u8)new_node_level
+ (n0.getLevel(nodemgr) == (u8)new_node_level
//&& ((n0.param2 & LIQUID_FLOW_DOWN_MASK) ==
//LIQUID_FLOW_DOWN_MASK) == flowing_down
))
(((n0.param2 & LIQUID_INFINITY_MASK) ==
LIQUID_INFINITY_MASK) == neighbors[i].i
))
- ) {
+ )*/
+ if (liquid_levels[i] == new_node_level)
+ {
continue;
}
- ++changed;
+
+ //++changed;
/*
update the current node
*/
+ /*
if (nodemgr->get(new_node_content).liquid_type == LIQUID_FLOWING) {
// set level to last 3 bits, flowing down bit to 4th bit
n0.param2 = (new_node_level & LIQUID_LEVEL_MASK);
//n0.param2 = ~(LIQUID_LEVEL_MASK | LIQUID_FLOW_DOWN_MASK);
n0.param2 = (neighbors[i].i ? LIQUID_INFINITY_MASK : 0x00);
}
+ */
/*
infostream << "set node i=" <<(int)i<<" "<< PP(p0)<< " nc="
<<new_node_content<< " p2="<<(int)n0.param2<< " nl="
<<(int)new_node_level<<std::endl;
*/
- n0.setContent(new_node_content);
+ n0.setContent(liquid_kind_flowing);
+ n0.setLevel(nodemgr, new_node_level);
// Find out whether there is a suspect for this action
std::string suspect;
if(m_gamedef->rollback()){
{
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)
+ if( 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::addLevel(INodeDefManager *nodemgr, s8 add)
+u8 MapNode::setLevel(INodeDefManager *nodemgr, s8 level)
{
- s8 level = getLevel(nodemgr);
u8 rest = 0;
- if (add == 0) level = 1;
- level += add;
if (level < 1) {
setContent(CONTENT_AIR);
return 0;
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;
+ if (level >= LIQUID_LEVEL_SOURCE) {
+ rest = level - LIQUID_LEVEL_SOURCE;
setContent(nodemgr->getId(f.liquid_alternative_source));
} else {
setContent(nodemgr->getId(f.liquid_alternative_flowing));
return rest;
}
+u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
+{
+ s8 level = getLevel(nodemgr);
+ if (add == 0) level = 1;
+ level += add;
+ return setLevel(nodemgr, level);
+}
+
+void MapNode::freezeMelt(INodeDefManager *ndef) {
+ u8 level_was_max = this->getMaxLevel(ndef);
+ u8 level_was = this->getLevel(ndef);
+ this->setContent(ndef->getId(ndef->get(*this).freezemelt));
+ u8 level_now_max = this->getMaxLevel(ndef);
+ if (level_was_max && level_was_max != level_now_max) {
+ u8 want = (float)level_now_max / level_was_max * level_was;
+ if (!want)
+ want = 1;
+ if (want != level_was)
+ this->setLevel(ndef, want);
+ //errorstream<<"was="<<(int)level_was<<"/"<<(int)level_was_max<<" nowm="<<(int)want<<"/"<<(int)level_now_max<< " => "<<(int)this->getLevel(ndef)<< std::endl;
+ }
+ if (this->getMaxLevel(ndef) && !this->getLevel(ndef))
+ this->addLevel(ndef);
+}
+
u32 MapNode::serializedLength(u8 version)
{
if(!ser_ver_supported(version))
#define LIQUID_INFINITY_MASK 0x80 //0b10000000
// mask for param2, now as for liquid
-#define LEVELED_MASK 0x07
+#define LEVELED_MASK 0x3F
#define LEVELED_MAX LEVELED_MASK
/*
/* Liquid helpers */
u8 getMaxLevel(INodeDefManager *nodemgr) const;
u8 getLevel(INodeDefManager *nodemgr) const;
+ u8 setLevel(INodeDefManager *nodemgr, s8 level = 1);
u8 addLevel(INodeDefManager *nodemgr, s8 add = 1);
+ void freezeMelt(INodeDefManager *nodemgr);
/*
Serialization functions
return 1;
}
+// minetest.set_node_level(pos, level)
+// pos = {x=num, y=num, z=num}
+// level: 0..63
+int ModApiEnvMod::l_set_node_level(lua_State *L)
+{
+ GET_ENV_PTR;
+
+ v3s16 pos = read_v3s16(L, 1);
+ u8 level = 1;
+ if(lua_isnumber(L, 2))
+ level = lua_tonumber(L, 2);
+ MapNode n = env->getMap().getNodeNoEx(pos);
+ lua_pushnumber(L, n.setLevel(env->getGameDef()->ndef(), level));
+ env->setNode(pos, n);
+ return 1;
+}
+
// minetest.add_node_level(pos, level)
// pos = {x=num, y=num, z=num}
-// level: 0..8
+// level: 0..63
int ModApiEnvMod::l_add_node_level(lua_State *L)
{
GET_ENV_PTR;
retval &= API_FCT(punch_node);
retval &= API_FCT(get_node_max_level);
retval &= API_FCT(get_node_level);
+ retval &= API_FCT(set_node_level);
retval &= API_FCT(add_node_level);
retval &= API_FCT(add_entity);
retval &= API_FCT(get_meta);
// pos = {x=num, y=num, z=num}
static int l_get_node_level(lua_State *L);
+ // minetest.set_node_level(pos)
+ // pos = {x=num, y=num, z=num}
+ static int l_set_node_level(lua_State *L);
+
// minetest.add_node_level(pos)
// pos = {x=num, y=num, z=num}
static int l_add_node_level(lua_State *L);