I have a Minecraft Earth map and I want it so if you go too far on one side, it will teleport you to the other side: so players can get from Japan to America by going through the Pacific Ocean. I tried the following command, but it didn't work. What should I do?

/execute as @e[x=5375,y=~,z=~,distance=..2] at @s run tp @s ~-10750 ~ ~
  • Did you get an error message? If so, what was it? – ExpertCoder14 Nov 5 at 1:20

Tilde notation with ~ is not available in target selectors, and even if it was supported, it wouldn't work, because the tilde is relative to the command block, not to the players selected.

What I would do is use a rectangular volume to make this work.

... as @e[x=5375,y=64,z=10,dx=0,dy=999,dz=999]

This makes a giant selection box starting at coordinates (5375, 64,10) and extending one block east, 1000 blocks up, and 1000 blocks south (an implicit 1 is added to all 3 delta values).

To determine x, y, and z, go to the lower northwest corner of your selection box. dx, dy, and dz should be the number of blocks east, up, and south to extend the border wall.

| improve this answer | |
  • I did what you said, and got no error message, but when I go through the area, nothing happens, no teleportation takes place – Wera Nov 5 at 3:49
  • @Wera Are you absolutely sure you got the numbers correct? Make sure x, y, and z represent the lower northwest corner of the target box. Also make sure to substitute the correct values in for dx, dy, and dz. – ExpertCoder14 Nov 5 at 3:55
  • actually nvm! Eye made a mistake, eye made dx dy dz the coordinate of the top east south corner, instead of how far to expand the box eye fixed it, thank you so much :> – Wera Nov 7 at 1:41
  • @Wera If this answer solved your problem, please click the gray check mark on this answer to indicate that your problem is now solved – ExpertCoder14 Nov 7 at 1:53

For my method, we will use scoreboards. First you must make a scoreboard with a dummy critera we'll name it xpos. Then you have to put it in a repeating command block or in a ticking function (a function running every tick) the following command.

execute as @a at @s store result score @s xpos run data get entity @s Pos[0]

That will at every tick store the x value of every player in the world to their scoreboard value. This is multiplayer friendly. Next, we test if they have a specific value or a range in the scoreboard with the following command.

execute as @a[scores={xpos=<range/value>}] at @s run tp <cordinates>

Keep in mind, for this to work, both commands I gave you must be in a repeating command block or in a ticking function. In your case replace <range/value> with 5375.. and <cordinates> to -5375 ~ ~. If you have any questions please ask I'll be happy to help.

| improve this answer | |
  • Works for an infinitely long border, but is unnecessary if the border has a finite length. – ExpertCoder14 Nov 5 at 3:37
  • 1
    @ExpertCoder14 but it is better for lag. – randomuser922 Nov 5 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.