Minecraft – Command Block Teleportation

minecraft-commandsminecraft-java-edition

I would like to make a detector in minecraft that makes it so when a player is in a specific location, that player will be teleported to a certain location.
Is that possible?
If so, may I have an example of the command?
(Only in command block form please)

Best Answer

Yes that is possible! It is actually very easy...

Command Set Up

If you want to get a player from a area you need a target selector. For your example the @a fits the best. If you have a target selector you are able to use target selector arguments. And with them you are able to define the area.

There are some more possibilities than the one I show you. I recommend you to select the players by volume. That means you have two points and all players within these points are selected.

[dx=DX,dy=DY,dz=DZ]

Selects only targets within the volume defined as starting from the location where the command was executed and extending DX blocks in the positive "x" direction (i.e., east), DY blocks in the positive "y" direction (i.e., upwards), and DZ blocks in the positive "z" direction (i.e., south). All values must be positive.

Usage of selection by volume from the minecraft gamepedia.

The command I use looks like this:

/tp @a[dx=10,dy=10,dz=10] -1718 63 -127

Here is the explaination of the command if you do not know how to use it!

Coords

The syntax of a tp command looks like this:

/tp [target player] <x> <y> <z>

The target player in your example are all players in the area. So you have to use the @a what selects all players.

Furthermore you need something that restricts that @a so that only the players in a area are selected. For that you need the selection by volume. It is written right behind the @a.

As I said before you need two points to select a area. The first point (1 in the picture) is the commandblock and you do not need to type it in the command. The secound point (2 in the picture) needs to be in the command.

So you have to type the information how far this point is away from the commandblock. In my example I made a cube wich is 10x10x10 big. So I have to type [dx=10, dy=10, dz=10] and the area gets expanded by ten on each side.

The last three digits are the coordinates where you want to teleport the players. The first is the x, the secound the y and the last the z.

You are able to see the coordinates if you press F3 on your keyboard.

Automatic Teleporting Set Up

I do not know now if you want to teleport the player if he enterd the area or if you press a button. If you want to control it you just have to add a button with redstone to the commandblock.

If you want that a player is teleported when he is entering the area you have to use a redstone clock. Keep in mind that a redstone clock needs some server ressources. So use them as less as possible!

Clock

You are able to turn the teleportation on and off with the levler of the clock.