Package net.minestom.server.utils.chunk
Class ChunkUtils
java.lang.Object
net.minestom.server.utils.chunk.ChunkUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
blockIndexToChunkPositionX
(int index) Converts a block index to a chunk position X.static int
blockIndexToChunkPositionY
(int index) Converts a block index to a chunk position Y.static int
blockIndexToChunkPositionZ
(int index) Converts a block index to a chunk position Z.static int
ceilSection
(int coordinate) static int
floorSection
(int coordinate) 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.static void
forChunksInRange
(@NotNull Point point, int range, IntegerBiConsumer consumer) static void
forDifferingChunksInRange
(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull IntegerBiConsumer callback) static void
forDifferingChunksInRange
(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull IntegerBiConsumer newCallback, @NotNull IntegerBiConsumer oldCallback) static int
getBlockIndex
(int x, int y, int z) Gets the block index of a position.static @NotNull Point
getBlockPosition
(int index, int chunkX, int chunkZ) static int
getChunkCoordinate
(double xz) static int
getChunkCoordinate
(int xz) static int
getChunkCoordX
(long index) Converts a chunk index to its chunk X position.static int
getChunkCoordZ
(long index) Converts a chunk index to its chunk Z position.static int
getChunkCount
(int range) static long
getChunkIndex
(int chunkX, int chunkZ) Gets the chunk index of chunk coordinates.static long
getChunkIndex
(@NotNull Point point) static long
getChunkIndex
(@NotNull Chunk chunk) static boolean
Gets if a chunk is loaded.static boolean
static boolean
static @NotNull CompletableFuture
<Void> optionalLoadAll
(@NotNull Instance instance, long @NotNull [] chunks, @Nullable Consumer<Chunk> eachCallback) ExecutesInstance.loadOptionalChunk(int, int)
for the array of chunkschunks
with multiple callbacks,eachCallback
which is executed each time a new chunk is loaded andendCallback
when all the chunks in the array have been loaded.static Chunk
static Chunk
static int
toRegionCoordinate
(int chunkCoordinate) static int
toRegionLocal
(int chunkCoordinate) static int
toSectionRelativeCoordinate
(int xyz) Converts a global coordinate value to a section coordinate
-
Method Details
-
optionalLoadAll
@NotNull public static @NotNull CompletableFuture<Void> optionalLoadAll(@NotNull @NotNull Instance instance, long @NotNull [] chunks, @Nullable @Nullable Consumer<Chunk> eachCallback) ExecutesInstance.loadOptionalChunk(int, int)
for the array of chunkschunks
with multiple callbacks,eachCallback
which is executed each time a new chunk is loaded andendCallback
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 ifInstance.hasEnabledAutoChunkLoad()
returns false and the chunk is not already loaded.- Parameters:
instance
- the instance to load the chunks fromchunks
- the chunks to loaded, long value fromgetChunkIndex(int, int)
eachCallback
- the optional callback when a chunk get loaded- Returns:
- a
CompletableFuture
completed once all chunks have been processed
-
isLoaded
-
isLoaded
Gets if a chunk is loaded.- Parameters:
instance
- the instance to checkx
- instance X coordinatez
- instance Z coordinate- Returns:
- true if the chunk is loaded, false otherwise
-
isLoaded
-
retrieve
-
retrieve
-
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 XchunkZ
- the chunk Z- Returns:
- a number storing the chunk X and Z
-
getChunkIndex
-
getChunkIndex
-
getChunkCoordX
public static int getChunkCoordX(long index) Converts a chunk index to its chunk X position.- Parameters:
index
- the chunk index computed bygetChunkIndex(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 bygetChunkIndex(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
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 Xy
- the block Yz
- the block Z- Returns:
- an index which can be used to store and retrieve later data linked to a block position
-
getBlockPosition
- Parameters:
index
- an index computed fromgetBlockIndex(int, int, int)
chunkX
- the chunk XchunkZ
- 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 fromgetBlockIndex(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 fromgetBlockIndex(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 fromgetBlockIndex(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
-
toRegionCoordinate
public static int toRegionCoordinate(int chunkCoordinate) -
toRegionLocal
public static int toRegionLocal(int chunkCoordinate) -
floorSection
public static int floorSection(int coordinate) -
ceilSection
public static int ceilSection(int coordinate)
-