Ejemplo n.º 1
0
 @Override
 public void doPopulate(Chunk chunk) {
   if (chunk.getY() >= 0 && chunk.getY() < 128) {
     populateMCChunk(chunk, 0, chunk.getY(), 0);
     populateMCChunk(chunk, 16, chunk.getY(), 0);
     populateMCChunk(chunk, 0, chunk.getY(), 16);
     populateMCChunk(chunk, 16, chunk.getY(), 16);
   }
   chunk.setPopulated(true);
 }
Ejemplo n.º 2
0
  private void populateMCChunk(Chunk chunk, int dx, int dy, int dz) {
    if (chunk.isPopulated()) {
      return;
    }
    int chunkX = (chunk.getX() - shiftX + dx) >> 4;
    int chunkZ = (chunk.getZ() - shiftX + dz) >> 4;

    DataInputStream inputStream = RegionFileCache.getChunkDataInputStream(file, chunkX, chunkZ);
    if (inputStream != null) {
      try {
        NBTInputStream nbt = new NBTInputStream(inputStream);
        CompoundTag root = (CompoundTag) nbt.readTag();
        CompoundTag level = (CompoundTag) root.getValue().get("Level");
        ByteArrayTag blocks = (ByteArrayTag) level.getValue().get("Blocks");

        int maxY = dy + OctreeNode.CHUNK_SIZE;
        if (maxY > 128) maxY = 128;
        byte[] data = blocks.getValue();
        for (int x = 0; x < SIZE_X; x++) {
          for (int y = dy; y < maxY; y++) {
            for (int z = 0; z < SIZE_Z; z++) {
              int i = y + (z * SIZE_Y) + x * SIZE_Y * SIZE_Z;
              if (data[i] != 0) {
                chunk.setPixel(chunk.getX() + dx + x, y, chunk.getZ() + dz + z, data[i]);
              }
            }
          }
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }