mirror of
https://github.com/minetest/minetest.git
synced 2024-11-26 17:43:45 +01:00
Better snow fall, finite liquid transform, leveled nodes api
This commit is contained in:
parent
3aedfac968
commit
037e84d377
@ -59,7 +59,14 @@ minetest.register_entity("__builtin:falling_node", {
|
||||
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
|
||||
@ -152,11 +159,13 @@ function nodeupdate_single(p, delay)
|
||||
-- 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)
|
||||
|
@ -1268,6 +1268,8 @@ minetest.get_node_max_level(pos)
|
||||
^ 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)
|
||||
|
@ -285,7 +285,7 @@ class LiquidFreeze : public ActiveBlockModifier {
|
||||
}
|
||||
}
|
||||
if (allow) {
|
||||
n.setContent(ndef->getId(ndef->get(n).freezemelt));
|
||||
n.freezeMelt(ndef);
|
||||
map->addNodeWithEvent(p, n);
|
||||
}
|
||||
}
|
||||
@ -316,9 +316,7 @@ class LiquidMeltWeather : public ActiveBlockModifier {
|
||||
|
||||
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);
|
||||
}
|
||||
@ -346,14 +344,13 @@ class LiquidMeltHot : public ActiveBlockModifier {
|
||||
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)
|
||||
@ -368,7 +365,7 @@ class LiquidMeltAround : public LiquidMeltHot {
|
||||
virtual u32 getTriggerChance()
|
||||
{ return 60; }
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
|
||||
env->addActiveBlockModifier(new GrowGrassABM());
|
||||
@ -378,7 +375,7 @@ void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef) {
|
||||
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));
|
||||
|
23
src/map.cpp
23
src/map.cpp
@ -1717,7 +1717,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
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);
|
||||
}
|
||||
@ -1731,7 +1731,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
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;
|
||||
@ -1849,7 +1849,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
<< (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;
|
||||
@ -1881,7 +1881,7 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
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 &&
|
||||
@ -1896,10 +1896,11 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
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
|
||||
))
|
||||
@ -1908,14 +1909,18 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
(((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);
|
||||
@ -1923,13 +1928,15 @@ void Map::transformLiquidsFinite(std::map<v3s16, MapBlock*> & modified_blocks)
|
||||
//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()){
|
||||
|
@ -364,9 +364,7 @@ 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)
|
||||
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;
|
||||
@ -392,12 +390,9 @@ u8 MapNode::getLevel(INodeDefManager *nodemgr) const
|
||||
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;
|
||||
@ -406,8 +401,8 @@ u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
|
||||
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));
|
||||
@ -423,6 +418,31 @@ u8 MapNode::addLevel(INodeDefManager *nodemgr, s8 add)
|
||||
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))
|
||||
|
@ -104,7 +104,7 @@ enum Rotation {
|
||||
#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
|
||||
|
||||
/*
|
||||
@ -229,7 +229,9 @@ struct MapNode
|
||||
/* 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
|
||||
|
@ -287,9 +287,26 @@ int ModApiEnvMod::l_get_node_level(lua_State *L)
|
||||
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;
|
||||
@ -913,6 +930,7 @@ bool ModApiEnvMod::Initialize(lua_State *L,int top)
|
||||
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);
|
||||
|
@ -76,6 +76,10 @@ private:
|
||||
// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user