pull/12/head
parent
3f2738ac1a
commit
baa863d6e1
|
@ -9,7 +9,7 @@ import com.github.halotroop.litecraft.screens.TitleScreen;
|
||||||
import com.github.halotroop.litecraft.types.block.Blocks;
|
import com.github.halotroop.litecraft.types.block.Blocks;
|
||||||
import com.github.halotroop.litecraft.util.RelativeDirection;
|
import com.github.halotroop.litecraft.util.RelativeDirection;
|
||||||
import com.github.halotroop.litecraft.world.World;
|
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.*;
|
||||||
import com.github.hydos.ginger.engine.api.game.*;
|
import com.github.hydos.ginger.engine.api.game.*;
|
||||||
import com.github.hydos.ginger.engine.cameras.*;
|
import com.github.hydos.ginger.engine.cameras.*;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import org.joml.Vector3f;
|
||||||
|
|
||||||
import com.github.halotroop.litecraft.Litecraft;
|
import com.github.halotroop.litecraft.Litecraft;
|
||||||
import com.github.halotroop.litecraft.world.*;
|
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.cameras.Camera;
|
||||||
import com.github.hydos.ginger.engine.elements.objects.Player;
|
import com.github.hydos.ginger.engine.elements.objects.Player;
|
||||||
|
|
||||||
|
|
|
@ -57,5 +57,8 @@ public class Block
|
||||||
public static final Block getBlock(String identifier)
|
public static final Block getBlock(String identifier)
|
||||||
{ return IDENTIFIER_TO_BLOCK.get(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<>();
|
private static final Map<String, Block> IDENTIFIER_TO_BLOCK = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,11 @@ public final class OctaveSimplexNoise
|
||||||
private double clamp;
|
private double clamp;
|
||||||
private double spread, amplitudeLow, amplitudeHigh;
|
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)
|
public OctaveSimplexNoise(Random rand, int octaves, double spread, double amplitudeHigh, double amplitudeLow)
|
||||||
{
|
{
|
||||||
this.samplers = new SimplexNoise[octaves];
|
this.samplers = new SimplexNoise[octaves];
|
||||||
|
@ -21,12 +26,26 @@ public final class OctaveSimplexNoise
|
||||||
|
|
||||||
public double sample(double x, double y)
|
public double sample(double x, double y)
|
||||||
{
|
{
|
||||||
double amplFreq = 0.5D;
|
double amplSpread = 0.5D;
|
||||||
double result = 0;
|
double result = 0;
|
||||||
for (SimplexNoise sampler : this.samplers)
|
for (SimplexNoise sampler : this.samplers)
|
||||||
{
|
{
|
||||||
result += (amplFreq * sampler.sample(x / (amplFreq * this.spread), y / (amplFreq * this.spread)));
|
result += (amplSpread * sampler.sample(x / (amplSpread * this.spread), y / (amplSpread * this.spread)));
|
||||||
amplFreq *= 0.5D;
|
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;
|
result = result * this.clamp;
|
||||||
return result > 0 ? result * this.amplitudeHigh : result * this.amplitudeLow;
|
return result > 0 ? result * this.amplitudeHigh : result * this.amplitudeLow;
|
||||||
|
|
|
@ -165,7 +165,7 @@ public class Chunk implements BlockAccess, WorldGenConstants, DataStorage
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
palette.put(intIdCache, Block.getBlock((String) o));
|
palette.put(intIdCache, Block.getBlockOrAir((String) o));
|
||||||
readInt = true;
|
readInt = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import org.joml.Vector3f;
|
||||||
import com.github.halotroop.litecraft.save.LitecraftSave;
|
import com.github.halotroop.litecraft.save.LitecraftSave;
|
||||||
import com.github.halotroop.litecraft.types.block.Block;
|
import com.github.halotroop.litecraft.types.block.Block;
|
||||||
import com.github.halotroop.litecraft.world.block.BlockRenderer;
|
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.halotroop.litecraft.world.gen.*;
|
||||||
import com.github.hydos.ginger.engine.elements.objects.Player;
|
import com.github.hydos.ginger.engine.elements.objects.Player;
|
||||||
import com.github.hydos.ginger.engine.obj.ModelLoader;
|
import com.github.hydos.ginger.engine.obj.ModelLoader;
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package com.github.halotroop.litecraft.world.gen;
|
package com.github.halotroop.litecraft.world.dimension;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
import com.github.halotroop.litecraft.world.gen.*;
|
||||||
|
|
||||||
import it.unimi.dsi.fastutil.ints.*;
|
import it.unimi.dsi.fastutil.ints.*;
|
||||||
|
|
||||||
public abstract class Dimension<T extends ChunkGenerator>
|
public abstract class Dimension<T extends ChunkGenerator>
|
|
@ -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
|
public final class Dimensions
|
||||||
{
|
{
|
|
@ -10,11 +10,14 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
|
||||||
{
|
{
|
||||||
public OverworldChunkGenerator(long seed, int dimension)
|
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;
|
this.dimension = dimension;
|
||||||
}
|
}
|
||||||
|
|
||||||
private final OctaveSimplexNoise noise;
|
private final OctaveSimplexNoise noise;
|
||||||
|
private final OctaveSimplexNoise stoneNoise;
|
||||||
private final int dimension;
|
private final int dimension;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,19 +29,40 @@ public class OverworldChunkGenerator implements ChunkGenerator, WorldGenConstant
|
||||||
double totalX = x + chunk.chunkStartX;
|
double totalX = x + chunk.chunkStartX;
|
||||||
for (int z = 0; z < CHUNK_SIZE; z++)
|
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++)
|
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;
|
int totalY = chunk.chunkStartY + y;
|
||||||
Block block = Blocks.AIR;
|
Block block = Blocks.AIR;
|
||||||
if (totalY < height - 3)
|
if (totalY < height - 3)
|
||||||
block = Blocks.DIRT;
|
block = pickStone(rockNoise);
|
||||||
else if (totalY < height)
|
else if (totalY < height)
|
||||||
block = Blocks.GNEISS;
|
block = Blocks.DIRT;
|
||||||
chunk.setBlock(x, y, z, block);
|
chunk.setBlock(x, y, z, block);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chunk;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.github.halotroop.litecraft.world.gen;
|
package com.github.halotroop.litecraft.world.gen;
|
||||||
|
|
||||||
|
import com.github.halotroop.litecraft.world.dimension.Dimension;
|
||||||
|
|
||||||
public class OverworldDimension extends Dimension<OverworldChunkGenerator>
|
public class OverworldDimension extends Dimension<OverworldChunkGenerator>
|
||||||
{
|
{
|
||||||
public OverworldDimension(int id)
|
public OverworldDimension(int id)
|
||||||
|
|
Loading…
Reference in New Issue