#How can I find the closest entity to a mob when it's spawned?

5 messages · Page 1 of 1 (latest)

near light
#

I'm working on a script to modify boss rifts when they're spawned from a specific boss, particularly bosses of mass destruction ones. The first step is figuring out what boss spawned the rift, and I thought the best way to test that would to check for the closest entity, since the boss rifts are spawned directly on the entity when they die. Right now I've got this

EntityEvents.spawned('bossrifts:boss_rift', event => {

    const rift = event.entity
    const entitiesNear = rift.level.getNearbyEntities(rift,rift.distanceToEntitySqr() < 100)
    console.log("Nearby: "+entitiesNear)
})

the part I'm struggling with is I know the code const entitiesNear = rift.level.getNearbyEntities(rift,rift.distanceToEntitySqr() < 100) is incorrect, but I don't know what the correct method would be. I just don't know every function and how to use it, even with probejs.

olive bladeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

spiral mango
#

doesnt getNearbyEntities return entitiES? if so, you need to iterate through every entity and check distance

near light
#

Wait, I think it's because the rift isn't a living entity, so it doesn't have the function for nearbyentities

#

So the question is how to get all nearby entities to a non-living entity?