]> git.lizzy.rs Git - minetest.git/blobdiff - src/mapgen/treegen.cpp
Store `MapEditEvent` blocks in a vector (#13071)
[minetest.git] / src / mapgen / treegen.cpp
index 4c351fcefae0ef087ced97e67f3e04b64f72f2a1..2c12664312b69de1bd293468373030589c040947 100644 (file)
@@ -25,7 +25,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "util/numeric.h"
 #include "map.h"
 #include "mapblock.h"
-#include "serverenvironment.h"
 #include "nodedef.h"
 #include "treegen.h"
 #include "voxelalgorithms.h"
@@ -44,6 +43,12 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
        MapNode treenode(ndef->getId("mapgen_tree"));
        MapNode leavesnode(ndef->getId("mapgen_leaves"));
        MapNode applenode(ndef->getId("mapgen_apple"));
+       if (treenode == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_tree' is invalid!" << std::endl;
+       if (leavesnode == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_leaves' is invalid!" << std::endl;
+       if (applenode == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_apple' is invalid!" << std::endl;
 
        PseudoRandom pr(seed);
        s16 trunk_h = pr.range(4, 5);
@@ -114,10 +119,9 @@ void make_tree(MMVManip &vmanip, v3s16 p0, bool is_apple_tree,
 
 
 // L-System tree LUA spawner
-treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
+treegen::error spawn_ltree(ServerMap *map, v3s16 p0,
        const NodeDefManager *ndef, const TreeDef &tree_definition)
 {
-       ServerMap *map = &env->getServerMap();
        std::map<v3s16, MapBlock*> modified_blocks;
        MMVManip vmanip(map);
        v3s16 tree_blockp = getNodeBlockPos(p0);
@@ -133,9 +137,8 @@ treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
        // Send a MEET_OTHER event
        MapEditEvent event;
        event.type = MEET_OTHER;
-       for (auto &modified_block : modified_blocks)
-               event.modified_blocks.insert(modified_block.first);
-       map->dispatchEvent(&event);
+       event.setModifiedBlocks(modified_blocks);
+       map->dispatchEvent(event);
        return SUCCESS;
 }
 
@@ -144,7 +147,6 @@ treegen::error spawn_ltree(ServerEnvironment *env, v3s16 p0,
 treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
        const NodeDefManager *ndef, TreeDef tree_definition)
 {
-       MapNode dirtnode(ndef->getId("mapgen_dirt"));
        s32 seed;
        if (tree_definition.explicit_seed)
                seed = tree_definition.seed + 14002;
@@ -222,43 +224,43 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
                axiom = temp;
        }
 
-       //make sure tree is not floating in the air
+       // Add trunk nodes below a wide trunk to avoid gaps when tree is on sloping ground
        if (tree_definition.trunk_type == "double") {
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X + 1, position.Y - 1, position.Z),
-                       dirtnode
+                       tree_definition
                );
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X, position.Y - 1, position.Z + 1),
-                       dirtnode
+                       tree_definition
                );
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X + 1, position.Y - 1, position.Z + 1),
-                       dirtnode
+                       tree_definition
                );
        } else if (tree_definition.trunk_type == "crossed") {
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X + 1, position.Y - 1, position.Z),
-                       dirtnode
+                       tree_definition
                );
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X - 1, position.Y - 1, position.Z),
-                       dirtnode
+                       tree_definition
                );
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X, position.Y - 1, position.Z + 1),
-                       dirtnode
+                       tree_definition
                );
-               tree_node_placement(
+               tree_trunk_placement(
                        vmanip,
                        v3f(position.X, position.Y - 1, position.Z - 1),
-                       dirtnode
+                       tree_definition
                );
        }
 
@@ -365,7 +367,7 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
                                        !tree_definition.thin_branches)) {
                                tree_trunk_placement(
                                        vmanip,
-                                       v3f(position.X +, position.Y, position.Z),
+                                       v3f(position.X + 1, position.Y, position.Z),
                                        tree_definition
                                );
                                tree_trunk_placement(
@@ -403,7 +405,8 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
                                        v3f(position.X, position.Y, position.Z - 1),
                                        tree_definition
                                );
-                       } if (!stack_orientation.empty()) {
+                       }
+                       if (!stack_orientation.empty()) {
                                s16 size = 1;
                                for (x = -size; x <= size; x++)
                                for (y = -size; y <= size; y++)
@@ -524,19 +527,6 @@ treegen::error make_ltree(MMVManip &vmanip, v3s16 p0,
 }
 
 
-void tree_node_placement(MMVManip &vmanip, v3f p0, MapNode node)
-{
-       v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
-       if (!vmanip.m_area.contains(p1))
-               return;
-       u32 vi = vmanip.m_area.index(p1);
-       if (vmanip.m_data[vi].getContent() != CONTENT_AIR
-                       && vmanip.m_data[vi].getContent() != CONTENT_IGNORE)
-               return;
-       vmanip.m_data[vmanip.m_area.index(p1)] = node;
-}
-
-
 void tree_trunk_placement(MMVManip &vmanip, v3f p0, TreeDef &tree_definition)
 {
        v3s16 p1 = v3s16(myround(p0.X), myround(p0.Y), myround(p0.Z));
@@ -662,6 +652,10 @@ void make_jungletree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
                c_tree = ndef->getId("mapgen_tree");
        if (c_leaves == CONTENT_IGNORE)
                c_leaves = ndef->getId("mapgen_leaves");
+       if (c_tree == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_jungletree' is invalid!" << std::endl;
+       if (c_leaves == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_jungleleaves' is invalid!" << std::endl;
 
        MapNode treenode(c_tree);
        MapNode leavesnode(c_leaves);
@@ -765,6 +759,10 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
                c_leaves = ndef->getId("mapgen_leaves");
        if (c_snow == CONTENT_IGNORE)
                c_snow = CONTENT_AIR;
+       if (c_tree == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_pine_tree' is invalid!" << std::endl;
+       if (c_leaves == CONTENT_IGNORE)
+               errorstream << "Treegen: Mapgen alias 'mapgen_pine_needles' is invalid!" << std::endl;
 
        MapNode treenode(c_tree);
        MapNode leavesnode(c_leaves);
@@ -807,7 +805,7 @@ void make_pine_tree(MMVManip &vmanip, v3s16 p0, const NodeDefManager *ndef,
                dev--;
        }
 
-       // Centre top nodes
+       // Center top nodes
        leaves_d[leaves_a.index(v3s16(0, 1, 0))] = 1;
        leaves_d[leaves_a.index(v3s16(0, 2, 0))] = 1;
        leaves_d[leaves_a.index(v3s16(0, 3, 0))] = 2;