3 Copyright (C) 2010-2013 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"
28 #include "settings.h" // For g_settings
29 #include "main.h" // For g_profiler
32 //////////////////////// Mapgen Singlenode parameter read/write
34 bool MapgenSinglenodeParams::readParams(Settings *settings) {
39 void MapgenSinglenodeParams::writeParams(Settings *settings) {
42 ///////////////////////////////////////////////////////////////////////////////
44 MapgenSinglenode::MapgenSinglenode(int mapgenid, MapgenSinglenodeParams *params) {
48 MapgenSinglenode::~MapgenSinglenode() {
51 //////////////////////// Map generator
53 void MapgenSinglenode::makeChunk(BlockMakeData *data) {
55 assert(data->nodedef);
56 assert(data->blockpos_requested.X >= data->blockpos_min.X &&
57 data->blockpos_requested.Y >= data->blockpos_min.Y &&
58 data->blockpos_requested.Z >= data->blockpos_min.Z);
59 assert(data->blockpos_requested.X <= data->blockpos_max.X &&
60 data->blockpos_requested.Y <= data->blockpos_max.Y &&
61 data->blockpos_requested.Z <= data->blockpos_max.Z);
63 this->generating = true;
64 this->vm = data->vmanip;
65 this->ndef = data->nodedef;
67 v3s16 blockpos_min = data->blockpos_min;
68 v3s16 blockpos_max = data->blockpos_max;
70 // Area of central chunk
71 v3s16 node_min = blockpos_min*MAP_BLOCKSIZE;
72 v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);
74 content_t c_node = ndef->getId("mapgen_singlenode");
75 if(c_node == CONTENT_IGNORE)
77 for(s16 z=node_min.Z; z<=node_max.Z; z++)
78 for(s16 y=node_min.Y; y<=node_max.Y; y++)
79 for(s16 x=node_min.X; x<=node_max.X; x++)
81 data->vmanip->setNode(v3s16(x,y,z), MapNode(c_node));
84 // Add top and bottom side of water to transforming_liquid queue
85 updateLiquid(&data->transforming_liquid, node_min, node_max);
88 calcLighting(node_min, node_max);
90 this->generating = false;
93 int MapgenSinglenode::getGroundLevelAtPoint(v2s16 p) {