How to define the size of the safety area using getsafelcoation?

Hello So I’m trying to make it so that Entities like Ghasts which have a 4 by 4 area needed for them to spawn are able to do so without taking damage…aka use something like getSafeLocation(spawnlocation, y coordinates, x z cooreds). and then have it check to see if getSafeLocation is then 4 blocks wide by 4 blocks tall and filled with air. How would i go about doing this?

If you want to check the area that the entity takes up, using their ‘aabb’ SpongeAPI/Entity.java at b603d33516ea20dc8a1ceb66974656ebd341adc7 · SpongePowered/SpongeAPI · GitHub

Which stands for axis aligned bounding box,

essentially, their hitbox,

Then you can scan the world to see if any blocks you don’t want to be there are there.

SafeTeleport is going to be useless for you, as it’s been coded with human sized entities in mind, so I suggest iterating or using a block worker over the area you need to test, or PR/create an issue on the API for a method to get a valid mob spawn position.

Ok…noob but sponge(i hope) related question in regards to the using createEntityNaturally event…so for the IllegalArguementException…what conditon would i throw? I’ve seen it used as a boolean like this below

public Percentage(int value) {
if (value < 0 || value > 100) {
throw new IllegalArgumentException(Integer.toString(value));
}
this.value = value;
}
public int getValue() {
return value;
}

However as you can see it checks if the value is less than 0 and greater then 100…so my big question is for this piece

Entity entity = extent.createEntityNaturally(listResult, spawnLocation.getPosition());

What would I use to compare to throw an exception? like the example in the docs?

default Entity createEntityNaturally(EntityType type, Vector3i position) throws IllegalArgumentException,
IllegalStateException {
checkNotNull(position, “position”);
return createEntityNaturally(type, position.toDouble());
}