コード例 #1
0
ファイル: CuboidCopy.java プロジェクト: Kerden/craftbook
  /** 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();
  }
コード例 #2
0
ファイル: CuboidCopy.java プロジェクト: Kerden/craftbook
  /**
   * Load a copy.
   *
   * @param file
   * @return
   * @throws IOException
   * @throws CuboidCopyException
   */
  public static CuboidCopy load(File file) throws IOException, CuboidCopyException {
    FileInputStream in = new FileInputStream(file);
    DataInputStream reader = new DataInputStream(in);

    int x, y, z;
    int width, height, length;
    byte[] blocks;
    byte[] data;

    try {
      @SuppressWarnings("unused")
      byte version = reader.readByte();
      x = reader.readInt();
      y = reader.readInt();
      z = reader.readInt();
      width = reader.readInt();
      height = reader.readInt();
      length = reader.readInt();
      int size = width * height * length;
      blocks = new byte[size];
      data = new byte[size];
      if (reader.read(blocks, 0, size) != size) {
        throw new CuboidCopyException("File error: Bad size");
      }
      data = new byte[size];
      if (reader.read(data, 0, size) != size) {
        throw new CuboidCopyException("File error: Bad size");
      }
    } finally {
      try {
        in.close();
      } catch (IOException e) {
      }
    }

    CuboidCopy copy = new CuboidCopy();
    copy.origin = new Vector(x, y, z);
    copy.width = width;
    copy.height = height;
    copy.length = length;
    copy.blocks = blocks;
    copy.data = data;
    copy.findTestOffset();

    return copy;
  }