/** * Gets the loaded chunk at the given block coordinate position. * * @param bx The x coordinate * @param by The y coordinate * @param bz The z coordinate * @return The chunk, if available */ default Optional<Chunk> getChunkAtBlock(int bx, int by, int bz) { return getChunk(Sponge.getServer().getChunkLayout().forceToChunk(bx, by, bz)); }
/** * Gets the underlying chunk position. * * @return The underlying chunk position */ public Vector3i getChunkPosition() { if (this.chunkPosition == null) { this.chunkPosition = Sponge.getServer().getChunkLayout().forceToChunk(getBlockPosition()); } return this.chunkPosition; }
/** * Gets the chunk in the given direction from this chunk. * * @param direction The cardinal or ordinal direction to get the chunk from * @param shouldLoad Whether the server should load or generate the chunk * if unavailable * @return The neighbor chunk, if available or if {@code shouldLoad} is true */ default Optional<Chunk> getNeighbor(Direction direction, boolean shouldLoad) { Optional<Vector3i> neighborPosition = Sponge.getServer().getChunkLayout().moveToChunk(getPosition(), direction); return neighborPosition.flatMap(vector3i -> getWorld().loadChunk(vector3i, shouldLoad)); }
/** * Gets the chunk in the given direction from this chunk. * * @param direction The cardinal or ordinal direction to get the chunk from * @param shouldLoad Whether the server should load or generate the chunk if unavailable * @return The neighbor chunk, if available or if {@code shouldLoad} is true */ default Optional<Chunk> getNeighbor(Direction direction, boolean shouldLoad) { Optional<Vector3i> neighborPosition = Sponge.getServer().getChunkLayout().moveToChunk(getPosition(), direction); return neighborPosition.isPresent() ? getWorld().loadChunk(neighborPosition.get(), shouldLoad) : Optional.empty(); }
/** * Get the loaded chunk at the given block coordinate position. * * @param bx The x coordinate * @param by The y coordinate * @param bz The z coordinate * @return The chunk, if available */ default Optional<Chunk> getChunkAtBlock(int bx, int by, int bz) { return getChunk(Sponge.getServer().getChunkLayout().forceToChunk(bx, by, bz)); }
/** * Get the underlying chunk position. * * @return The underlying chunk position */ public Vector3i getChunkPosition() { if (this.chunkPosition == null) { this.chunkPosition = Sponge.getServer().getChunkLayout().forceToChunk(getBlockPosition()); } return this.chunkPosition; }
Vector3i pos = new Vector3i(x, y, z).add(min); Optional<Vector3i> chunkPos = Sponge.getServer().getChunkLayout().toChunk(pos); if (!chunkPos.isPresent()) { stop("Invalid chunk pos");