Ejemplo n.º 1
0
  /** Make the copy from world. */
  public void copy() {
    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          int index = y * width * length + z * width + x;
          blocks[index] = (byte) CraftBook.getBlockID(origin.add(x, y, z));
          data[index] = (byte) CraftBook.getBlockData(origin.add(x, y, z));
        }
      }
    }

    findTestOffset();
  }
Ejemplo n.º 2
0
  /** Paste to world. */
  public void paste(BlockBag bag) throws BlockSourceException {
    DoubleArrayList<Vector, byte[]> queueAfter = new DoubleArrayList<Vector, byte[]>(false);
    DoubleArrayList<Vector, byte[]> queueLast = new DoubleArrayList<Vector, byte[]>(false);

    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          int index = y * width * length + z * width + x;
          Vector pt = origin.add(x, y, z);

          if (BlockType.shouldPlaceLast(CraftBook.getBlockID(pt))) {
            CraftBook.setBlockID(pt, 0);
          }

          if (BlockType.shouldPlaceLast(blocks[index])) {
            queueLast.put(pt, new byte[] {blocks[index], data[index]});
          } else {
            queueAfter.put(pt, new byte[] {blocks[index], data[index]});
          }
        }
      }
    }

    for (Map.Entry<Vector, byte[]> entry : queueAfter) {
      byte[] v = entry.getValue();
      try {
        bag.setBlockID(entry.getKey(), v[0]);
        if (BlockType.usesData(v[0])) {
          CraftBook.setBlockData(entry.getKey(), v[1]);
        }
      } catch (OutOfBlocksException e) {
        // Eat error
      }
    }

    for (Map.Entry<Vector, byte[]> entry : queueLast) {
      byte[] v = entry.getValue();
      try {
        bag.setBlockID(entry.getKey(), v[0]);
        if (BlockType.usesData(v[0])) {
          CraftBook.setBlockData(entry.getKey(), v[1]);
        }
      } catch (OutOfBlocksException e) {
        // Eat error
      }
    }

    bag.flushChanges();
  }
Ejemplo n.º 3
0
  /** Clear the area. */
  public void clear(BlockBag bag) throws BlockSourceException {
    List<Vector> queued = new ArrayList<Vector>();

    for (int x = 0; x < width; x++) {
      for (int y = 0; y < height; y++) {
        for (int z = 0; z < length; z++) {
          Vector pt = origin.add(x, y, z);
          if (BlockType.shouldPlaceLast(CraftBook.getBlockID(pt))) {
            bag.setBlockID(pt, 0);
          } else {
            // Can't destroy these blocks yet
            queued.add(pt);
          }
        }
      }
    }

    for (Vector pt : queued) {
      bag.setBlockID(pt, 0);
    }

    bag.flushChanges();
  }
Ejemplo n.º 4
0
 /**
  * Returns true if the bridge should be turned 'off'.
  *
  * @return
  */
 public boolean shouldClear() {
   Vector v = origin.add(testOffset);
   return CraftBook.getBlockID(v) != 0;
 }