How to teleport all cobblestone and no other items to me

minecraft-commandsminecraft-java-edition

I am using a plugin that involves chunk mining and all I want is the cobblestone, but none of the research I have found tells me how to do that, or is out of date. I am on version 1.16.5.

How can I teleport only cobblestone and no other items to me?

Best Answer

To teleport all cobblestone to your player, you need to use teleportation. The Official Minecraft Wiki summarization of this game mechanic is excerpted below:

Teleportation is a form of transportation in which the moving object is instantaneously moved to its target location.

This is the best solution your question because it is instant, efficient, and simple. Alternatives would include using water streams or slime block contraptions to move the items. These are complicated and take time to set up. But you already specified in your title that you wanted to use teleportation, so you probably knew all of this already.

You can use teleportation via several methods, such as throwing an ender pearl, eating a chorus fruit, or passing through a Nether portal, End portal, Exit portal or End gateway. For this question, we can use teleportation via commands, as long as you have a high enough permission level and also satisfy the restrictions.

There are many commands, but the one we are concerned about is the /teleport command. It has a complicated and thorough syntax. Of the many usages, you can use the tp command like so:

tp <targets> <location>

Here, we must satisfy 2 arguments. The second argument, <location>, is easy. It accepts an x, y, and z coordinate as the location. To teleport the items to your player's current location, we can use Relative World Coordinates. This allows you to avoid needing to know the exact coordinates of your player. Here is what it would look like:

tp <targets> ~ ~ ~

The first argument, <targets>, is a little more complex. Most simply, the target can be a player-name, like so:

tp ginkgo ~ ~ ~

But to select an item, you need to use a target selector. A target selector consists of 2 main parts: a target selector variable, and an optional target selector argument.

There are 5 target selector variables:

Variable Function
@p nearest player
@r random player
@a all players
@e all entities
@s entity executing the command

...and many many target selector arguments. Since items are an entity, we will be using the @e target selector variable. It's usage would be as follows:

tp @e ~ ~ ~

Beware, this command can cause disaster! Notice how the target selector variable selects all entities—this includes all mobs, paintings, armor stands, minecarts, players, and items!

To filter out only item entities, we can use the type target selector argument. This can be appended to the target selector variable like so:

tp @e[type=item] ~ ~ ~

Finally, to filter out only cobblestone items, we can use another target selector argument to detect the item's nbt data:

tp @e[type=item,nbt={Item:{id:"minecraft:cobblestone"}}] ~ ~ ~