#Is there anyway to invert a bounding box detection with .getPlayers();
1 messages · Page 1 of 1 (latest)
Fyi I have this currently
world.getDimension('overworld').getPlayers(
{
location: { x: -2, y: 1, z: -2 },
volume: { x: 4, y: 4, z: 3.5 },
})
Still dont know how to do this :<
Your goal is to get players outside the bounding box?
Not very efficient but you could getAllPlayers() and then removes the ones in the box
Hm maybe
That's about the best way to do it. Wouldn't be too complicated—assuming a uniform player hitbox size, you could filter the array like this:
const loc = {x: -2, y: 1, z: -2};
const vol = {x: 4, y: 4, z: 3.5};
const outsidePlayers = world.getDimension('overworld').getPlayers({
location: loc
}).filter(player =>
player.location.x + 0.3 < loc.x &&
player.location.x - 0.3 > loc.x + vol.x &&
player.location.y + 1.8 < loc.y &&
player.location.y > loc.y + vol.y &&
player.location.z + 0.3 < loc.z &&
player.location.z - 0.3 > loc.z + vol.z
});
There is probably a cleaner way to write that using more arithmetic but I wouldn't know it