@bedrock-oss/bedrock-boost
    Preparing search index...

    Function jobProgressPromise

    • Runs a job and returns a promise that resolves when the job is done. The promise also reports progress once per tick.

      Type Parameters

      • Progress
      • Result

      Parameters

      • generator: Generator<Progress, Result, void>

        The generator function to run.

      • onProgress: (progress: Progress) => void

        The function to call when progress is reported.

      Returns Promise<Result>

      A promise that resolves when the job is done.

      const dimension = world.getDimension(MinecraftDimensionTypes.overworld);
      function* generator(startLocation: Vec3): Generator<number, Block | undefined, void> {
      const total = 10 * 10 * 10;
      for (let x = 0; x < 10; x++) {
      for (let z = 0; z < 10; z++) {
      for (let y = 0; y < 10; y++) {
      const location = startLocation.add(x, y, z);
      const block = dimension.getBlock(location);
      if (block && block.isSolid) {
      return block;
      }
      yield (x * 10 * 10 + z * 10 + y) / total;
      }
      }
      }
      }
      jobProgressPromise(generator(Vec3.from(0, 0, 0)), console.log)
      .then(console.log);