Class RelativeBlockBatch

java.lang.Object
net.minestom.server.instance.batch.RelativeBlockBatch
All Implemented Interfaces:
Batch<Runnable>, Block.Setter

public class RelativeBlockBatch extends Object implements Batch<Runnable>
A Batch which can be used when changes are required across chunk borders, and are going to be reused in different places. If translation is not required, AbsoluteBlockBatch should be used instead for efficiency purposes.

Coordinates are relative to (0, 0, 0) with some limitations. All coordinates must fit within a 16 bit integer of the first coordinate (32,767 blocks). If blocks must be spread out over a larger area, an AbsoluteBlockBatch should be used.

All inverses are AbsoluteBlockBatchs and represent the inverse of the application at the position which it was applied.

If a batch will be used multiple times at the same coordinate, it is suggested to convert it to an AbsoluteBlockBatch and cache the result. Application of absolute batches (currently) is significantly faster than their relative counterpart.

See Also:
  • Constructor Details

    • RelativeBlockBatch

      public RelativeBlockBatch()
    • RelativeBlockBatch

      public RelativeBlockBatch(BatchOption options)
  • Method Details

    • setBlock

      public void setBlock(int x, int y, int z, @NotNull @NotNull Block block)
      Specified by:
      setBlock in interface Block.Setter
    • clear

      public void clear()
      Description copied from interface: Batch
      Removes all block data from this batch.
      Specified by:
      clear in interface Batch<Runnable>
    • apply

      public AbsoluteBlockBatch apply(@NotNull @NotNull Instance instance, @Nullable @Nullable Runnable callback)
      Applies this batch to the given instance at the origin (0, 0, 0) of the instance.
      Specified by:
      apply in interface Batch<Runnable>
      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
    • apply

      public AbsoluteBlockBatch apply(@NotNull @NotNull Instance instance, @NotNull @NotNull Point position, @Nullable @Nullable Runnable callback)
      Applies this batch to the given instance at the given block position.
      Parameters:
      instance - The instance in which the batch should be applied
      position - The position to apply the batch
      callback - The callback to be executed when the batch is applied
      Returns:
      The inverse of this batch, if inverse is enabled in the BatchOption
    • apply

      public AbsoluteBlockBatch apply(@NotNull @NotNull Instance instance, int x, int y, int z, @Nullable @Nullable Runnable callback)
      Applies this batch to the given instance at the given position.
      Parameters:
      instance - The instance in which the batch should be applied
      x - The x position to apply the batch
      y - The y position to apply the batch
      z - The z position to apply the batch
      callback - The callback to be executed when the batch is applied
      Returns:
      The inverse of this batch, if inverse is enabled in the BatchOption
    • applyUnsafe

      public AbsoluteBlockBatch applyUnsafe(@NotNull @NotNull Instance instance, int x, int y, int z, @Nullable @Nullable Runnable callback)
      Applies this batch to the given instance at the given position, and execute the callback immediately when the blocks have been applied, int an unknown thread.
      Parameters:
      instance - The instance in which the batch should be applied
      x - The x position to apply the batch
      y - The y position to apply the batch
      z - The z position to apply the batch
      callback - The callback to be executed when the batch is applied
      Returns:
      The inverse of this batch, if inverse is enabled in the BatchOption
    • apply

      protected AbsoluteBlockBatch apply(@NotNull @NotNull Instance instance, int x, int y, int z, @Nullable @Nullable Runnable callback, boolean safeCallback)
      Applies this batch to the given instance at the given position, execute the callback depending on safeCallback.
      Parameters:
      instance - The instance in which the batch should be applied
      x - The x position to apply the batch
      y - The y position to apply the batch
      z - The z position to apply the batch
      callback - The callback to be executed when the batch is applied
      safeCallback - If true, the callback will be executed in the next instance update. Otherwise it will be executed immediately upon completion
      Returns:
      The inverse of this batch, if inverse is enabled in the BatchOption
    • toAbsoluteBatch

      @NotNull public @NotNull AbsoluteBlockBatch toAbsoluteBatch()
      Converts this batch to an absolute batch at the origin (0, 0, 0).
      Returns:
      An absolute batch of this batch at the origin
    • toAbsoluteBatch

      @NotNull public @NotNull AbsoluteBlockBatch toAbsoluteBatch(int x, int y, int z)
      Converts this batch to an absolute batch at the given coordinates.
      Parameters:
      x - The x position of the batch in the world
      y - The y position of the batch in the world
      z - The z position of the batch in the world
      Returns:
      An absolute batch of this batch at (x, y, z)