4

I have a vanilla server 1.8.7 that uses a book to teleport players to spawn or to their "home" (an invisible armor stand that is connected to the player via their UUID). The problem is, if they set their home (place their armor stand) in one dimension (Overworld), and go to another dimension (the Nether) and activate the "teleport home" function using a trigger, it sends them to the same coordinates in that dimension, more often than not resulting in the player's death.

I did some digging, and there seems to be a dimension parameter, but I can't quite figure out the syntax or how to get it to work.

I updated the command block to:

/tp @a[score_tpHome_min=1,Dimension=0] 68 68 68

I was hoping it would only tp the player when they were in the overworld (Dimension 0), but it seems to be ignoring that parameter in the nether and still teleporting to those co-ordinates in the nether.

I also tried:

/tp @a[score_tpHome_min=1,Dimension:0] 68 68 68

which is the way other people were using the parameter in other ways, but that gave an error.

2
  • Have you actually tried this with the armor stands? I'm pretty sure the game can't resolve entities in another dimension, causing the tp to fail automatically.
    – MrLemon
    Commented Jul 7, 2015 at 9:39
  • May I ask how did you set up the score_tpHome? Did you testfor a player with that score and some how associate the teleport? I'm so confuse on setting up these commands. Commented Jan 1, 2017 at 22:28

4 Answers 4

3

This is almost a version of @MrLemon's answer. Run the following command once:

/scoreboard objectives add Dimension dummy

Put the following commands on a fill/fast clock:

/scoreboard players set @a Dimension -2 {Dimension:-2}
/scoreboard players set @a Dimension -1 {Dimension:-1}
/scoreboard players set @a Dimension 0 {Dimension:0}    

Then do the tp as following:

/tp @a[score_tpHome_min=1,score_Dimension_min=0] 68 68 68

How this works is it gets the player dimension by setting the scoreboard objective Dimension to the dimension that they are in.

3

The Dimension parameter does not exist as a target selector argument, but is present in the entity data.

Sadly, /tp does not allow you to check for entity data, so you will have to create a workaround using a scoreboard objective.

/scoreboard objectives add inNether dummy

One the objective exists, create a fill/setblock clock and run the following two commands, in this order:

/scoreboard players set @a inNether 0
/scoreboard players set @a inNether 1 {Dimension:-1}

This will set the objective to 1 for everyone in the Nether and you can use this to limit your tp command to

/tp @a[score_tpHome_min=1,score_inNether=0] 68 68 68

That being said, this would allow the use of the TP in the End, which almost definitely results in death. I suggest turning the logic around by doing

/scoreboard players set @a inOverworld 0
/scoreboard players set @a inOverworld 1 {Dimension:0}

instead, and check for score_inOverworld_min=1.

1

Minecraft 1.13's addition of NBT to the selector argument syntax means the general technique described in the other answers can be done without scoreboards:

/tp @a[score_tpHome_min=1,nbt={Dimension:0}] 68 68 68

That said, /tp can now teleport players across dimensions, so it may be better to do that instead of disabling the teleport ability entirely in the nether.


Additionally, Minecraft 1.16 changed the NBT format so that the Dimension tag is stored as a string, meaning that you have to use:

 /tp @a[score_tpHome_min=1,nbt={Dimension:"minecraft:overworld"}] 68 68 68

instead if you are playing the most recent version.

0

While all the previous answers are valid and work, they all make use of checking a player's NBT tags in one form or another. As Minecraft commands have evolved and more complex functionality has been introduced, the performance impact of the commands that you run has become significant enough that caution must be taken when performing NBT checks. NBT operations are among the most expensive in the game, and it is recommended that they be avoided whenever possible in favour of other methods.

In the newest version of Minecraft Java, targeting players only in a certain dimension can be done without any NBT checks using this command:

execute in minecraft:the_nether run tp @a[x=0,scores={tpHome=1..}] 68 68 68

It is important that x=0 is added, this ensures the @a[…] applies only to players in the current dimension and not all dimensions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .