3 Copyright (C) 2013-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2013-2016 kwolekr, Ryan Kwolek <kwolekr@minetest.net>
5 Copyright (C) 2015-2017 paramat
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.
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.
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.
22 #include "mapgen_singlenode.h"
28 #include "voxelalgorithms.h"
32 MapgenSinglenode::MapgenSinglenode(int mapgenid,
33 MapgenParams *params, EmergeManager *emerge)
34 : Mapgen(mapgenid, params, emerge)
36 flags = params->flags;
38 INodeDefManager *ndef = emerge->ndef;
40 c_node = ndef->getId("mapgen_singlenode");
41 if (c_node == CONTENT_IGNORE)
44 MapNode n_node(c_node);
45 set_light = (ndef->get(n_node).sunlight_propagates) ? LIGHT_SUN : 0x00;
49 MapgenSinglenode::~MapgenSinglenode()
54 //////////////////////// Map generator
56 void MapgenSinglenode::makeChunk(BlockMakeData *data)
60 assert(data->nodedef);
61 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
62 data->blockpos_requested.Y >= data->blockpos_min.Y &&
63 data->blockpos_requested.Z >= data->blockpos_min.Z);
64 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
65 data->blockpos_requested.Y <= data->blockpos_max.Y &&
66 data->blockpos_requested.Z <= data->blockpos_max.Z);
68 this->generating = true;
69 this->vm = data->vmanip;
70 this->ndef = data->nodedef;
72 v3s16 blockpos_min = data->blockpos_min;
73 v3s16 blockpos_max = data->blockpos_max;
75 // Area of central chunk
76 v3s16 node_min = blockpos_min * MAP_BLOCKSIZE;
77 v3s16 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
79 blockseed = getBlockSeed2(node_min, data->seed);
81 MapNode n_node(c_node);
83 for (s16 z = node_min.Z; z <= node_max.Z; z++)
84 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
85 u32 i = vm->m_area.index(node_min.X, y, z);
86 for (s16 x = node_min.X; x <= node_max.X; x++) {
87 if (vm->m_data[i].getContent() == CONTENT_IGNORE)
88 vm->m_data[i] = n_node;
93 // Add top and bottom side of water to transforming_liquid queue
94 updateLiquid(&data->transforming_liquid, node_min, node_max);
97 if ((flags & MG_LIGHT) && set_light == LIGHT_SUN)
98 setLighting(LIGHT_SUN, node_min, node_max);
100 this->generating = false;
104 int MapgenSinglenode::getSpawnLevelAtPoint(v2s16 p)