Răsfoiți Sursa

spawn grass only on dirt blocks

Kolja Strohm 2 ani în urmă
părinte
comite
af3e39142b

+ 2 - 1
FactoryCraft/BiomGenerator.h

@@ -20,7 +20,8 @@ protected:
 public:
     BiomGenerator();
     virtual Framework::Either<Block*, int> generateAboveSurfaceBlock(
-        int x, int y, int z, int surfaceHeight) = 0;
+        int x, int y, int z, int surfaceHeight, Chunk* partialGeneratedChunk)
+        = 0;
     virtual Framework::Either<Block*, int> generateSurfaceBlock(
         int x, int y, int z)
         = 0;

+ 2 - 2
FactoryCraft/DimensionGenerator.cpp

@@ -222,7 +222,7 @@ Chunk* DimensionGenerator::generateChunk(int centerX, int centerY)
                     else if (z >= height)
                     {
                         generated = biom->generateAboveSurfaceBlock(
-                            x + centerX, y + centerY, z, height);
+                            x + centerX, y + centerY, z, height, chunk);
                     }
                     zm.messungEnde();
                     blockGenTime += zm.getSekunden();
@@ -291,7 +291,7 @@ Framework::Either<Block*, int> DimensionGenerator::generateBlock(
     if (location.z >= height)
     {
         return biom->generateAboveSurfaceBlock(
-            location.x, location.x, location.z, height);
+            location.x, location.x, location.z, height, Game::INSTANCE->zDimension(getDimensionId())->zChunk(Game::INSTANCE->getChunkCenter(location.x, location.y)));
     }
     return BlockTypeEnum::AIR;
 }

+ 13 - 4
FactoryCraft/GrasslandBiom.cpp

@@ -6,6 +6,8 @@
 #include "FastNoiseWrapper.h"
 #include "NoBlock.h"
 #include "TreeTemplate.h"
+#include "Chunk.h"
+#include "Constants.h"
 
 GrasslandBiom::GrasslandBiom()
     : BiomGenerator()
@@ -42,11 +44,18 @@ GrasslandBiom::~GrasslandBiom()
 }
 
 Framework::Either<Block*, int> GrasslandBiom::generateAboveSurfaceBlock(
-    int x, int y, int z, int surfaceHeight)
+    int x, int y, int z, int surfaceHeight, Chunk* partialGeneratedChunk)
 {
-    if (z > surfaceHeight)
-        return BlockTypeEnum::AIR;
-    return BlockTypeEnum::GRASS;
+    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))
+        return BlockTypeEnum::GRASS;
+    return BlockTypeEnum::AIR;
 }
 
 Framework::Either<Block*, int> GrasslandBiom::generateSurfaceBlock(

+ 1 - 1
FactoryCraft/GrasslandBiom.h

@@ -16,7 +16,7 @@ public:
     GrasslandBiom();
     ~GrasslandBiom();
     Framework::Either<Block*, int> generateAboveSurfaceBlock(
-        int x, int y, int z, int surfaceHeight) override;
+        int x, int y, int z, int surfaceHeight, Chunk *partialGeneratedChunk) override;
     Framework::Either<Block*, int> generateSurfaceBlock(
         int x, int y, int z) override;
     Framework::Either<Block*, int> generateBelowSurfaceBlock(