Пример #1
0
 /** Update sky and emitted light */
 private final void updateLightLevel() {
   /* Look up transparency for current block */
   BlockTransparency bt = HDTextureMap.getTransparency(blocktypeid);
   if (bt == BlockTransparency.TRANSPARENT) {
     skylevel = mapiter.getBlockSkyLight();
     emitlevel = mapiter.getBlockEmittedLight();
   } else if (HDTextureMap.getTransparency(lastblocktypeid)
       != BlockTransparency.SEMITRANSPARENT) {
     mapiter.unstepPosition(laststep); /* Back up to block we entered on */
     if (mapiter.getY() < 128) {
       emitlevel = mapiter.getBlockEmittedLight();
       skylevel = mapiter.getBlockSkyLight();
     } else {
       emitlevel = 0;
       skylevel = 15;
     }
     mapiter.stepPosition(laststep);
   } else {
     mapiter.unstepPosition(laststep); /* Back up to block we entered on */
     if (mapiter.getY() < 128) {
       mapiter.stepPosition(BlockStep.Y_PLUS); /* Look above */
       emitlevel = mapiter.getBlockEmittedLight();
       skylevel = mapiter.getBlockSkyLight();
       mapiter.stepPosition(BlockStep.Y_MINUS);
     } else {
       emitlevel = 0;
       skylevel = 15;
     }
     mapiter.stepPosition(laststep);
   }
 }
Пример #2
0
  protected void scan(
      DynmapWorld world,
      int seq,
      boolean isnether,
      final Color result,
      final Color result_day,
      MapIterator mapiter) {
    int lightlevel = 15;
    int lightlevel_day = 15;
    BiomeMap bio = null;
    double rain = 0.0;
    double temp = 0.0;
    result.setTransparent();
    if (result_day != null) result_day.setTransparent();
    for (; ; ) {
      if (mapiter.getY() < 0) {
        return;
      }
      int id = mapiter.getBlockTypeID();
      int data = 0;
      if (isnether) {
          /* Make bedrock ceiling into air in nether */
        if (id != 0) {
          /* Remember first color we see, in case we wind up solid */
          if (result.isTransparent()) {
            try {
              if (colorScheme.colors[id] != null) {
                result.setColor(colorScheme.colors[id][seq]);
              }
            } catch (ArrayIndexOutOfBoundsException aioobx) {
              colorScheme.resizeColorArray(id);
            }
          }
          id = 0;
        } else isnether = false;
      }
      if (id != 0) {
          /* No update needed for air */
        switch (biomecolored) {
          case NONE:
            try {
              if (colorScheme.datacolors[id] != null) {
                  /* If data colored */
                data = mapiter.getBlockData();
              }
            } catch (ArrayIndexOutOfBoundsException aioobx) {
              colorScheme.resizeColorArray(id);
            }
            break;
          case BIOME:
            bio = mapiter.getBiome();
            break;
          case RAINFALL:
            rain = mapiter.getRawBiomeRainfall();
            break;
          case TEMPERATURE:
            temp = mapiter.getRawBiomeTemperature();
            break;
        }
        if ((shadowscale != null) && (mapiter.getY() < (mapiter.getWorldHeight() - 1))) {
          /* Find light level of previous chunk */
          BlockStep last = mapiter.unstepPosition();
          lightlevel = lightlevel_day = mapiter.getBlockSkyLight();
          if (lightscale != null) lightlevel = lightscale[lightlevel];
          if ((lightlevel < 15) || (lightlevel_day < 15)) {
            int emitted = mapiter.getBlockEmittedLight();
            lightlevel = Math.max(emitted, lightlevel);
            lightlevel_day = Math.max(emitted, lightlevel_day);
          }
          mapiter.stepPosition(last);
        }
      }

      switch (seq) {
        case 0:
          mapiter.stepPosition(BlockStep.X_MINUS);
          break;
        case 1:
        case 3:
          mapiter.stepPosition(BlockStep.Y_MINUS);
          break;
        case 2:
          mapiter.stepPosition(BlockStep.Z_PLUS);
          break;
      }

      seq = (seq + 1) & 3;

      if (id != 0) {
        if (highlightBlocks.contains(id)) {
          result.setColor(highlightColor);
          return;
        }
        Color[] colors = null;
        switch (biomecolored) {
          case NONE:
            try {
              if (data != 0) colors = colorScheme.datacolors[id][data];
              else colors = colorScheme.colors[id];
            } catch (ArrayIndexOutOfBoundsException aioobx) {
              colorScheme.resizeColorArray(id);
            }
            break;
          case BIOME:
            if (bio != null) colors = colorScheme.biomecolors[bio.ordinal()];
            break;
          case RAINFALL:
            colors = colorScheme.getRainColor(rain);
            break;
          case TEMPERATURE:
            colors = colorScheme.getTempColor(temp);
            break;
        }
        if (colors != null) {
          Color c = colors[seq];
          if (c.getAlpha() > 0) {
            /* we found something that isn't transparent, or not doing transparency */
            if ((!transparency) || (c.getAlpha() == 255)) {
              /* it's opaque - the ray ends here */
              result.setARGB(c.getARGB() | 0xFF000000);
              if (lightlevel < 15) {
                  /* Not full light? */
                shadowColor(result, lightlevel);
              }
              if (result_day != null) {
                if (lightlevel_day == lightlevel) /* Same light = same result */
                  result_day.setColor(result);
                else {
                  result_day.setColor(c);
                  if (lightlevel_day < 15) shadowColor(result_day, lightlevel_day);
                }
              }
              return;
            }

            /* this block is transparent, so recurse */
            scan(world, seq, isnether, result, result_day, mapiter);

            int cr = c.getRed();
            int cg = c.getGreen();
            int cb = c.getBlue();
            int ca = c.getAlpha();
            if (lightlevel < 15) {
              int scale = shadowscale[lightlevel];
              cr = (cr * scale) >> 8;
              cg = (cg * scale) >> 8;
              cb = (cb * scale) >> 8;
            }
            cr *= ca;
            cg *= ca;
            cb *= ca;
            int na = 255 - ca;
            result.setRGBA(
                (result.getRed() * na + cr) >> 8,
                (result.getGreen() * na + cg) >> 8,
                (result.getBlue() * na + cb) >> 8,
                255);
            /* Handle day also */
            if (result_day != null) {
              cr = c.getRed();
              cg = c.getGreen();
              cb = c.getBlue();
              if (lightlevel_day < 15) {
                int scale = shadowscale[lightlevel_day];
                cr = (cr * scale) >> 8;
                cg = (cg * scale) >> 8;
                cb = (cb * scale) >> 8;
              }
              cr *= ca;
              cg *= ca;
              cb *= ca;
              result_day.setRGBA(
                  (result_day.getRed() * na + cr) >> 8,
                  (result_day.getGreen() * na + cg) >> 8,
                  (result_day.getBlue() * na + cb) >> 8,
                  255);
            }
            return;
          }
        }
      }
    }
  }