This runInterval causes a watchdog slow running script warning (about 6.5ms):
system.runInterval(() => {
const players = world.getPlayers();
var dimensions = [];
players.forEach((player) => {
if (player.isValid()) {
if (!dimensions.includes(player.dimension)) dimensions.push(player.dimension);
}
});
dimensions.forEach((dimension) => {
dimension.getEntities({ tags: ["billey_thrown_piranha"] }).forEach((piranha) => {
if (piranha.target) {
if (piranha.target.matches({ location: piranha.location, maxDistance: 2 })) {
piranha.teleport(piranha.target.location);
}
if (piranha.target.matches({ location: piranha.location, maxDistance: 1 })) {
piranha.target.applyDamage(1, { cause: "entityAttack", damagingEntity: piranha });
}
}
});
});
});
Also the warning doesn't get spammed it just appears once every time I've thrown like 10 piranhas.
Anyone know a more efficient way to do this?