Cuberite
A lightweight, fast and extensible game server for Minecraft
ChunkGenerator.cpp
Go to the documentation of this file.
1 
2 #include "Globals.h"
3 
4 #include "ChunkGenerator.h"
5 #include "ChunkDesc.h"
6 #include "ComposableGenerator.h"
7 #include "Noise3DGenerator.h"
8 #include "../IniFile.h"
9 #include "../FastRandom.h"
10 
11 
12 
13 
14 
16 {
17  // Get the seed; create a new one and log it if not found in the INI file:
18  if (a_IniFile.HasValue("Seed", "Seed"))
19  {
20  m_Seed = a_IniFile.GetValueI("Seed", "Seed");
21  }
22  else
23  {
25  LOGINFO("Chosen a new random seed for world: %d", m_Seed);
26  a_IniFile.SetValueI("Seed", "Seed", m_Seed);
27  }
28 
29  m_Dimension = StringToDimension(a_IniFile.GetValue("General", "Dimension", "Overworld"));
30 }
31 
32 
33 
34 
35 
36 std::unique_ptr<cChunkGenerator> cChunkGenerator::CreateFromIniFile(cIniFile & a_IniFile)
37 {
38  // Get the generator engine based on the INI file settings:
39  std::unique_ptr<cChunkGenerator> res;
40  AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable");
41  if (NoCaseCompare(GeneratorName, "Noise3D") == 0)
42  {
43  res.reset(new cNoise3DGenerator());
44  }
45  else
46  {
47  if (NoCaseCompare(GeneratorName, "composable") != 0)
48  {
49  LOGWARN("[Generator]::Generator value \"%s\" not recognized, using \"Composable\".", GeneratorName.c_str());
50  }
51  res.reset(new cComposableGenerator());
52  }
53 
54  if (res == nullptr)
55  {
56  LOGERROR("Generator could not start, aborting the server");
57  return nullptr;
58  }
59 
60  res->Initialize(a_IniFile);
61  return res;
62 }
63 
64 
65 
66 
67 
68 EMCSBiome cChunkGenerator::GetBiomeAt(int a_BlockX, int a_BlockZ)
69 {
70  cChunkDef::BiomeMap Biomes;
71  int Y = 0;
72  int ChunkX, ChunkZ;
73  cChunkDef::AbsoluteToRelative(a_BlockX, Y, a_BlockZ, ChunkX, ChunkZ);
74  GenerateBiomes({ChunkX, ChunkZ}, Biomes);
75  return cChunkDef::GetBiome(Biomes, a_BlockX, a_BlockZ);
76 }
77 
78 
79 
80 
EMCSBiome
Biome IDs The first batch corresponds to the clientside biomes, used by MineCraft.
Definition: BiomeDef.h:18
eDimension StringToDimension(const AString &a_DimensionString)
Translates a dimension string to dimension enum.
Definition: Defines.cpp:194
MTRand & GetRandomProvider()
Returns the current thread's random number source.
Definition: FastRandom.cpp:12
void LOGERROR(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:73
#define LOGWARN
Definition: LoggerSimple.h:88
void LOGINFO(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:61
int NoCaseCompare(const AString &s1, const AString &s2)
Case-insensitive string comparison.
std::string AString
Definition: StringUtils.h:11
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
Definition: ChunkDef.h:147
static EMCSBiome GetBiome(const BiomeMap &a_BiomeMap, int a_X, int a_Z)
Definition: ChunkDef.h:319
EMCSBiome BiomeMap[Width *Width]
The type used for any biomemap operations and storage inside Cuberite, using Cuberite biomes (need no...
Definition: ChunkDef.h:137
IntType RandInt(IntType a_Min, IntType a_Max)
Return a random IntType in the range [a_Min, a_Max].
Definition: FastRandom.h:78
virtual EMCSBiome GetBiomeAt(int a_BlockX, int a_BlockZ)
Returns the biome at the specified coords.
virtual void Initialize(cIniFile &a_IniFile)
Called to initialize the generator on server startup.
eDimension m_Dimension
The dimension, read from the INI file.
virtual void GenerateBiomes(cChunkCoords a_ChunkCoords, cChunkDef::BiomeMap &a_BiomeMap)=0
Generates the biomes for the specified chunk.
int m_Seed
The main seed, read from the INI file, used for the entire generator.
static std::unique_ptr< cChunkGenerator > CreateFromIniFile(cIniFile &a_IniFile)
Creates and initializes the entire generator based on the settings in the INI file.
bool HasValue(const AString &a_KeyName, const AString &a_ValueName) const override
Returns true iff the specified value exists.
Definition: IniFile.cpp:656
AString GetValue(const AString &keyname, const AString &valuename, const AString &defValue="") const override
Get the value at the specified key and value, returns defValue on failure.
Definition: IniFile.cpp:485
int GetValueI(const AString &keyname, const AString &valuename, const int defValue=0) const
Definition: IniFile.cpp:506
bool SetValueI(const AString &a_KeyName, const AString &a_ValueName, const int a_Value, const bool a_CreateIfNotExists=true) override
Definition: IniFile.cpp:445
AString GetValueSet(const AString &keyname, const AString &valuename, const AString &defValue="") override
Gets the value; if not found, write the default to the repository.
Definition: IniFile.cpp:526