Ejemplo n.º 1
0
  /**
   * Restores to world.
   *
   * @param editSession
   * @throws MaxChangedBlocksException
   */
  public void restore(EditSession editSession) 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()) {
          BaseBlock block = chunk.getBlock(pos);
          editSession.setBlock(pos, block);
        }
      } 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();
      }
    }
  }
Ejemplo n.º 2
0
  /**
   * Find needed chunks in the region.
   *
   * @param region
   */
  private void findNeededChunks(Region region) {
    // First, we need to group points by chunk so that we only need
    // to keep one chunk in memory at any given moment
    for (Vector pos : region) {
      BlockVector2D chunkPos = ChunkStore.toChunk(pos);

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

      neededChunks.get(chunkPos).add(pos);
    }
  }
Ejemplo n.º 3
0
  /**
   * Find needed chunks in the cuboid of the region.
   *
   * @param region
   */
  private void findNeededCuboidChunks(Region region) {
    Vector min = region.getMinimumPoint();
    Vector max = region.getMaximumPoint();

    // First, we need to group points by chunk so that we only need
    // to keep one chunk in memory at any given moment
    for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) {
      for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) {
        for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) {
          Vector pos = new Vector(x, y, z);
          BlockVector2D chunkPos = ChunkStore.toChunk(pos);

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

          neededChunks.get(chunkPos).add(pos);
        }
      }
    }
  }