Beispiel #1
0
  private void checkAndAddBlock(Vector pos) {
    if (editSession.getMask() != null && !editSession.getMask().test(pos)) return;

    BlockVector2D chunkPos = ChunkStore.toChunk(pos);

    // Unidentified chunk
    if (!neededChunks.containsKey(chunkPos)) {
      neededChunks.put(chunkPos, new ArrayList<Vector>());
    }

    neededChunks.get(chunkPos).add(pos);
  }
Beispiel #2
0
  /**
   * Restores to world.
   *
   * @throws MaxChangedBlocksException
   */
  public void restore() throws MaxChangedBlocksException {

    missingChunks = new ArrayList<Vector2D>();
    errorChunks = new ArrayList<Vector2D>();

    // Now let's start restoring!
    for (Map.Entry<BlockVector2D, ArrayList<Vector>> entry : neededChunks.entrySet()) {
      BlockVector2D chunkPos = entry.getKey();
      Chunk chunk;

      try {
        chunk = chunkStore.getChunk(chunkPos, editSession.getWorld());
        // Good, the chunk could be at least loaded

        // Now just copy blocks!
        for (Vector pos : entry.getValue()) {
          try {
            BaseBlock block = chunk.getBlock(pos);
            editSession.rawSetBlock(pos, block);
          } catch (DataException e) {
            // this is a workaround: just ignore for now
          }
        }
      } catch (MissingChunkException me) {
        missingChunks.add(chunkPos);
      } catch (MissingWorldException me) {
        errorChunks.add(chunkPos);
        lastErrorMessage = me.getMessage();
      } catch (DataException de) {
        errorChunks.add(chunkPos);
        lastErrorMessage = de.getMessage();
      } catch (IOException ioe) {
        errorChunks.add(chunkPos);
        lastErrorMessage = ioe.getMessage();
      }
    }
  }