package projectzombie.world.layer.layergen; import java.util.Random; import gl_engine.MathHelpers; import gl_engine.vec.Vec2d; import gl_engine.vec.Vec2i; import gl_engine.vec.Vec3d; import projectzombie.Main; import projectzombie.entity.Entity; import projectzombie.entity.EntityZombie; import projectzombie.init.Tiles; import projectzombie.util.math.ColorRange; import projectzombie.util.math.TileState; import projectzombie.util.math.random.OpenSimplexNoise; import projectzombie.util.math.random.RandomHelpers; import projectzombie.world.chunk.Chunk; import projectzombie.world.layer.Layer; public class LayerGenCaves extends LayerGen { @Override public void generateChunk(Chunk chunk, Layer layer, Random rand, Vec2i c_pos) { // Is there going to be a portal up in this chunk boolean portal = PortalSpawnrates.WorldCavePortal(rand); Vec2i portal_pos = null; if(portal) portal_pos = new Vec2i( RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // Is there going to be a portal down in this chunk boolean portal_down = PortalSpawnrates.CaveLavaCavePortal(rand); Vec2i portal_down_pos = null; if(portal_down) portal_down_pos = new Vec2i( RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // Get some noise generators OpenSimplexNoise noisegen_n = new OpenSimplexNoise(new Random(layer.lseed).nextLong()); // Loop over the chunk for(int x=0;x 80) { chunk.setBackTile(Tiles.STONE.getDefaultState(), pos); } else { chunk.setBackTile(Tiles.WALL.getDefaultState(), pos); } } } if(portal) { chunk.setFrontTile(new TileState(Tiles.LADDER_UP, (short)0), portal_pos); } if(portal_down) { chunk.setBackTile(new TileState(Tiles.PORTAL_DOWN, (short)2), portal_down_pos); chunk.setFrontTile(Tiles.LADDER.getDefaultState(), portal_down_pos); } Vec2i chest_pos = new Vec2i( RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.mx), RandomHelpers.randrange(rand, Chunk.CHUNK_SIZE.my)); // Only place a chest here if the tile is clear if(chunk.getBackTile(chest_pos).tile == getTileDestroyed().tile) { chunk.setFrontTile(new TileState(Tiles.CHEST, 1), chest_pos); } } @Override public void spawnEntities(Layer layer, Random rand) { if(rand.nextDouble() > 0.9) { Entity zombie = new EntityZombie(new Vec2d( RandomHelpers.randrange(rand, (int)Main.player.pos.x - 128, (int)Main.player.pos.x + 128), RandomHelpers.randrange(rand, (int)Main.player.pos.y - 128, (int)Main.player.pos.y + 128))); boolean exists = false; for(Entity e : layer.getChunk(zombie.pos).entities) { if(e.getClass() == zombie.getClass()) { exists = true; break; } } if( !exists && layer.getBackTile(new Vec2i((int)zombie.pos.x, (int)zombie.pos.y)).tile == getTileDestroyed().tile && zombie.pos.squareDistance(Main.player.pos) > 32 ) { layer.spawnEntity(zombie); } } } @Override public TileState getTileDestroyed() { return Tiles.STONE.getDefaultState(); } @Override public ColorRange getLightLevel() { return new ColorRange(new Vec3d(0, 0, 0), new Vec3d(0, 0, 0)); } @Override public double getTemperatureStatic(Layer layer, Vec2d pos) { return 0.5; } @Override public double getTemperatureDynamic(Layer layer, Vec2d pos) { return 0.5; } }