pull/12/head
valoeghese 2020-02-28 20:23:27 +13:00
parent 3f2738ac1a
commit baa863d6e1
10 changed files with 65 additions and 12 deletions

View File

@ -9,7 +9,7 @@ import com.github.halotroop.litecraft.screens.TitleScreen;
import com.github.halotroop.litecraft.types.block.Blocks;
import com.github.halotroop.litecraft.util.RelativeDirection;
import com.github.halotroop.litecraft.world.World;
import com.github.halotroop.litecraft.world.gen.Dimensions;
import com.github.halotroop.litecraft.world.dimension.Dimensions;
import com.github.hydos.ginger.engine.api.*;
import com.github.hydos.ginger.engine.api.game.*;
import com.github.hydos.ginger.engine.cameras.*;

View File

@ -7,7 +7,7 @@ import org.joml.Vector3f;
import com.github.halotroop.litecraft.Litecraft;
import com.github.halotroop.litecraft.world.*;
import com.github.halotroop.litecraft.world.gen.Dimension;
import com.github.halotroop.litecraft.world.dimension.Dimension;
import com.github.hydos.ginger.engine.cameras.Camera;
import com.github.hydos.ginger.engine.elements.objects.Player;

View File

@ -57,5 +57,8 @@ public class Block
public static final Block getBlock(String identifier)
{ return IDENTIFIER_TO_BLOCK.get(identifier); }
public static final Block getBlockOrAir(String identifier)
{ return IDENTIFIER_TO_BLOCK.getOrDefault(identifier, Blocks.AIR); }
private static final Map<String, Block> IDENTIFIER_TO_BLOCK = new HashMap<>();
}

View File

@ -8,6 +8,11 @@ public final class OctaveSimplexNoise
private double clamp;
private double spread, amplitudeLow, amplitudeHigh;
public OctaveSimplexNoise(Random rand, int octaves)
{
this(rand, octaves, 1D, 1D, 1D);
}
public OctaveSimplexNoise(Random rand, int octaves, double spread, double amplitudeHigh, double amplitudeLow)
{
this.samplers = new SimplexNoise[octaves];
@ -21,12 +26,26 @@ public final class OctaveSimplexNoise
public double sample(double x, double y)
{
double amplFreq = 0.5D;
double amplSpread = 0.5D;
double result = 0;
for (SimplexNoise sampler : this.samplers)
{
result += (amplFreq * sampler.sample(x / (amplFreq * this.spread), y / (amplFreq * this.spread)));
amplFreq *= 0.5D;
result += (amplSpread * sampler.sample(x / (amplSpread * this.spread), y / (amplSpread * this.spread)));
amplSpread *= 0.5D;
}
result = result * this.clamp;
return result > 0 ? result * this.amplitudeHigh : result * this.amplitudeLow;
}
public double sample(double x, double y, double z)
{
double amplSpread = 0.5D;
double result = 0;
for (SimplexNoise sampler : this.samplers)
{
double divisor = amplSpread * this.spread;
result += (amplSpread * sampler.sample(x / divisor, y / divisor, z / divisor));
amplSpread *= 0.5D;
}
result = result * this.clamp;
return result > 0 ? result * this.amplitudeHigh : result * this.amplitudeLow;

View File

@ -165,7 +165,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
}
else
{
palette.put(intIdCache, Block.getBlock((String) o));
palette.put(intIdCache, Block.getBlockOrAir((String) o));
readInt = true;
}
}

View File

@ -8,6 +8,7 @@ import org.joml.Vector3f;
import com.github.halotroop.litecraft.save.LitecraftSave;
import com.github.halotroop.litecraft.types.block.Block;
import com.github.halotroop.litecraft.world.block.BlockRenderer;
import com.github.halotroop.litecraft.world.dimension.Dimension;
import com.github.halotroop.litecraft.world.gen.*;
import com.github.hydos.ginger.engine.elements.objects.Player;
import com.github.hydos.ginger.engine.obj.ModelLoader;

View File

@ -1,7 +1,9 @@
package com.github.halotroop.litecraft.world.gen;
package com.github.halotroop.litecraft.world.dimension;
import java.util.*;
import com.github.halotroop.litecraft.world.gen.*;
import it.unimi.dsi.fastutil.ints.*;
public abstract class Dimension<T extends ChunkGenerator>

View File

@ -1,4 +1,6 @@
package com.github.halotroop.litecraft.world.gen;
package com.github.halotroop.litecraft.world.dimension;
import com.github.halotroop.litecraft.world.gen.*;
public final class Dimensions
{

View File

@ -10,11 +10,14 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
{
public OverworldChunkGenerator(long seed, int dimension)
{
this.noise = new OctaveSimplexNoise(new Random(seed), 3, 250.0, 35.0, 10.0);
Random rand = new Random(seed);
this.noise = new OctaveSimplexNoise(rand, 3, 250.0, 35.0, 10.0);
this.stoneNoise = new OctaveSimplexNoise(rand, 1);
this.dimension = dimension;
}
private final OctaveSimplexNoise noise;
private final OctaveSimplexNoise stoneNoise;
private final int dimension;
@Override
@ -26,19 +29,40 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
double totalX = x + chunk.chunkStartX;
for (int z = 0; z < CHUNK_SIZE; z++)
{
int height = (int) this.noise.sample(totalX, chunk.chunkStartZ + z);
double totalZ = chunk.chunkStartZ + z;
int height = (int) this.noise.sample(totalX, totalZ);
for (int y = 0; y < CHUNK_SIZE; y++)
{
double rockNoise = this.stoneNoise.sample(totalX / 160.0, (chunk.chunkStartY + y) / 50.0, totalZ / 160.0);
int totalY = chunk.chunkStartY + y;
Block block = Blocks.AIR;
if (totalY < height - 3)
block = Blocks.DIRT;
block = pickStone(rockNoise);
else if (totalY < height)
block = Blocks.GNEISS;
block = Blocks.DIRT;
chunk.setBlock(x, y, z, block);
}
}
}
return chunk;
}
private static Block pickStone(double rockNoise) {
if (rockNoise < -0.25)
{
return Blocks.ANDESITE;
}
else if (rockNoise < 0)
{
return Blocks.DIORITE;
}
else if (rockNoise < 0.25)
{
return Blocks.GNEISS;
}
else
{
return Blocks.GRANITE;
}
}
}

View File

@ -1,5 +1,7 @@
package com.github.halotroop.litecraft.world.gen;
import com.github.halotroop.litecraft.world.dimension.Dimension;
public class OverworldDimension extends Dimension<OverworldChunkGenerator>
{
public OverworldDimension(int id)