Esempio n. 1
0
  private void paintChessPiece(Cuboid region, ChessStone stone, MassBlockUpdate mbu) {
    assert region.getSizeX() >= stone.getSizeX();
    assert region.getSizeZ() >= stone.getSizeZ();

    int xOff = (region.getSizeX() - stone.getSizeX()) / 2;
    int zOff = (region.getSizeZ() - stone.getSizeZ()) / 2;

    Map<Block, MaterialWithData> deferred = new HashMap<Block, MaterialWithData>();
    World world = region.getWorld();
    for (int x = 0; x < stone.getSizeX(); x++) {
      for (int y = 0; y < stone.getSizeY(); y++) {
        for (int z = 0; z < stone.getSizeZ(); z++) {
          MaterialWithData mat = stone.getMaterial(x, y, z);
          if (mat.getId() == 0) {
            // the region was pre-cleared, skip placing air a second time
            continue;
          }
          Block b = region.getRelativeBlock(world, x + xOff, y, z + zOff);
          if (BlockType.shouldPlaceLast(mat.getId())) {
            deferred.put(b, mat);
          } else {
            mat.applyToBlock(b, mbu);
          }
        }
      }
    }

    for (Entry<Block, MaterialWithData> e : deferred.entrySet()) {
      e.getValue().applyToBlock(e.getKey(), mbu);
    }
  }
  private void paintStruts(MassBlockUpdate mbu) {
    MaterialData struts = boardStyle.getStrutsMaterial();

    // vertical struts at the frame corners
    Cuboid c =
        new Cuboid(frameBoard.getLowerNE())
            .shift(CuboidDirection.Up, 1)
            .expand(CuboidDirection.Up, boardStyle.getHeight());
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.South, frameBoard.getSizeX() - 1);
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.West, frameBoard.getSizeZ() - 1);
    c.fill(struts, mbu);
    c = c.shift(CuboidDirection.North, frameBoard.getSizeZ() - 1);
    c.fill(struts, mbu);

    // horizontal struts along roof edge
    Cuboid roof = frameBoard.shift(CuboidDirection.Up, boardStyle.getHeight() + 1);
    roof.getFace(CuboidDirection.East).fill(struts, mbu);
    roof.getFace(CuboidDirection.North).fill(struts, mbu);
    roof.getFace(CuboidDirection.West).fill(struts, mbu);
    roof.getFace(CuboidDirection.South).fill(struts, mbu);
  }
  /**
   * Use Bresenham's algorithm to draw line between two squares on the board
   *
   * @param from Square index of the first square
   * @param to Square index of the second square
   * @param isHighlighting True if drawing a highlight, false if erasing it
   */
  private void drawHighlightLine(int from, int to, boolean isHighlighting) {
    if (from < 0 || to < 0 || from >= 64 || to >= 64) {
      return;
    }

    Cuboid s1 = getSquare(Chess.sqiToRow(from), Chess.sqiToCol(from));
    Cuboid s2 = getSquare(Chess.sqiToRow(to), Chess.sqiToCol(to));
    Location loc1 = s1.getRelativeBlock(s1.getSizeX() / 2, 0, s1.getSizeZ() / 2).getLocation();
    Location loc2 = s2.getRelativeBlock(s2.getSizeX() / 2, 0, s2.getSizeZ() / 2).getLocation();

    int dx = Math.abs(loc1.getBlockX() - loc2.getBlockX());
    int dz = Math.abs(loc1.getBlockZ() - loc2.getBlockZ());
    int sx = loc1.getBlockX() < loc2.getBlockX() ? 1 : -1;
    int sz = loc1.getBlockZ() < loc2.getBlockZ() ? 1 : -1;
    int err = dx - dz;

    while (loc1.getBlockX() != loc2.getBlockX() || loc1.getBlockZ() != loc2.getBlockZ()) {
      int sqi = getSquareAt(loc1);
      MaterialData m =
          isHighlighting
              ? boardStyle.getHighlightMaterial(Chess.isWhiteSquare(sqi))
              : (Chess.isWhiteSquare(sqi)
                  ? boardStyle.getWhiteSquareMaterial()
                  : boardStyle.getBlackSquareMaterial());
      loc1.getBlock().setTypeIdAndData(m.getItemTypeId(), m.getData(), false);
      int e2 = 2 * err;
      if (e2 > -dz) {
        err -= dz;
        loc1.add(sx, 0, 0);
      }
      if (e2 < dx) {
        err += dx;
        loc1.add(0, 0, sz);
      }
    }
  }