Interface Batch<C>

Type Parameters:
C - The callback function type.
All Superinterfaces:
Block.Setter
All Known Implementing Classes:
AbsoluteBlockBatch, ChunkBatch, RelativeBlockBatch

public interface Batch<C> extends Block.Setter
A Batch is a tool used to cache a list of block changes, and apply the changes whenever you want.

Batches offer a performance benefit because clients are not notified of any change until all of the blocks have been placed, and because changes can happen with less synchronization.

All batches may be rotated using {link}, however rotate operations do not mutate the batch, so the result should be cached if used multiple times.

If reversal is a desired behavior, batches may be applied in "reversal mode" using {link}. This operation will return a new batch with the blocks set to whatever they were before the batch was applied.

See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final ExecutorService
     
  • Method Summary

    Modifier and Type
    Method
    Description
    @Nullable Batch<C>
    apply(@NotNull Instance instance, C callback)
    Called to apply the batch to the given instance.
    default void
    Blocks the current thread until the batch is ready to be applied.
    void
    Removes all block data from this batch.
    default boolean
    Gets if the batch is ready to be applied to an instance.

    Methods inherited from interface net.minestom.server.instance.block.Block.Setter

    setBlock, setBlock
  • Field Details

  • Method Details

    • isReady

      default boolean isReady()
      Gets if the batch is ready to be applied to an instance.
      Returns:
      true if the batch is ready to apply
    • awaitReady

      default void awaitReady()
      Blocks the current thread until the batch is ready to be applied.
      See Also:
    • clear

      void clear()
      Removes all block data from this batch.
    • apply

      @Nullable @Nullable Batch<C> apply(@NotNull @NotNull Instance instance, @Nullable C callback)
      Called to apply the batch to the given instance.

      The implementation for all current batches executes the block updates in a dedicated pool, and runs the callback on the next instance update after block placement is complete. This means that the callback can be called up to 50ms after the blocks have been placed, however, it will be called in a determinable thread. If immediate execution of the callback is needed, see the unsafeApply method in each implementation.

      See the specific batch classes for alternative application methods.

      Parameters:
      instance - The instance in which the batch should be applied
      callback - The callback to be executed when the batch is applied
      Returns:
      The inverse of this batch, if inverse is enabled in the BatchOption