GrasslandBiom.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "GrasslandBiom.h"
  2. #include "BlockType.h"
  3. #include "BasicBlocks.h"
  4. #include "FastNoiseLite.h"
  5. #include "FastNoiseWrapper.h"
  6. #include "TreeTemplate.h"
  7. #include "NoBlock.h"
  8. GrasslandBiom::GrasslandBiom()
  9. : BiomGenerator()
  10. {
  11. addTemplateGenerator(new TreeTemplate(0.02f, BirchBlockType::INSTANCE, BirchLeavesBlockType::INSTANCE, 8, 15));
  12. addTemplateGenerator(new TreeTemplate(0.01f, BeechBlockType::INSTANCE, BeechLeavesBlockType::INSTANCE, 8, 13));
  13. addTemplateGenerator(new TreeTemplate(0.005f, OakBlockType::INSTANCE, OakLeavesBlockType::INSTANCE, 10, 15));
  14. addTemplateGenerator(new TreeTemplate(0.0025f, PineBlockType::INSTANCE, PineLeavesBlockType::INSTANCE, 15, 24));
  15. heightNoise = 0;
  16. }
  17. GrasslandBiom::~GrasslandBiom()
  18. {
  19. if (heightNoise)
  20. heightNoise->release();
  21. }
  22. Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(int x, int y, int z)
  23. {
  24. if (((float)rand() / (float)RAND_MAX) < 0.05f) // TODO: use random noise
  25. return CobbleBlockType::ID;
  26. return DirtBlockType::ID;
  27. }
  28. Framework::Either<Block*, int> GrasslandBiom::generateBelowSurfaceBlock(int x, int y, int z)
  29. {
  30. return StoneBlockType::ID;
  31. }
  32. Framework::Either<Block*, int> GrasslandBiom::generateCaveBlock(int x, int y, int z)
  33. {
  34. return AirBlockBlockType::ID;
  35. }
  36. Noise* GrasslandBiom::zHeightMapNoise(int seed)
  37. {
  38. if (heightNoise)
  39. return heightNoise;
  40. FastNoiseLite* noise = new FastNoiseLite(seed);
  41. noise->SetNoiseType(FastNoiseLite::NoiseType::NoiseType_ValueCubic);
  42. FastNoiseWrapper* wrapper = new FastNoiseWrapper(noise, seed);
  43. wrapper->setMultiplier(0.2f);
  44. heightNoise = wrapper;
  45. return heightNoise;
  46. }