Class ChunkUtils

java.lang.Object
net.minestom.server.utils.chunk.ChunkUtils

@Internal public final class ChunkUtils extends Object
  • Method Details

    • optionalLoadAll

      @NotNull public static @NotNull CompletableFuture<Void> optionalLoadAll(@NotNull @NotNull Instance instance, long @NotNull [] chunks, @Nullable @Nullable Consumer<Chunk> eachCallback)
      Executes Instance.loadOptionalChunk(int, int) for the array of chunks chunks with multiple callbacks, eachCallback which is executed each time a new chunk is loaded and endCallback when all the chunks in the array have been loaded.

      Be aware that Instance.loadOptionalChunk(int, int) can give a null chunk in the callback if Instance.hasEnabledAutoChunkLoad() returns false and the chunk is not already loaded.

      Parameters:
      instance - the instance to load the chunks from
      chunks - the chunks to loaded, long value from getChunkIndex(int, int)
      eachCallback - the optional callback when a chunk get loaded
      Returns:
      a CompletableFuture completed once all chunks have been processed
    • isLoaded

      public static boolean isLoaded(@Nullable @Nullable Chunk chunk)
    • isLoaded

      public static boolean isLoaded(@NotNull @NotNull Instance instance, double x, double z)
      Gets if a chunk is loaded.
      Parameters:
      instance - the instance to check
      x - instance X coordinate
      z - instance Z coordinate
      Returns:
      true if the chunk is loaded, false otherwise
    • isLoaded

      public static boolean isLoaded(@NotNull @NotNull Instance instance, @NotNull @NotNull Point point)
    • retrieve

      public static Chunk retrieve(Instance instance, Chunk originChunk, double x, double z)
    • retrieve

      public static Chunk retrieve(Instance instance, Chunk originChunk, Point position)
    • getChunkCoordinate

      public static int getChunkCoordinate(double xz)
      Parameters:
      xz - the instance coordinate to convert
      Returns:
      the chunk X or Z based on the argument
    • getChunkCoordinate

      public static int getChunkCoordinate(int xz)
    • getChunkIndex

      public static long getChunkIndex(int chunkX, int chunkZ)
      Gets the chunk index of chunk coordinates.

      Used when you want to store a chunk somewhere without using a reference to the whole object (as this can lead to memory leaks).

      Parameters:
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      a number storing the chunk X and Z
    • getChunkIndex

      public static long getChunkIndex(@NotNull @NotNull Chunk chunk)
    • getChunkIndex

      public static long getChunkIndex(@NotNull @NotNull Point point)
    • getChunkCoordX

      public static int getChunkCoordX(long index)
      Converts a chunk index to its chunk X position.
      Parameters:
      index - the chunk index computed by getChunkIndex(int, int)
      Returns:
      the chunk X based on the index
    • getChunkCoordZ

      public static int getChunkCoordZ(long index)
      Converts a chunk index to its chunk Z position.
      Parameters:
      index - the chunk index computed by getChunkIndex(int, int)
      Returns:
      the chunk Z based on the index
    • getChunkCount

      public static int getChunkCount(int range)
    • forDifferingChunksInRange

      public static void forDifferingChunksInRange(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull @NotNull IntegerBiConsumer callback)
    • forDifferingChunksInRange

      public static void forDifferingChunksInRange(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull @NotNull IntegerBiConsumer newCallback, @NotNull @NotNull IntegerBiConsumer oldCallback)
    • forChunksInRange

      public static void forChunksInRange(int chunkX, int chunkZ, int range, IntegerBiConsumer consumer)
      New implementation comes from Krypton which comes from kotlin port by Esophose, which comes from a stackoverflow answer.
    • forChunksInRange

      public static void forChunksInRange(@NotNull @NotNull Point point, int range, IntegerBiConsumer consumer)
    • getBlockIndex

      public static int getBlockIndex(int x, int y, int z)
      Gets the block index of a position.
      Parameters:
      x - the block X
      y - the block Y
      z - the block Z
      Returns:
      an index which can be used to store and retrieve later data linked to a block position
    • getBlockPosition

      @NotNull public static @NotNull Point getBlockPosition(int index, int chunkX, int chunkZ)
      Parameters:
      index - an index computed from getBlockIndex(int, int, int)
      chunkX - the chunk X
      chunkZ - the chunk Z
      Returns:
      the instance position of the block located in index
    • blockIndexToChunkPositionX

      public static int blockIndexToChunkPositionX(int index)
      Converts a block index to a chunk position X.
      Parameters:
      index - an index computed from getBlockIndex(int, int, int)
      Returns:
      the chunk position X (O-15) of the specified index
    • blockIndexToChunkPositionY

      public static int blockIndexToChunkPositionY(int index)
      Converts a block index to a chunk position Y.
      Parameters:
      index - an index computed from getBlockIndex(int, int, int)
      Returns:
      the chunk position Y of the specified index
    • blockIndexToChunkPositionZ

      public static int blockIndexToChunkPositionZ(int index)
      Converts a block index to a chunk position Z.
      Parameters:
      index - an index computed from getBlockIndex(int, int, int)
      Returns:
      the chunk position Z (O-15) of the specified index
    • toSectionRelativeCoordinate

      public static int toSectionRelativeCoordinate(int xyz)
      Converts a global coordinate value to a section coordinate
      Parameters:
      xyz - global coordinate
      Returns:
      section coordinate
    • floorSection

      public static int floorSection(int coordinate)
    • ceilSection

      public static int ceilSection(int coordinate)