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!
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!
You are able to turn the teleportation on and off with the levler of the clock.
It's very difficult to see whether someone has an object anywhere in their inventory. That would take 36 command blocks, one for each slot! You can, however, take the object, then see if taking the object worked.
The Commands
- Set up a fast clock (but not as fast as a fill clock)
- One command block does
/clear @p iron_ingot 0 1
(clears 1 iron ingot from the nearest player. You can choose which player, but it must be exactly one. Also, you must use the same selector throughout all these commands.)
- Run a comparator from that command block to another command block running this command:
/scoreboard players add @p ironIngots 1
(Increases the player's ironIngots
score by 1. Make sure you create ironIngots
first!)
- Create another command block that does whatever you want. In the case of giving them a diamond, you would do this:
/give @p[score_ironIngots_min=10] diamond
. Note the target selector; it gives the player the diamond only if their ironIngots score is 10 or greater.
- The last thing you want to do is take the ironIngots score away so they don't keep getting items. Just run
/scoreboard players remove @p[score_ironIngots_min=10] ironIngots 10
. This removes 10 iron ingots from the player if they have an ironIngots
score of 10 or greater. Any player who matches this will have received a diamond in the previous step.
How to Set Them Up
The commands listed above must run in order. It is actually very simple to put them in order. Just open the debug menu and look at the stylish new crosshair. Align the command blocks along either the green or red line so that one of those lines points down the first to the last command block.
Notes
- You don't have to press a button to use this, you just have to be the nearest player. You can change the command to the nearest player within 10 blocks, nearest player on a team, etc.
- The commands will take a short amount of time to finish, but for 10 iron ingots, it will only take half a second. It's one tick (1/20 of a second) per item taken away.
- It will take away iron ingots even if you don't have ten. However, you can submit one, then later submit five, then submit four more later, and it will still give you the diamond. You can also submit 14 at a time and the extra 4 will be saved for later.
Best Answer
So I figured out how to do this. I made a 1 x 1 block structure with just single diamond ore in it. Then, every time the player mined the ore, it built the structure right where the ore is located and then killed all the normal diamonds in that area (if there are some).