#1369: Add World#getIntersectingChunks(BoundingBox)

By: Flo0 <flo.roma@web.de>
This commit is contained in:
CraftBukkit/Spigot 2024-04-01 09:43:49 +11:00
parent 3f9e7c4e39
commit 779b5137f8

View File

@ -146,6 +146,7 @@ import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.PotionType;
import org.bukkit.util.BiomeSearchResult;
import org.bukkit.util.BoundingBox;
import org.bukkit.util.NumberConversions;
import org.bukkit.util.RayTraceResult;
import org.bukkit.util.StructureSearchResult;
import org.bukkit.util.Vector;
@ -462,6 +463,25 @@ public class CraftWorld extends CraftRegionAccessor implements World {
return ret.entrySet().stream().collect(ImmutableMap.toImmutableMap(Map.Entry::getKey, (entry) -> entry.getValue().build()));
}
@NotNull
@Override
public Collection<Chunk> getIntersectingChunks(@NotNull BoundingBox boundingBox) {
List<Chunk> chunks = new ArrayList<>();
int minX = NumberConversions.floor(boundingBox.getMinX()) >> 4;
int maxX = NumberConversions.floor(boundingBox.getMaxX()) >> 4;
int minZ = NumberConversions.floor(boundingBox.getMinZ()) >> 4;
int maxZ = NumberConversions.floor(boundingBox.getMaxZ()) >> 4;
for (int x = minX; x <= maxX; x++) {
for (int z = minZ; z <= maxZ; z++) {
chunks.add(getChunkAt(x, z, false));
}
}
return chunks;
}
@Override
public boolean isChunkForceLoaded(int x, int z) {
return getHandle().getForcedChunks().contains(ChunkCoordIntPair.asLong(x, z));