]> git.lizzy.rs Git - dragonfireclient.git/blob - src/mapgen/mapgen_singlenode.cpp
Revert "Replace MyEventReceiver KeyList with std::unordered_set" (#10622)
[dragonfireclient.git] / src / mapgen / mapgen_singlenode.cpp
1 /*
2 Minetest
3 Copyright (C) 2013-2018 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2018 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5 Copyright (C) 2015-2018 paramat
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation; either version 2.1 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 */
21
22 #include "mapgen_singlenode.h"
23 #include "voxel.h"
24 #include "mapblock.h"
25 #include "mapnode.h"
26 #include "map.h"
27 #include "nodedef.h"
28 #include "voxelalgorithms.h"
29 #include "emerge.h"
30
31
32 MapgenSinglenode::MapgenSinglenode(MapgenParams *params, EmergeParams *emerge)
33         : Mapgen(MAPGEN_SINGLENODE, params, emerge)
34 {
35         const NodeDefManager *ndef = emerge->ndef;
36
37         c_node = ndef->getId("mapgen_singlenode");
38         if (c_node == CONTENT_IGNORE)
39                 c_node = CONTENT_AIR;
40
41         MapNode n_node(c_node);
42         set_light = (ndef->get(n_node).sunlight_propagates) ? LIGHT_SUN : 0x00;
43 }
44
45
46 //////////////////////// Map generator
47
48 void MapgenSinglenode::makeChunk(BlockMakeData *data)
49 {
50         // Pre-conditions
51         assert(data->vmanip);
52         assert(data->nodedef);
53         assert(data->blockpos_requested.X >= data->blockpos_min.X &&
54                 data->blockpos_requested.Y >= data->blockpos_min.Y &&
55                 data->blockpos_requested.Z >= data->blockpos_min.Z);
56         assert(data->blockpos_requested.X <= data->blockpos_max.X &&
57                 data->blockpos_requested.Y <= data->blockpos_max.Y &&
58                 data->blockpos_requested.Z <= data->blockpos_max.Z);
59
60         this->generating = true;
61         this->vm   = data->vmanip;
62         this->ndef = data->nodedef;
63
64         v3s16 blockpos_min = data->blockpos_min;
65         v3s16 blockpos_max = data->blockpos_max;
66
67         // Area of central chunk
68         v3s16 node_min = blockpos_min * MAP_BLOCKSIZE;
69         v3s16 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
70
71         blockseed = getBlockSeed2(node_min, data->seed);
72
73         MapNode n_node(c_node);
74
75         for (s16 z = node_min.Z; z <= node_max.Z; z++)
76         for (s16 y = node_min.Y; y <= node_max.Y; y++) {
77                 u32 i = vm->m_area.index(node_min.X, y, z);
78                 for (s16 x = node_min.X; x <= node_max.X; x++) {
79                         if (vm->m_data[i].getContent() == CONTENT_IGNORE)
80                                 vm->m_data[i] = n_node;
81                         i++;
82                 }
83         }
84
85         // Add top and bottom side of water to transforming_liquid queue
86         updateLiquid(&data->transforming_liquid, node_min, node_max);
87
88         // Set lighting
89         if ((flags & MG_LIGHT) && set_light == LIGHT_SUN)
90                 setLighting(LIGHT_SUN, node_min, node_max);
91
92         this->generating = false;
93 }
94
95
96 int MapgenSinglenode::getSpawnLevelAtPoint(v2s16 p)
97 {
98         return 0;
99 }