#set world spawn in another dimension

91 messages · Page 1 of 1 (latest)

wary swallow
#

hey im trying to automaticly set the world spawn to the moon from ad astra. but the only thing that somewhat worked is this :

fossil sparrowBOT
#

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

wary swallow
#
PlayerEvents.loggedIn(event => {
    let player = event.player;
    let moon = World.get("ad_astra:moon");
    player.setSpawn(moon.getSpawnPos(), true);
    player.teleport(moon.getSpawnPos());
});```
#

but this sets the spawn point every time the world loads

#

i just want one that only does it once on world generation

orchid wren
#

if you're using 1.20.1 forge you can use this mod instead of kubejs if you want

#

i tried doing exactly the same as you want to do but i give up haha

wary swallow
#

it works

#

but i spawn underground

orchid wren
#

Hmm, its supposed to have a secure tp.class for what i see, but idk how it works entirely

#

For me it works fine, i created like 4/5 worlds and in everyone of them i spawned above

wary swallow
#

hm

#

thats weird

wary swallow
#

ad astras moon surface it at 105/110

#

not at 60

#

cuz thats where i spawned

orchid wren
#

Tbh i never had that problem haha

pastel swan
wary swallow
#

doesnt seem to work

#

i mean i put it into server scripts

deep oceanBOT
#

Never say 'it crashed', 'it errored', or 'it didn't work' without providing the full scripts and log/crash report!

#

Please send your KubeJS server log. It can be found at /minecraft/logs/kubejs/server.log.
If you are on 1.18 or 1.16 it will be called server.txt.
Please send the file directly, without links or snippets.

pastel swan
# wary swallow hm

wait is that the whole code you sent earlier? where are you getting "World" from?

#

also im pretty sure setSpawn is just not a method off of Player

#

same with teleport

#

it would be teleportTo and should have more arguements

#

where'd you get all this from? chatgpt?

#

yeah, most of that code is wrong so no need to send the error reports, try this one and if this doesnt work then send your server logs js PlayerEvents.loggedIn(event => { let { player, server } = event if (player.stages.has("first_login")) return let moon = server.getLevel("ad_astra:moon") let spawnPos = moon.getHeightmapPos("world_surface", new BlockPos(0, 0, 0)) player.setRespawnPosition(moon.dimensionKey, spawnPos, 0, true, false); player.teleportTo("ad_astra:moon", spawnPos.x, spawnPos.y, spawnPos.z, player.yaw, player.pitch); player.stages.add("first_login"); });

#

youll also want to either start a new world or remove the gamestage somehow like in an item right click event to troubleshoot otherwise youll still have the stage and it'll always return on your testsjs ItemEvents.rightClicked(event => { event.player.stages.remove("first_login"); })

deep oceanBOT
#

Paste version of server.log from @wary swallow

pastel swan
#

oh woops

#

the first arguement of setRespawnPosition takes in the resource key of the dimension, i just edited the above script to use that instead of Level directly, try it again js player.setRespawnPosition(moon.dimensionKey, spawnPos, 0, true, false);

wary swallow
#

i spawn in the void now

#

not sure if its the moon or not

#

but if i die im in the over world

pastel swan
#

ah, i think this is a similar issue to another ticket with finding heightmap pos, i think the way i fixed it was delaying it by a tick, lemme see if i can find it

wary swallow
#

yea i spawn on the moon

#

but at -90

pastel swan
deep oceanBOT
wary swallow
#

so

#

id have to use level.getBlockState(blockpos)

pastel swan
#

you'll have to iterate over the blocks until you find a block that sees the sky

wary swallow
#

hm

#

but how do i get it to load before i spawn

pastel swan
#

you dont need to, level.getBlock does what level.getHeightmapPos doesnt and loads it for you

#

try this script, i pretty much copied over the logic ```js
PlayerEvents.loggedIn(event => {
let { player, server } = event
if (player.stages.has("first_login")) return
try {
let moon = server.getLevel("ad_astra:moon")
let x = 0
let z = 0
let found = null
for (let y = moon.getMinBuildHeight(); y < moon.getMaxBuildHeight(); y++) {
let pos = new BlockPos(x, y, z)
if (
moon.canSeeSkyFromBelowWater(pos) &&
moon.getBlock(pos).blockState.fluidState.empty &&
moon.getBlock(pos.above()).blockState.isAir()
) {
found = pos.above()
break
}
}
if (found) {
player.setRespawnPosition(moon.dimensionKey, found, 0, true, false)
player.teleportTo("ad_astra:moon", found.x, found.y, found.z, player.yaw, player.pitch)
player.stages.add("first_login")
} else {
let spawnPos = moon.getHeightmapPos("world_surface", new BlockPos(x, 0, z))
player.setRespawnPosition(moon.dimensionKey, spawnPos, 0, true, false)
player.teleportTo("ad_astra:moon", spawnPos.x, spawnPos.y, spawnPos.z, player.yaw, player.pitch)
player.stages.add("first_login")
}
} catch (error) {
console.log(error)
}
})

wary swallow
#

uhh

#

layer events is not defined

deep oceanBOT
#

Paste version of server.log from @wary swallow

pastel swan
#

PlayerEvents is not defined?

wary swallow
#

nope

#

layer

pastel swan
#

yeah you didnt copy it fully then

#

you're missing the P in playerevents

wary swallow
#

oh

#

my bad

pastel swan
#

lol all g

wary swallow
#

wow

#

it works

#

thanks

#

would this be a good example script ?

#

idk

pastel swan
#

possibly

#

there might already be one of these though im not sure

wary swallow
#

if i looked right

#

there isnt one

#

but you do respawn in the air

#

but maybe thats just a ad astra thing

pastel swan
#

instead of block.above() you can just do block where it sets the found variable

#

pos.above() -> pos

#

i did that in the rtp script just because rtp commands usually do that in my experience

#

for spawning though its fine to leave it as the actual pos

wary swallow
#

hm

#

ok

pastel swan
#

anyways glad we got it working

deep oceanBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue!
This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You should create a new post for unrelated issues.

wary swallow
fossil sparrowBOT
#

Ticket closed!

orchid wren
#

i'm using this tbh but if you place a bed, save respawn and break the bed you spawn in overworld ^^, theres something to make that dont happen?

deep oceanBOT
#

Please avoid re-opening/necroing old solved tickets.
If you're experiencing a similar issue, open a new ticket instead. You can link or reference the old thread if it's relevant. This helps keep support organized and ensures your specific problem gets proper attention.