#getEntites

27 messages · Page 1 of 1 (latest)

wind stratus
#
ServerEvents.tick(event => {
    const targetDimension = 'minecraft:the_end'; 
    const teleportY = 80; 
    event.server.level.getEntities().forEach(entity => {
        if (entity.getY() > 200) {
            entity.teleportTo(targetDimension, entity.getX(), teleportY, entity.getX(), entity.getYaw(), 0);
        }
    });
});```

I keep getting the error 

[12:59:05] [ERROR] ! addonpack_ss:kubejs_scripts/earthorbit.js#6: Error in 'ServerEvents.tick': TypeError: Cannot call method "getEntities" of undefined
arctic gardenBOT
#

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

craggy vortex
#

iirc it's just event.level

#

also you have the .getX() twice

#

you probably want getX() and getZ()

wind stratus
#

ah thank you I just noticed that XD

#

Unfortunately it still doesn't work, same error

'ServerEvents.tick': TypeError: Cannot call method "getEntities" of undefined
craggy vortex
#

oh yeah sorry server tick has no "default" level

#

you would need to do event.server.getLevel('minecraft:the_end')

wind stratus
#

Where would I put that
Sorry I'm still kinda new to this

craggy vortex
#

where you currently have event.server.level

#

but what are you trying to achieve with this?

#

and why?

wind stratus
#

go above y = 200 and teleport to another dimension and the goal is to try make some sort of compatbility between Valk skies and Ad astra

#

I've already sorted the oxygen issues

#

tried to sort the freezing xD

craggy vortex
#

also you may want to run this only every second instead

wind stratus
craggy vortex
craggy vortex
wind stratus
wind stratus
#

Also it works now thank you

craggy vortex
#

this is probably what you want and only runs every second, the dimension where the teleport takes place from is the overworld

ServerEvents.tick(event => {
    let level = event.server.getLevel('minecraft:overworld')
    if(level.time % 20 != 0) return
    const targetDimension = 'minecraft:the_end' 
    const teleportY = 80
    level.getEntities().forEach(entity => {
        if (entity.getY() > 200) {
            entity.teleportTo(targetDimension, entity.getX(), teleportY, entity.getZ(), entity.getYaw(), 0)
        }
    })
})
trail ravine
#

Hi, VS2 Ships aren't entities