#How can I get all the entities in a certain radius around a non-living entity?

1 messages · Page 1 of 1 (latest)

real warren
#

I'm trying to get boss rifts from the boss rift mod to move depending on the boss they generate from. To do this, I figured I would need to get all nearby entities, and ended up with this (Minecart is for easier debugging)

EntityEvents.spawned('minecraft:minecart', event => {

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

This issue I've found is that the rift is not a living entity, and so to my knowledge, the getNearbyEntities function does not work for this. I'm not quite sure how to do this when the entity isn't living.

agile nexusBOT
#

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

wild carbon
#

who the hell is rift?

real warren
# wild carbon who the hell is rift?

rift as in the mob or the code?
The code is meant to be the spawned entity, in this case, a minecart.
The actual rift itself is from the mod Boss Rifts. It's a non-living entity.

wild carbon
#

@real warren is it ai generated or what?

real warren
#

My code is not ai generated if that's what you mean

wild carbon
#

are u sure the function getNearbyEntities exists?

real warren
#

It does, but it doesn't seem to work for non living entities

wild carbon
#

[19:33:16] [ERROR] ! example.js#4: Error in 'EntityEvents.spawned': TypeError: Cannot find function getNearbyEntities in object Minecart['Minecart'/200, l='ServerLevel[New World]', x=-35.50, y=69.06, z=-35.50].

#

did u even checked the logs?

#

i told you there is no such function, because it doesnt even make sense

real warren
#

Yes. I said it exists but it isn't for non living entities.

wild carbon
#

LIE

real warren
#

Okay, I just tested it again. I could've sworn it worked with mobs like zombies.

#

Oh wait, it was a function for level maybe? I'm checking it out again

wild carbon
#

nah

#

there is no such function anywhere

real warren
#

It definitely looks like it is

wild carbon
#

do u have other kubejss addons or what?

#

what the hell

#

now i have too

real warren
#

Applied KubeJS, EntityJS, LootJS, ProbeJS, OccultismJS and the irons spellbooks one

#

It could be that I'm using the function wrong. I'm kinda confused on what I need to put in each.

wild carbon
#

ok so here is the script you need

#

EntityEvents.spawned("minecart", e => {
    let entityAABB = e.entity.boundingBox.inflate(2) //argument is radius in blocks
    let entitiesNear = e.entity.level.getEntitiesWithin(entityAABB)
    console.log(entitiesNear)
})