/**
   * Draw the chess piece represented by stone into the given row and column. The actual blocks
   * drawn depend on the board's current chess set.
   *
   * @param row
   * @param col
   * @param stone
   */
  public void paintChessPiece(int row, int col, int stone) {
    // for entity sets, just check that the entity is still at (row,col)
    // for block sets, get the stone and paste its data into the region at (row,col)
    ChessSet cSet = designer != null ? designer.getChessSet() : chessSet;
    if (cSet.hasMovablePieces()) {
      // we don't paint movable pieces; moveChessPiece() can handle those
      return;
    }
    Cuboid region = getPieceRegion(row, col);
    MassBlockUpdate mbu =
        CraftMassBlockUpdate.createMassBlockUpdater(
            ChessCraft.getInstance(), getBoard().getWorld());
    region.fill(0, (byte) 0, mbu);
    if (stone != Chess.NO_STONE) {
      ChessStone cStone = cSet.getStone(stone, getRotation());
      if (cStone != null) {
        cStone.paint(region, mbu);
      } else {
        LogUtils.severe("unknown chess stone " + stone);
      }
    }

    region.expand(CuboidDirection.Down, 1).forceLightLevel(boardStyle.getLightLevel());
    mbu.notifyClients();
    if (ChessCraft.getInstance().getDynmapIntegration() != null) {
      ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(region);
    }
  }
Exemple #2
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);
    }
  }
 public void moveChessPiece(int fromSqi, int toSqi, int captureSqi, int promoteStone) {
   if (chessSet.hasMovablePieces()) {
     ChessStone stone = chessSet.getStoneAt(fromSqi);
     int colour = Chess.stoneToColor(stone.getStone());
     Location to =
         getSquare(Chess.sqiToRow(toSqi), Chess.sqiToCol(toSqi)).getCenter().add(0, 0.5, 0);
     float yaw = getRotation().getYaw();
     if (colour == Chess.BLACK) {
       yaw = (yaw + 180) % 360;
     }
     to.setYaw(yaw);
     chessSet.movePiece(fromSqi, toSqi, captureSqi, to, promoteStone);
   } else {
     // TODO: maybe some particle effect showing move direction?
   }
 }