Minecraft-Java-Edition-Minecraft-Commands – How to Detect the Dimension Where a Player Is in Minecraft

minecraft-commandsminecraft-java-edition

I want to check a player's current dimension using a scoreboard. For example, if a player is in the overworld, scoreboard would be set to 1. Nether would be 2. And the End would be 3.

I have tried execute if entity @a in minecraft:the_nether but that actually changes the coordinate's dimension.

Do you know any way to detect a player's current dimension?

Best Answer

It's saved in NBT. Quote from the Minecraft wiki (archive):

Dimension: The dimension the player is in. -1 is the Nether, 0 is the Overworld, 1 is the End.


Alternatively, you could still use /execute in, but also check for a radius of 0 or more (which sounds useless, but can be used as a dimension check):

/execute in the_nether if entity @a[distance=0..] run …

This executes if there is a player in the Nether.


There is also an advancement trigger called "changed_dimension" (archive) that can be used to detect a change to a specified dimension and trigger something at that moment. Alternatively you could use the dimension field in the location trigger (archive).