Skip to content

Commit

Permalink
Merge pull request #482 from proller/liquid
Browse files Browse the repository at this point in the history
finite liquid
  • Loading branch information
kwolekr committed Feb 26, 2013
2 parents 9b5f182 + b90e431 commit 979ca23
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 8 deletions.
10 changes: 8 additions & 2 deletions games/minimal/mods/default/mapgen.lua
Expand Up @@ -27,7 +27,7 @@ minetest.register_alias("mapgen_mese", "default:mese")
-- Ore generation
--

local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max)
local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume, ore_per_chunk, height_min, height_max, param2)
if maxp.y < height_min or minp.y > height_max then
return
end
Expand Down Expand Up @@ -57,7 +57,7 @@ local function generate_ore(name, wherein, minp, maxp, seed, chunks_per_volume,
local z2 = z0+z1
local p2 = {x=x2, y=y2, z=z2}
if minetest.env:get_node(p2).name == wherein then
minetest.env:set_node(p2, {name=name})
minetest.env:set_node(p2, {name=name, param2=param2})
end
end
end
Expand Down Expand Up @@ -110,5 +110,11 @@ minetest.register_on_generated(function(minp, maxp, seed)
end
end
end
if minetest.setting_get("liquid_finite") then
generate_ore("default:water_source", "default:stone", minp, maxp, seed+42, 1/24/24/24, 4, -100, -10, 128)
generate_ore("default:water_source", "default:stone", minp, maxp, seed+42, 1/28/28/28, 3, -10000, -101, 128)
generate_ore("default:lava_source", "default:stone", minp, maxp, seed+43, 1/38/38/38, 2, -500, -100, 128)
generate_ore("default:lava_source", "default:stone", minp, maxp, seed+43, 1/30/30/30, 4, -31000, -501, 128)
end
end)

8 changes: 8 additions & 0 deletions minetest.conf.example
Expand Up @@ -90,6 +90,14 @@
#enable_fog = true
# Enable a bit lower water surface; disable for speed (not quite optimized)
#new_style_water = false
# Constant volume liquids
#liquid_finite = false
# Update liquids every .. recommend for finite: 0.2
#liquid_update = 1.0
# When finite liquid: relax flowing blocks to source if level near max and N nearby source blocks, more realistic, but not true constant. values: 0,1,2,3,4 : 0 - disable, 1 - most aggresive
#liquid_relax = 1
# optimization: faster cave flood (and not true constant)
#liquid_fast_flood = 1
# Enable nice leaves; disable for speed
#new_style_leaves = true
# Enable smooth lighting with simple ambient occlusion;
Expand Down
36 changes: 34 additions & 2 deletions src/content_abm.cpp
Expand Up @@ -26,6 +26,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h"
#include "mapblock.h" // For getNodeBlockPos
#include "treegen.h" // For treegen::make_tree
#include "main.h" // for g_settings
#include "map.h"

#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
Expand Down Expand Up @@ -146,11 +147,42 @@ class MakeTreesFromSaplingsABM : public ActiveBlockModifier
}
};

class LiquidFlowABM : public ActiveBlockModifier
{
private:
std::set<std::string> contents;

public:
LiquidFlowABM(ServerEnvironment *env, INodeDefManager *nodemgr)
{
std::set<content_t> liquids;
nodemgr->getIds("group:liquid", liquids);
for(std::set<content_t>::const_iterator k = liquids.begin(); k != liquids.end(); k++)
contents.insert(nodemgr->get(*k).liquid_alternative_flowing);

}
virtual std::set<std::string> getTriggerContents()
{
return contents;
}
virtual float getTriggerInterval()
{ return 10.0; }
virtual u32 getTriggerChance()
{ return 10; }
virtual void trigger(ServerEnvironment *env, v3s16 p, MapNode n)
{
ServerMap *map = &env->getServerMap();
if (map->transforming_liquid_size() < 500)
map->transforming_liquid_add(p);
//if ((*map).m_transforming_liquid.size() < 500) (*map).m_transforming_liquid.push_back(p);
}
};

void add_legacy_abms(ServerEnvironment *env, INodeDefManager *nodedef)
{
env->addActiveBlockModifier(new GrowGrassABM());
env->addActiveBlockModifier(new RemoveGrassABM());
env->addActiveBlockModifier(new MakeTreesFromSaplingsABM());
if (g_settings->getBool("liquid_finite"))
env->addActiveBlockModifier(new LiquidFlowABM(env, nodedef));
}


4 changes: 2 additions & 2 deletions src/content_mapblock.cpp
Expand Up @@ -261,7 +261,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
level = (-0.5+node_liquid_level) * BS;
else if(n2.getContent() == c_flowing)
level = (-0.5 + ((float)(n2.param2&LIQUID_LEVEL_MASK)
+ 0.5) / 8.0 * node_liquid_level) * BS;
+ 0.5) / (float)LIQUID_LEVEL_SOURCE * node_liquid_level) * BS;

// Check node above neighbor.
// NOTE: This doesn't get executed if neighbor
Expand Down Expand Up @@ -324,7 +324,7 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
}
}
if(air_count >= 2)
cornerlevel = -0.5*BS;
cornerlevel = -0.5*BS+0.1;
else if(valid_count > 0)
cornerlevel /= valid_count;
corner_levels[i] = cornerlevel;
Expand Down
5 changes: 5 additions & 0 deletions src/defaultsettings.cpp
Expand Up @@ -206,6 +206,11 @@ void set_default_settings(Settings *settings)
//mapgen related things
settings->setDefault("mg_name", "v6");
settings->setDefault("water_level", "1");
settings->setDefault("liquid_finite", "false");
settings->setDefault("liquid_update", "1.0");
settings->setDefault("liquid_relax", "1");
settings->setDefault("liquid_fast_flood", "1");

settings->setDefault("chunksize", "5");
settings->setDefault("mg_flags", "trees, caves, v6_biome_blend");
settings->setDefault("mgv6_freq_desert", "0.45");
Expand Down

0 comments on commit 979ca23

Please sign in to comment.