Beispiel #1
0
  public static Map drawChunk(int x, int z, boolean force) {
    synchronized (chunks) {
      Map map = chunks.get(levelOfDetail).get(x, z);
      if (map == null || (force && map == blankMap)) {
        map = new Map(16);
        map.originOffsetX = 0;
        map.originOffsetY = 0;
        map.renderSize = 16;
      } else if (!force) {
        return map;
      }
      boolean pixelSet = false;
      try {
        for (int cx = 0; cx < 16; cx++) {
          for (int cz = 0; cz < 16; cz++) {

            int aX = x * 16 + cx * levelOfDetail;
            int aZ = z * 16 + cz * levelOfDetail;

            short height = heightMap.getHeight(aX, aZ);
            byte id = heightMap.getBlockId(aX, aZ);
            if (id == -1 || height == -1) {
              continue;
            } else {
              pixelSet = true;
            }

            if (levelOfDetail <= 2) {
              short reference = heightMap.getHeight(aX + levelOfDetail, aZ + levelOfDetail);
              int color = MapCalculator.getHeightColor(height, reference);
              map.heightimg.setARGB(cx, cz, color);
            }

            map.setColorPixel(cz, cx, BlockColor.getBlockColor(id, 0).color | 0xff000000);
          }
        }
      } catch (Exception e) {
        pixelSet = false;
      }
      if (pixelSet) {
        getChunkMap(levelOfDetail).put(x, z, map);
      } else {
        getChunkMap(levelOfDetail).put(x, z, blankMap);
      }
      return map;
    }
  }