#set world spawn in another dimension
91 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
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
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
Hm
Thanks
I’ll try it
hm
it works
but i spawn underground
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
the problem is
ad astras moon surface it at 105/110
not at 60
cuz thats where i spawned
Tbh i never had that problem haha
this is simple with stages, here it only adds it once upon first world spawn js PlayerEvents.loggedIn(event => { let player = event.player; if (player.stages.has("first_login")) return let moon = World.get("ad_astra:moon"); player.setSpawn(moon.getSpawnPos(), true); player.teleport(moon.getSpawnPos()); player.stages.add("first_login"); });
hm
doesnt seem to work
i mean i put it into server scripts
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.
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"); })
Paste version of server.log from @wary swallow
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);
uhm
i spawn in the void now
not sure if its the moon or not
but if i die im in the over world
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
ah yes, it is the similar issue to this #1367644810953101484 message
[➤](#1367644810953101484 message) the issue with that is it will default to world lower limit (usually -63) because at the time of the check the chunk will not be loaded yet
you'll have to iterate over the blocks until you find a block that sees the sky
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)
}
})
Paste version of server.log from @wary swallow
PlayerEvents is not defined?
lol all g
if i looked right
there isnt one
but you do respawn in the air
but maybe thats just a ad astra thing
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
anyways glad we got it working
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.
thanks again
Ticket closed!
Ticket closed!
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?
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.