示例#1
0
  /** Initialize a single chunk from the chunk generator. */
  private void generateChunk(GlowChunk chunk, int x, int z) {
    Random random = new Random((long) x * 341873128712L + (long) z * 132897987541L);
    BiomeGrid biomes = new BiomeGrid();

    int[] biomeValues =
        biomeGrid[0].generateValues(
            x * GlowChunk.WIDTH, z * GlowChunk.HEIGHT, GlowChunk.WIDTH, GlowChunk.HEIGHT);
    for (int i = 0; i < biomeValues.length; i++) {
      biomes.biomes[i] = (byte) biomeValues[i];
    }

    // extended sections with data
    if (generator instanceof GlowChunkGenerator) {
      short[][] extSections =
          ((GlowChunkGenerator) generator)
              .generateExtBlockSectionsWithData(world, random, x, z, biomes);
      if (extSections != null) {
        GlowChunk.ChunkSection[] sections = new GlowChunk.ChunkSection[extSections.length];
        for (int i = 0; i < extSections.length; ++i) {
          // this is sort of messy.
          if (extSections[i] != null) {
            sections[i] = new GlowChunk.ChunkSection();
            for (int j = 0; j < extSections[i].length; ++j) {
              sections[i].types[j] = (char) extSections[i][j];
            }
            sections[i].recount();
          }
        }
        chunk.initializeSections(sections);
        chunk.setBiomes(biomes.biomes);
        chunk.automaticHeightMap();
        return;
      }
    }

    // extended sections
    short[][] extSections = generator.generateExtBlockSections(world, random, x, z, biomes);
    if (extSections != null) {
      GlowChunk.ChunkSection[] sections = new GlowChunk.ChunkSection[extSections.length];
      for (int i = 0; i < extSections.length; ++i) {
        // this is sort of messy.
        if (extSections[i] != null) {
          sections[i] = new GlowChunk.ChunkSection();
          for (int j = 0; j < extSections[i].length; ++j) {
            sections[i].types[j] = (char) (extSections[i][j] << 4);
          }
          sections[i].recount();
        }
      }
      chunk.initializeSections(sections);
      chunk.setBiomes(biomes.biomes);
      chunk.automaticHeightMap();
      return;
    }

    // normal sections
    byte[][] blockSections = generator.generateBlockSections(world, random, x, z, biomes);
    if (blockSections != null) {
      GlowChunk.ChunkSection[] sections = new GlowChunk.ChunkSection[blockSections.length];
      for (int i = 0; i < blockSections.length; ++i) {
        // this is sort of messy.
        if (blockSections[i] != null) {
          sections[i] = new GlowChunk.ChunkSection();
          for (int j = 0; j < blockSections[i].length; ++j) {
            sections[i].types[j] = (char) (blockSections[i][j] << 4);
          }
          sections[i].recount();
        }
      }
      chunk.initializeSections(sections);
      chunk.setBiomes(biomes.biomes);
      chunk.automaticHeightMap();
      return;
    }

    // deprecated flat generation
    byte[] types = generator.generate(world, random, x, z);
    GlowChunk.ChunkSection[] sections = new GlowChunk.ChunkSection[8];
    for (int sy = 0; sy < sections.length; ++sy) {
      GlowChunk.ChunkSection sec = new GlowChunk.ChunkSection();
      int by = 16 * sy;
      for (int cx = 0; cx < 16; ++cx) {
        for (int cz = 0; cz < 16; ++cz) {
          for (int cy = by; cy < by + 16; ++cy) {
            char type = (char) types[(cx * 16 + cz) * 128 + cy];
            sec.types[sec.index(cx, cy, cz)] = (char) (type << 4);
          }
        }
      }
      sec.recount();
      sections[sy] = sec;
    }
    chunk.initializeSections(sections);
    chunk.setBiomes(biomes.biomes);
    chunk.automaticHeightMap();
  }