Utilising BlockVolume to retrieve blocks in a spherical radius

Hi,

I’m having trouble finding documentation (besides JavaDoc) on how BlockVolume should be used. I’m wanting to iterate over blocks in a spherical radius. I’ve had a look into ray tracing, but I’m not certain on which filters would be appropriate - or even if ray tracing would be the most efficient means of doing this. I’m using API v5. Help would be appreciated.

Thanks

The only thing I know for sure that ray tracing isn’t meant for that purpose. As it says, it is for a ray.
I don’t think that there currently is a way to retrieve 3d shapes like a sphere.

1 Like

Here is a method to iterate over all block pos in a spherical radius :

	public static List<Vector3i> getBlocks(Vector3d center, double radius) {
		List<Vector3i> l = new ArrayList<>();
		double radius2 = Math.pow(radius, 2);
		double cX = center.getX(), cY = center.getY(), cZ = center.getZ();
		int minX = (int) (cX - radius), minY = (int) (cY - radius), minZ = (int) (cZ - radius);
		int maxX = (int) (cX + radius), maxY = (int) (cY + radius), maxZ = (int) (cZ + radius);
		for (int x = minX; x < maxX; x++) {
			double x2 = Math.pow(cX - x, 2);
			for (int y = minY; y < maxY; y++) {
				double y2 = Math.pow(cY - y, 2);
				for (int z = minZ; z < maxZ; z++) {
					double z2 = Math.pow(cZ - z, 2);
					if (x2 + y2 + z2 <= radius2)
						l.add(new Vector3i(x, y, z));
				}
			}
		}
		return l;
	}

I don’t knows if it’s what you want, hopes that can help you.

1 Like

It’s not what I want, but more the old-fashioned way of doing things. I was hoping that there was a built-in means within the API to handle this. It’s horribly inefficient, especially as I’ll be doing lots of these operations every few ticks. I’ll probably write something with lambdas for now.

Do you need the order to be from closest to furthest away? because if not bounding it to an AABB and looping over that, skipping anything not within the radius will likely be quicker anyway if you are iterating in the same order that it’s aligned on memory.