gen world
parent
9592f8b320
commit
20a294c33c
|
@ -0,0 +1,22 @@
|
|||
package com.github.halotroop.litecraft.world;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.Block;
|
||||
import com.github.halotroop.litecraft.world.gen.WorldGenConstants;
|
||||
|
||||
final class GenWorld implements BlockAccess, WorldGenConstants
|
||||
{
|
||||
GenWorld(World parent)
|
||||
{
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public final World parent;
|
||||
|
||||
@Override
|
||||
public Block getBlock(int x, int y, int z)
|
||||
{ return this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).getBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS); }
|
||||
|
||||
@Override
|
||||
public void setBlock(int x, int y, int z, Block block)
|
||||
{ this.parent.getGenChunk(x >> POS_SHIFT, y >> POS_SHIFT, z >> POS_SHIFT).setBlock(x & MAX_POS, y & MAX_POS, z & MAX_POS, block); }
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.github.halotroop.litecraft.world;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Random;
|
||||
|
||||
import com.github.halotroop.litecraft.types.block.Block;
|
||||
import com.github.halotroop.litecraft.world.gen.*;
|
||||
|
@ -17,6 +17,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
private final Long2ObjectMap<Chunk> chunks;
|
||||
private final WorldModifier[] worldModifiers;
|
||||
private final ChunkGenerator chunkGenerator;
|
||||
private final BlockAccess genBlockAccess;
|
||||
|
||||
private final long seed;
|
||||
public Player player;
|
||||
|
@ -27,6 +28,7 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
this.seed = seed;
|
||||
this.chunkGenerator = dim.createChunkGenerator(seed);
|
||||
this.worldModifiers = dim.getWorldModifierArray();
|
||||
this.genBlockAccess = new GenWorld(this);
|
||||
|
||||
for (int i = (0 - (size/2)); i < (size/2); i++)
|
||||
for (int k = (0 - (size/2)); k < (size/2); k++)
|
||||
|
@ -54,11 +56,14 @@ public class World implements BlockAccess, WorldGenConstants
|
|||
|
||||
for (WorldModifier modifier : this.worldModifiers)
|
||||
{
|
||||
modifier.modifyWorld(rand, chunkStartX, chunkStartY, chunkStartZ);
|
||||
modifier.modifyWorld(this.genBlockAccess, rand, chunkStartX, chunkStartY, chunkStartZ);
|
||||
}
|
||||
}
|
||||
|
||||
Chunk getPartiallyGeneratedChunk(int chunkX, int chunkY, int chunkZ)
|
||||
/**
|
||||
* @return a chunk that has not neccesarily gone through chunk populating. Used in chunk populating to prevent infinite recursion.
|
||||
*/
|
||||
Chunk getGenChunk(int chunkX, int chunkY, int chunkZ)
|
||||
{ return this.chunks.computeIfAbsent(posHash(chunkX, chunkY, chunkZ), pos -> this.chunkGenerator.generateChunk(chunkX, chunkY, chunkZ)); }
|
||||
|
||||
private static long posHash(int chunkX, int chunkY, int chunkZ)
|
||||
|
|
|
@ -2,6 +2,8 @@ package com.github.halotroop.litecraft.world.gen;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import com.github.halotroop.litecraft.world.BlockAccess;
|
||||
|
||||
public interface WorldModifier {
|
||||
void modifyWorld(Random rand, int chunkStartX, int chunkStartY, int chunkStartZ);
|
||||
void modifyWorld(BlockAccess world, Random rand, int chunkStartX, int chunkStartY, int chunkStartZ);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue