3 Copyright (C) 2010-2015 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "mapgen_singlenode.h"
26 #include "voxelalgorithms.h"
30 MapgenSinglenode::MapgenSinglenode(int mapgenid,
31 MapgenParams *params, EmergeManager *emerge)
32 : Mapgen(mapgenid, params, emerge)
34 flags = params->flags;
36 INodeDefManager *ndef = emerge->ndef;
38 c_node = ndef->getId("mapgen_singlenode");
39 if (c_node == CONTENT_IGNORE)
42 MapNode n_node(c_node);
43 set_light = (ndef->get(n_node).sunlight_propagates) ? LIGHT_SUN : 0x00;
47 MapgenSinglenode::~MapgenSinglenode()
52 //////////////////////// Map generator
54 void MapgenSinglenode::makeChunk(BlockMakeData *data)
58 assert(data->nodedef);
59 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
60 data->blockpos_requested.Y >= data->blockpos_min.Y &&
61 data->blockpos_requested.Z >= data->blockpos_min.Z);
62 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
63 data->blockpos_requested.Y <= data->blockpos_max.Y &&
64 data->blockpos_requested.Z <= data->blockpos_max.Z);
66 this->generating = true;
67 this->vm = data->vmanip;
68 this->ndef = data->nodedef;
70 v3s16 blockpos_min = data->blockpos_min;
71 v3s16 blockpos_max = data->blockpos_max;
73 // Area of central chunk
74 v3s16 node_min = blockpos_min * MAP_BLOCKSIZE;
75 v3s16 node_max = (blockpos_max + v3s16(1, 1, 1)) * MAP_BLOCKSIZE - v3s16(1, 1, 1);
77 blockseed = getBlockSeed2(node_min, data->seed);
79 MapNode n_node(c_node);
81 for (s16 z = node_min.Z; z <= node_max.Z; z++)
82 for (s16 y = node_min.Y; y <= node_max.Y; y++) {
83 u32 i = vm->m_area.index(node_min.X, y, z);
84 for (s16 x = node_min.X; x <= node_max.X; x++) {
85 if (vm->m_data[i].getContent() == CONTENT_IGNORE)
86 vm->m_data[i] = n_node;
91 // Add top and bottom side of water to transforming_liquid queue
92 updateLiquid(&data->transforming_liquid, node_min, node_max);
95 if ((flags & MG_LIGHT) && set_light == LIGHT_SUN)
96 setLighting(LIGHT_SUN, node_min, node_max);
98 this->generating = false;
102 int MapgenSinglenode::getSpawnLevelAtPoint(v2s16 p)