Package net.minestom.server.utils.chunk
Class ChunkUtils
java.lang.Object
net.minestom.server.utils.chunk.ChunkUtils
-
Method Summary
Modifier and TypeMethodDescriptionstatic intblockIndexToChunkPositionX(int index) Converts a block index to a chunk position X.static intblockIndexToChunkPositionY(int index) Converts a block index to a chunk position Y.static intblockIndexToChunkPositionZ(int index) Converts a block index to a chunk position Z.static intceilSection(int coordinate) static intfloorSection(int coordinate) static voidforChunksInRange(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 voidforChunksInRange(@NotNull Point point, int range, IntegerBiConsumer consumer) static voidforDifferingChunksInRange(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull IntegerBiConsumer callback) static voidforDifferingChunksInRange(int newChunkX, int newChunkZ, int oldChunkX, int oldChunkZ, int range, @NotNull IntegerBiConsumer newCallback, @NotNull IntegerBiConsumer oldCallback) static intgetBlockIndex(int x, int y, int z) Gets the block index of a position.static @NotNull PointgetBlockPosition(int index, int chunkX, int chunkZ) static intgetChunkCoordinate(double xz) static intgetChunkCoordinate(int xz) static intgetChunkCoordX(long index) Converts a chunk index to its chunk X position.static intgetChunkCoordZ(long index) Converts a chunk index to its chunk Z position.static intgetChunkCount(int range) static longgetChunkIndex(int chunkX, int chunkZ) Gets the chunk index of chunk coordinates.static longgetChunkIndex(@NotNull Point point) static longgetChunkIndex(@NotNull Chunk chunk) static booleanGets if a chunk is loaded.static booleanstatic booleanstatic @NotNull CompletableFuture<Void> optionalLoadAll(@NotNull Instance instance, long @NotNull [] chunks, @Nullable Consumer<Chunk> eachCallback) ExecutesInstance.loadOptionalChunk(int, int)for the array of chunkschunkswith multiple callbacks,eachCallbackwhich is executed each time a new chunk is loaded andendCallbackwhen all the chunks in the array have been loaded.static Chunkstatic Chunkstatic inttoSectionRelativeCoordinate(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 chunkschunkswith multiple callbacks,eachCallbackwhich is executed each time a new chunk is loaded andendCallbackwhen 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
CompletableFuturecompleted 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
-
floorSection
public static int floorSection(int coordinate) -
ceilSection
public static int ceilSection(int coordinate)
-