Package Hexel.generation

Source Code of Hexel.generation.ChunkGenerator

package Hexel.generation;

import Hexel.blocks.types.Block;
import Hexel.blocks.types.BlockTransparent;
import Hexel.chunk.Chunk;
import Hexel.chunk.Chunks;
import Hexel.generation.terrainGenerator.FlatTerrainMap;
import Hexel.generation.terrainGenerator.ForestTerrainMap;
import Hexel.generation.terrainGenerator.TerrainMap;
import Hexel.generation.terrainGenerator.VariedTerrainMap;
import Hexel.math.Vector2i;
import Hexel.math.Vector3i;
import Hexel.util.Cleanup;

public class ChunkGenerator {
  public TerrainMap tm;

  private Chunks chunks;

  public ChunkGenerator(int seed, Chunks chunks, Cleanup cleanup) {
    this.chunks = chunks;
    this.tm = new VariedTerrainMap(seed);
  }

  public Chunk genChunk(Vector3i pos) {
    return this.genChunk(pos.x, pos.y, pos.z);
  }

  public Chunk genChunk(int cx, int cy, int cz) {
    Chunk chunk = new Chunk(cx, cy, cz);

    Vector2i tmp = new Vector2i();

    for (int x = 0; x < 32; x++) {
      for (int y = 0; y < 16; y++) {
        for (int z = 0; z < 32; z++) {
          int gx = cx * 32 + x;
          int gy = cy * 16 + y;
          int gz = cz * 32 + z;
          Block b = this.tm.getBlock(gx, gy, gz, tmp);
          chunk.set(x, y, z, b);
          chunk.stepsToSim[x][y][z] = 100;
          chunk.nextSimSteps[x][y][z] = -1;
          if (!(b instanceof BlockTransparent))
            chunks.updateHighestBlockAtXY(gx, gy, gz, tmp);

        }
      }
    }

    chunk.nextSimStep = -1;
    chunk.modified = false;
    chunk.needFirstSim = true;

    return chunk;
  }

}
TOP

Related Classes of Hexel.generation.ChunkGenerator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.