123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #include "GrasslandBiom.h"
- #include "BasicBlocks.h"
- #include "BlockType.h"
- #include "Chunk.h"
- #include "Constants.h"
- #include "FastNoiseLite.h"
- #include "FastNoiseWrapper.h"
- #include "NoBlock.h"
- #include "TreeTemplate.h"
- #include "RandNoise.h"
- GrasslandBiom::GrasslandBiom()
- : BiomGenerator()
- {
- addTemplateGenerator(new TreeTemplate(0.002f,
- BlockTypeEnum::WOOD_BIRCH,
- BlockTypeEnum::LEAVES_WOOD_BIRCH,
- 8,
- 15));
- addTemplateGenerator(new TreeTemplate(0.001f,
- BlockTypeEnum::WOOD_BEECH,
- BlockTypeEnum::LEAVES_WOOD_BEECH,
- 8,
- 13));
- addTemplateGenerator(new TreeTemplate(0.0005f,
- BlockTypeEnum::WOOD_OAK,
- BlockTypeEnum::LEAVES_WOOD_OAK,
- 10,
- 15));
- addTemplateGenerator(new TreeTemplate(0.00025f,
- BlockTypeEnum::WOOD_PINE,
- BlockTypeEnum::LEAVES_WOOD_PINE,
- 15,
- 24));
- heightNoise = 0;
- undergroundDirdNoise = 0;
- surfaceSandNoise = 0;
- undergroundGravelNoise = 0;
- grassNoise = 0;
- }
- GrasslandBiom::~GrasslandBiom()
- {
- if (heightNoise) heightNoise->release();
- if (grassNoise) grassNoise->release();
- if (undergroundGravelNoise) undergroundGravelNoise->release();
- if (undergroundDirdNoise) undergroundDirdNoise->release();
- }
- Framework::Either<Block*, int> GrasslandBiom::generateAboveSurfaceBlock(int x,
- int y,
- int z,
- int dimensionId,
- int surfaceHeight,
- Chunk* partialGeneratedChunk)
- {
- int cx = x % CHUNK_SIZE;
- int cy = y % CHUNK_SIZE;
- if (cx < 0) cx += CHUNK_SIZE;
- if (cy < 0) cy += CHUNK_SIZE;
- auto below
- = partialGeneratedChunk->zBlockAt(Framework::Vec3<int>(cx, cy, z - 1));
- if ((below.isA()
- && below.getA()->zBlockType()->getId() == BlockTypeEnum::DIRT)
- || (below.isB() && below.getB() == BlockTypeEnum::DIRT))
- {
- if (grassNoise->getNoise((double)x, (double)y, (double)z) > 0.75)
- {
- return BlockTypeEnum::GRASS;
- }
- }
- return BlockTypeEnum::AIR;
- }
- Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(
- int x, int y, int z, int dimensionId)
- {
- if (surfaceSandNoise->getNoise((double)x, (double)y, (double)z) < 0.35)
- {
- return BlockTypeEnum::SAND;
- }
- if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
- < 0.35)
- {
- return BlockTypeEnum::GRAVEL;
- }
- return BlockTypeEnum::DIRT;
- }
- Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(
- int x, int y, int z, int dimensionId)
- {
- if (undergroundDirdNoise->getNoise((double)x, (double)y, (double)z) < 0.35)
- {
- return BlockTypeEnum::DIRT;
- }
- if (undergroundGravelNoise->getNoise((double)x, (double)y, (double)z)
- < 0.35)
- {
- return BlockTypeEnum::GRAVEL;
- }
- return BlockTypeEnum::STONE;
- }
- Framework::Either<Block*, int> GrasslandBiom::generateCaveBlock(
- int x, int y, int z, int dimensionId)
- {
- return BlockTypeEnum::AIR;
- }
- Framework::Either<Block*, int> GrasslandBiom::generateUnderWaterBlock(int x,
- int y,
- int z,
- int dimensionId,
- int surfaceHeight,
- Chunk* partialGeneratedChunk)
- {
- return StaticRegistry<BlockType>::INSTANCE.zElement(BlockTypeEnum::WATER)
- ->createBlockAt(Framework::Vec3<int>(x, y, z), dimensionId, 0);
- }
- void GrasslandBiom::setSeed(int seed)
- {
- BiomGenerator::setSeed(seed);
- if (heightNoise) heightNoise->release();
- FastNoiseLite* noise = new FastNoiseLite(seed);
- noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
- FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
- wrapper->setMultiplier(0.2f);
- heightNoise = wrapper;
- noise = new FastNoiseLite(seed);
- noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
- noise->SetFrequency(0.15f);
- undergroundDirdNoise = new FastNoiseWrapper(noise, seed);
- noise = new FastNoiseLite(seed + 1);
- noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
- noise->SetFrequency(0.125f);
- undergroundGravelNoise = new FastNoiseWrapper(noise, seed + 1);
- noise = new FastNoiseLite(seed + 2);
- noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
- noise->SetFrequency(0.1f);
- surfaceSandNoise = new FastNoiseWrapper(noise, seed + 2);
- grassNoise = new RandNoise(seed + 3);
- }
- Noise* GrasslandBiom::zHeightMapNoise()
- {
- return heightNoise;
- }
|