diff options
author | STRWarrior <niels.breuker@hotmail.nl> | 2015-04-19 19:45:18 +0200 |
---|---|---|
committer | STRWarrior <niels.breuker@hotmail.nl> | 2015-04-19 19:45:18 +0200 |
commit | e7542f676d1905e41b31b3c5b3d7108704529176 (patch) | |
tree | 6d6ce2ce0aa4a3ddce7ad8aab8dfd393345cd95d | |
parent | Added extra divide operator to Vector3. (diff) | |
download | cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar.gz cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar.bz2 cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar.lz cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar.xz cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.tar.zst cuberite-e7542f676d1905e41b31b3c5b3d7108704529176.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Generating/ComposableGenerator.cpp | 4 | ||||
-rw-r--r-- | src/Generating/FinishGen.cpp | 114 | ||||
-rw-r--r-- | src/Generating/FinishGen.h | 22 | ||||
-rw-r--r-- | src/World.cpp | 2 |
4 files changed, 140 insertions, 2 deletions
diff --git a/src/Generating/ComposableGenerator.cpp b/src/Generating/ComposableGenerator.cpp index 4a670b064..846e6fe12 100644 --- a/src/Generating/ComposableGenerator.cpp +++ b/src/Generating/ComposableGenerator.cpp @@ -347,6 +347,10 @@ void cComposableGenerator::InitFinishGens(cIniFile & a_IniFile) AString HeightDistrib = a_IniFile.GetValueSet ("Generator", "DungeonRoomsHeightDistrib", "0, 0; 10, 10; 11, 500; 40, 500; 60, 40; 90, 1"); m_FinishGens.push_back(cFinishGenPtr(new cDungeonRoomsFinisher(m_ShapeGen, Seed, GridSize, MaxSize, MinSize, HeightDistrib))); } + else if (NoCaseCompare(*itr, "GlowStone") == 0) + { + m_FinishGens.push_back(cFinishGenPtr(new cFinishGenGlowStone(Seed))); + } else if (NoCaseCompare(*itr, "Ice") == 0) { m_FinishGens.push_back(cFinishGenPtr(new cFinishGenIce)); diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 5839a4ccc..2a71f7629 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -180,6 +180,118 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a //////////////////////////////////////////////////////////////////////////////// +// cFinishGenGlowStone: + +void cFinishGenGlowStone::GenFinish(cChunkDesc & a_ChunkDesc) +{ + int ChunkX = a_ChunkDesc.GetChunkX(); + int ChunkZ = a_ChunkDesc.GetChunkZ(); + + // Change the number of attempts to create a vein depending on the maximum height of the chunk. A standard Nether could have 5 veins at most. + int NumGlowStone = m_Noise.IntNoise2DInt(ChunkX, ChunkZ) % a_ChunkDesc.GetMaxHeight() / 23; + + for (int i = 1; i <= NumGlowStone; i++) + { + // The maximum size for a string of glowstone can get 3 - 5 blocks long + int Size = 3 + m_Noise.IntNoise3DInt(ChunkX, i, ChunkZ) % 3; + + // Generate X/Z coordinates. + int X = Size + (m_Noise.IntNoise2DInt(i, Size) % (cChunkDef::Width - Size * 2)); + int Z = Size + (m_Noise.IntNoise2DInt(X, i) % (cChunkDef::Width - Size * 2)); + + int Height = a_ChunkDesc.GetHeight(X, Z); + for (int y = Height; y > Size; y--) + { + if (!cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(X, y, Z))) + { + // Current block isn't solid, bail out + continue; + } + + if (a_ChunkDesc.GetBlockType(X, y - 1, Z) != E_BLOCK_AIR) + { + // The block below isn't air, bail out + continue; + } + + if ((m_Noise.IntNoise3DInt(X, y, Z) % 100) < 95) + { + // Have a 5% chance of creating the glowstone + continue; + } + + TryPlaceGlowstone(a_ChunkDesc, X, y, Z, Size, 5 + m_Noise.IntNoise3DInt(X, y, Z) % 7); + break; + } + } +} + + + + + +void cFinishGenGlowStone::TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings) +{ + // The starting point of every glowstone string + Vector3i StartPoint = Vector3i(a_RelX, a_RelY, a_RelZ); + + // Array with possible directions for a string of glowstone to go to. + const Vector3i AvailableDirections[] = + { + { -1, 0, 0 }, { 1, 0, 0 }, + { 0, -1, 0 }, // Don't let the glowstone go up + { 0, 0, -1 }, { 0, 0, 1 }, + + // Diagonal direction. Only X or Z with Y. + // If all were changed the glowstone string looks awkward + { 0, -1, 1 }, { 1, -1, 0 }, + { 0, -1, -1 }, { -1, -1, 0 }, + + }; + + for (int i = 1; i <= a_NumStrings; i++) + { + // The current position of the string that is being generated + Vector3i CurrentPos = Vector3i(StartPoint); + + // A vector where the previous direction of a glowstone string is stored. + // This is used to make the strings change direction when going one block further + Vector3i PreviousDirection = Vector3i(); + + for (int j = 0; j < a_Size; j++) + { + Vector3i Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + int Attempts = 2; // multiply by 1 would make no difference, so multiply by 2 instead + + while (Direction.Equals(PreviousDirection)) + { + // To make the glowstone branches look better we want to make the direction change every time. + Direction = AvailableDirections[m_Noise.IntNoise3DInt(CurrentPos.x, CurrentPos.y * i * Attempts, CurrentPos.z) % ARRAYCOUNT(AvailableDirections)]; + Attempts++; + } + + // Update the previous direction variable + PreviousDirection = Direction; + + // Update the position of the glowstone string + CurrentPos += Direction; + if (cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z)) && (a_ChunkDesc.GetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z) != E_BLOCK_GLOWSTONE)) + { + // The glowstone hit something solid, and it wasn't glowstone. Stop the string. + break; + } + + // Place a glowstone block. + a_ChunkDesc.SetBlockType(CurrentPos.x, CurrentPos.y, CurrentPos.z, E_BLOCK_GLOWSTONE); + } + } +} + + + + + +//////////////////////////////////////////////////////////////////////////////// // cFinishGenTallGrass: void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc) @@ -523,7 +635,7 @@ void cFinishGenSoulsandRims::GenFinish(cChunkDesc & a_ChunkDesc) { // The current block is air. Let's bail ut. BLOCKTYPE Block = a_ChunkDesc.GetBlockType(x, y, z); - if (Block == E_BLOCK_AIR) + if (Block != E_BLOCK_NETHERRACK) { continue; } diff --git a/src/Generating/FinishGen.h b/src/Generating/FinishGen.h index 70696c4f8..02f3b98ae 100644 --- a/src/Generating/FinishGen.h +++ b/src/Generating/FinishGen.h @@ -70,6 +70,28 @@ protected: +class cFinishGenGlowStone : + public cFinishGen +{ +public: + cFinishGenGlowStone(int a_Seed) : + m_Seed(a_Seed), + m_Noise(a_Seed) + { + } + +protected: + cNoise m_Noise; + int m_Seed; + + void TryPlaceGlowstone(cChunkDesc & a_ChunkDesc, int a_RelX, int a_RelY, int a_RelZ, int a_Size, int a_NumStrings); + virtual void GenFinish(cChunkDesc & a_ChunkDesc) override; +} ; + + + + + class cFinishGenTallGrass : public cFinishGen { diff --git a/src/World.cpp b/src/World.cpp index 4480013c3..a088f6eb1 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -812,7 +812,7 @@ void cWorld::InitialiseGeneratorDefaults(cIniFile & a_IniFile) a_IniFile.GetValueSet("Generator", "HeightGen", "Flat"); a_IniFile.GetValueSet("Generator", "FlatHeight", "128"); a_IniFile.GetValueSet("Generator", "CompositionGen", "Nether"); - a_IniFile.GetValueSet("Generator", "Finishers", "SoulsandRims, WormNestCaves, BottomLava, LavaSprings, NetherClumpFoliage, NetherOreNests, NetherForts, PreSimulator"); + a_IniFile.GetValueSet("Generator", "Finishers", "SoulsandRims, WormNestCaves, BottomLava, LavaSprings, NetherClumpFoliage, NetherOreNests, NetherForts, GlowStone, PreSimulator"); a_IniFile.GetValueSet("Generator", "BottomLavaHeight", "30"); break; } |