2

Found a possible solution for teleporting a player back to the overworld if in the end / nether (1.20.3)

lzenl's Avatar lzenl12/9/23 8:23 am history
2 emeralds 363 4
12/16/2023 1:26 pm
lzenl's Avatar lzenl

for players in the end
execute as @a[​nbt={Dimension: "minecraft:the_end"}] in overworld run tp @s
~ ~ ~

for players in the nether
execute as @a[​nbt={Dimension: "minecraft:the_nether"}] in overworld run tp @s ~ ~ ~


Note: this teleports you back to the world spawn point and NOT to the previous spawn point

(edit)

I didn't test if the nether command works as intended so it may not work
Posted by lzenl's Avatar
lzenl
Level 24 : Expert Strawberry
10

Create an account or sign in to comment.

4

ShelLuser
12/13/2023 9:53 pm
Level 57 : Grandmaster Engineer
history
ShelLuser's Avatar
That won't work if the player isn't an op who doesn't have access to server commands.

Another thing is that there's no need for such complex constructions in the first place because teleporting players across dimensions has already been implemented into vanilla Minecraft quite some time ago.

If my friend Aya is in the nether and I want to get her out all I have to do is: /tp AyanamiKun @p, and I'm done. This also applies to datapacks.

(edit)

I glossed over a detail... what if you don't have a specific destination, then coordinates obviously won't work. Yah, my bad!

But there's still a better solution: /execute in minecraft:overworld run tp AyanamiKun ~ ~ ~. However, this does not tp someone to any kind of spawn, but to their current location (~ ~ ~) yet in the other dimension. And of course, if you don't want to focus on one player but want to get all players out of the nether you'd use: /execute in minecraft:overworld run tp @a[nbt={Dimension:"minecraft:the_nether"}] ~ ~ ~

Hope this can help!
2
lzenl
12/16/2023 9:01 am
Level 24 : Expert Strawberry
history
lzenl's Avatar
Hmm, it did work tho...

I tested multiple variations and this should always teleport you back to spawn since the functions of a data pack are always executed at the World Spawn Point.

Note: this is in the section of Data packs and not a command block execution.

since it's executed as @a and not @a


execute as @a[,nbt={Dimension: "minecraft:the_end"}] in overworld run tp @s ~ ~ ~



and it does work for multiple players.

Yours is still better since it requires fewer tests for the execution :)


execute in minecraft:overworld run tp @a[​nbt={Dimension:"minecraft:the_nether"}] ~ ~ ~


Thanks for the comment tho!



1
HoboMaggot
12/16/2023 10:13 am
Level 52 : Grandmaster Blob
history
HoboMaggot's Avatar
Pretty sure both use the same amount of tests as you're checking out of all possible players if any of them are currently in the nether/end.
Checking for nbt in general can get expensive especially if you're using it many times and on many entities).
Since you're using a datapack, I suggest using an 'entity properties' predicate
2
lzenl
12/16/2023 1:26 pm
Level 24 : Expert Strawberry
lzenl's Avatar
I think it requires fewer tests but the amount of performance you get out of it is negligible.
I am aware that checking NBT isn't very efficient but it's just supposed to be a quick fix.
My skills in creating data packs aren't very developed and I'm not well versed with predictates.

I'll keep this in mind.

Thx for the comment!
1
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome