mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-30 13:08:19 +01:00
Add getters for chunk coordinates in Point
Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
parent
a5b6af34bd
commit
96bfc4c6fa
@ -72,6 +72,18 @@ public interface Point {
|
||||
return (int) Math.floor(z());
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@Contract(pure = true)
|
||||
default int chunkX() {
|
||||
return ChunkUtils.getChunkCoordinate(x());
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
@Contract(pure = true)
|
||||
default int chunkZ() {
|
||||
return ChunkUtils.getChunkCoordinate(z());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a point with a modified X coordinate based on its value.
|
||||
*
|
||||
@ -241,7 +253,6 @@ public interface Point {
|
||||
* @return true if 'this' is in the same chunk as {@code point}
|
||||
*/
|
||||
default boolean sameChunk(@NotNull Point point) {
|
||||
return ChunkUtils.getChunkCoordinate(x()) == ChunkUtils.getChunkCoordinate(point.x()) &&
|
||||
ChunkUtils.getChunkCoordinate(z()) == ChunkUtils.getChunkCoordinate(point.z());
|
||||
return chunkX() == point.chunkX() && chunkZ() == point.chunkZ();
|
||||
}
|
||||
}
|
||||
|
@ -1210,8 +1210,8 @@ public class Entity implements Viewable, Tickable, TagHandler, PermissionHandler
|
||||
if (instance != null) {
|
||||
final int lastChunkX = currentChunk.getChunkX();
|
||||
final int lastChunkZ = currentChunk.getChunkZ();
|
||||
final int newChunkX = ChunkUtils.getChunkCoordinate(newPosition.x());
|
||||
final int newChunkZ = ChunkUtils.getChunkCoordinate(newPosition.z());
|
||||
final int newChunkX = newPosition.chunkX();
|
||||
final int newChunkZ = newPosition.chunkZ();
|
||||
if (lastChunkX != newChunkX || lastChunkZ != newChunkZ) {
|
||||
// Entity moved in a new chunk
|
||||
final Chunk newChunk = instance.getChunk(newChunkX, newChunkZ);
|
||||
|
@ -167,8 +167,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
* @param point the chunk position
|
||||
*/
|
||||
public @NotNull CompletableFuture<@NotNull Chunk> loadChunk(@NotNull Point point) {
|
||||
return loadChunk(ChunkUtils.getChunkCoordinate(point.x()),
|
||||
ChunkUtils.getChunkCoordinate(point.z()));
|
||||
return loadChunk(point.chunkX(), point.chunkZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,8 +188,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
* @return a {@link CompletableFuture} completed once the chunk has been processed, null if not loaded
|
||||
*/
|
||||
public @NotNull CompletableFuture<@Nullable Chunk> loadOptionalChunk(@NotNull Point point) {
|
||||
return loadOptionalChunk(ChunkUtils.getChunkCoordinate(point.x()),
|
||||
ChunkUtils.getChunkCoordinate(point.z()));
|
||||
return loadOptionalChunk(point.chunkX(), point.chunkZ());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -556,7 +554,7 @@ public abstract class Instance implements BlockGetter, BlockSetter, Tickable, Ta
|
||||
* @return the chunk at the given position, null if not loaded
|
||||
*/
|
||||
public @Nullable Chunk getChunkAt(@NotNull Point point) {
|
||||
return getChunkAt(point.x(), point.z());
|
||||
return getChunk(point.chunkX(), point.chunkZ());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -78,7 +78,8 @@ public final class ChunkUtils {
|
||||
}
|
||||
|
||||
public static boolean isLoaded(@NotNull Instance instance, @NotNull Point point) {
|
||||
return isLoaded(instance, point.x(), point.z());
|
||||
final Chunk chunk = instance.getChunk(point.chunkX(), point.chunkZ());
|
||||
return isLoaded(chunk);
|
||||
}
|
||||
|
||||
public static Chunk retrieve(Instance instance, Chunk originChunk, double x, double z) {
|
||||
|
Loading…
Reference in New Issue
Block a user