コード例 #1
0
ファイル: MapCalculator.java プロジェクト: Top-Cat/Spoutcraft
  private final int getBlockHeight(World world, int x, int z) {
    if (MinimapConfig.getInstance().isCavemap()) {
      Chunk chunk = world.getChunkFromBlockCoords(x, z);
      cmdist.setSeed((x & 0xffff) | ((z & 0xffff) << 16));
      float dist =
          distance(
              (int) Minecraft.getMinecraft().thePlayer.posX,
              (int) Minecraft.getMinecraft().thePlayer.posZ,
              x,
              z);
      int y = (int) Minecraft.getMinecraft().thePlayer.posY;
      if (dist > 5) y -= (cmdist.nextInt((int) (dist)) - ((int) dist / 2));
      x &= 0xf;
      z &= 0xf;

      if (y < 0) {
        y = 0;
      } else if (y > 255) {
        y = 255;
      }

      if (blockIsSolid(chunk, x, y, z)) {
        int itery = y;
        while (true) {
          itery++;
          if (itery > y + 10) return y + 10;
          if (!blockIsSolid(chunk, x, itery, z)) {
            return itery - 1;
          }
        }
      }
      while (y > -1) {
        y--;
        if (blockIsSolid(chunk, x, y, z)) {
          return y;
        }
      }
      return -1;
    }

    return world.getHeightValue(x, z) - 1;

    // return world.b(x, z).b(x & 0xf, z & 0xf);
    /*
     * li chunk = world.b(x, z); int y = (int)(game.h.aM); // starty; x &=
     * 0xf; z &= 0xf;
     *
     * //while (y > 0) // {
     *
     *
     * if (getBlockColor(id, meta).alpha == 0) return -1; // y--; else return
     * y + 1; // what //}
     */
    // return -1;
  }
コード例 #2
0
ファイル: MapCalculator.java プロジェクト: Top-Cat/Spoutcraft
  private void mapCalc() {
    if (Minecraft.getMinecraft().thePlayer == null || Minecraft.getMinecraft().theWorld == null)
      return;
    try {
      final boolean square = MinimapConfig.getInstance().isSquare();
      final World data = Minecraft.getMinecraft().theWorld;
      int renderSize;
      int startX;
      int startZ;
      synchronized (map) {
        if (map.zoom != MinimapConfig.getInstance().getZoom()) {
          map.zoom = MinimapConfig.getInstance().getZoom();
          switch (map.zoom) {
            case 0:
              map.renderSize = Map.ZOOM_0;
              break;
            case 1:
              map.renderSize = Map.ZOOM_1;
              break;
            case 2:
              map.renderSize = Map.ZOOM_2;
              break;
            default:
              map.renderSize = Map.ZOOM_2;
              break;
          }
          map.renderOff = map.renderSize / 2;
          map.clear();
        }
        map.square = square;

        map.update(
            Minecraft.getMinecraft().thePlayer.posX, Minecraft.getMinecraft().thePlayer.posZ);
        renderSize = map.renderSize;
        startX = (int) (map.getPlayerX() - map.renderOff);
        startZ = (int) (map.getPlayerZ() - map.renderOff);
      }

      for (int worldX = startX; worldX < startX + renderSize; worldX++) {
        for (int worldZ = startZ; worldZ < startZ + renderSize; worldZ++) {
          int worldY = getBlockHeight(data, worldX, worldZ);

          int pixelX = worldX - startX;
          if (pixelX >= renderSize) {
            pixelX -= renderSize;
          }

          int pixelZ = worldZ - startZ;
          pixelZ = renderSize - pixelZ;
          if (pixelZ >= renderSize) {
            pixelZ -= renderSize;
          }

          if (square
              || MinimapUtils.insideCircle(
                  startX + renderSize / 2,
                  startZ + renderSize / 2,
                  renderSize / 2,
                  worldX,
                  worldZ)) {
            int color = getBlockColor(data, worldX, worldY, worldZ);
            if (color == 0) {
              map.clearColorPixel(pixelX, pixelZ);
            } else {
              map.setColorPixel(pixelX, pixelZ, color);
            }

            short height = (short) data.getHeightValue(worldX, worldZ);
            short reference = (short) data.getHeightValue(worldX + 1, worldZ + 1);
            map.heightimg.setARGB(pixelZ, pixelX, getHeightColor(height, reference));
            map.setLightPixel(pixelX, pixelZ, getBlockLight(data, worldX, worldY, worldZ));

          } else {
            map.clearColorPixel(pixelX, pixelZ);
            map.heightimg.setARGB(pixelX, pixelZ, 0);
            map.setLightPixel(pixelX, pixelZ, 255);
          }
        }
      }

      synchronized (map) {
        for (Waypoint pt : MinimapConfig.getInstance().getWaypoints(MinimapUtils.getWorldName())) {
          if (pt.enabled) {
            boolean render = false;
            if (square) {
              render =
                  Math.abs(map.getPlayerX() - pt.x) < map.renderSize
                      && Math.abs(map.getPlayerZ() - pt.z) < map.renderSize;
            } else {
              render =
                  MinimapUtils.insideCircle(
                      startX + map.renderSize / 2,
                      startZ + map.renderSize / 2,
                      map.renderSize / 2,
                      pt.x,
                      pt.z);
            }
            if (pt.deathpoint && !MinimapConfig.getInstance().isDeathpoints()) {
              render = false;
            }
            if (render) {
              int pixelX = pt.x - startX;

              int pixelZ = pt.z - startZ;
              pixelZ = map.renderSize - pixelZ;

              int scale = map.zoom + 2;
              if (map.zoom > 2) {
                scale += 2;
              }
              if (map.zoom > 1) {
                scale += 1;
              }

              int color = 0xEE2C2C;
              if (pt == MinimapConfig.getInstance().getFocussedWaypoint()) {
                color = 0xff00ffff;
              }
              drawCircle(pixelX, pixelZ, scale + map.zoom + 1, pt.deathpoint ? color : 0);
              drawCircle(pixelX, pixelZ, scale, pt.deathpoint ? 0 : color);
            }
          }
        }
        for (Waypoint pt : MinimapConfig.getInstance().getServerWaypoints()) {
          boolean render = false;
          if (square) {
            render =
                Math.abs(map.getPlayerX() - pt.x) < map.renderSize
                    && Math.abs(map.getPlayerZ() - pt.z) < map.renderSize;
          } else {
            render =
                MinimapUtils.insideCircle(
                    startX + map.renderSize / 2,
                    startZ + map.renderSize / 2,
                    map.renderSize / 2,
                    pt.x,
                    pt.z);
          }
          if (render) {
            int pixelX = pt.x - startX;

            int pixelZ = pt.z - startZ;
            pixelZ = map.renderSize - pixelZ;

            int scale = map.zoom + 2;
            if (map.zoom > 2) {
              scale += 2;
            }
            if (map.zoom > 1) {
              scale += 1;
            }

            int color = 0x3366CC;
            if (pt == MinimapConfig.getInstance().getFocussedWaypoint()) {
              color = 0xff00ffff;
            }
            drawCircle(pixelX, pixelZ, scale + map.zoom + 1, 0);
            drawCircle(pixelX, pixelZ, scale, color);
          }
        }
      }
    } catch (Throwable whatever) {
    }
  }