Skip to content

Instantly share code, notes, and snippets.

@Dinnerbone
Created September 17, 2012 09:49
Show Gist options
  • Save Dinnerbone/3736487 to your computer and use it in GitHub Desktop.
Save Dinnerbone/3736487 to your computer and use it in GitHub Desktop.
New Minecraft target selector syntax!

Syntax

All target selectors start with @. The following character is the selector type. For example, @p means 'closest player'.

Target selectors may have additional, optional arguments. You can specify these in [ ], using the syntax a=0. For example, @p[a=0,b=5,c=-500].

There is a special short syntax for just specifying x, y, z and r arguments; simply list their values separated by a comma, without x=. For example: @p[100,64,-100,5] for 5 range, x=100, y=64 and z=-100. Each of these are optional and skippable by leaving them empty. For example, to just specify y coordinate: @p[,64].

Global Arguments:

  • x - X coordinate for search center. Default is senders coordinate, or 0.
  • y - Y coordinate for search center. Default is senders coordinate, or 0.
  • z - Z coordinate for search center. Default is senders coordinate, or 0.
  • r - Range, number above 0. Default 0 ("No range limit")
  • m - Game mode, number above 0. Default -1 ("No mode limit")
  • c - Max count of results. Default 0 ("No count limit"). Numbers below 0 will make it return the last x amount of entries.

Selectors:

  • p - Closest player.
  • a - A list of all players.
  • r - A random player.

All selectors are lists, but only p has a default count limit of 0 (unlimited). When using lists in a string context (for example, /say Hello @a) it will list all players as strings. When used as a command argument, it will iterate the command for each player in the list.

Examples

@p[r=5]

Closest person within 5 blocks. If there's nobody within 5 blocks, the command will fail.

@a[x=100,y=64,z=-100,c=10,r=5]

Closest 10 players within 5 blocks of 100,64,-100.

@p[0,64,0,c=-2]

The furthest 2 players from 0,64,0.

@a[,,,10,c=5]

The closest 5 players within 10 blocks of your current position.

@ezfe
Copy link

ezfe commented Sep 17, 2012

Fail. They are not. My brain just failed me.

@Similacrest
Copy link

My thoughts about this:

  1. Maybe, we need also modifier that shows if player is OP or not? o=1 - for ops, o=0 - for non-ops.
  2. Some kind of if clause, something like @if[clause, then_command, else_command]:
    @if[@p[,,,r=10,m=1], /difficulty peaceful, /say "You dont have permissions"] - if there are no creative players in range of 10, it won't change difficulty.
  3. What about multiple commands in one block?
  4. And, maybe some logical operators? &, |, ! at least...
  5. Oh, no, after operators it will be variables, cycles, redstone interaction, multithreading... It's easier to implement ComputerCraft.
  6. Just one crazy idea - interacting with command block through the chat...
  7. I will stop, ok, but right after addition of manipulating the redstone output of the block.

At least, ideas 1-3 are not that imbossible.

@Similacrest
Copy link

And yes, this allows vanilla WorldGuard!
Just make something like:

/gamemode @A[, <radius of protection+1>, m=2] 0
/gamemode @A[, , m=0] 2
/gamemode 0
And connect it to a redstone clock.

Just need something like /gamerule tnt_explosion and /gamerule allow_adventure_players_open_inventories (like chests, furnaces, etc)

@Similacrest
Copy link

/gamemode @A[[coords of home],[range of protection+1], m=2] 0
/gamemode @A[[coords of home],[range of protection], m=0] 2
/gamemode [owner] 0

Fixed that.

@AdeonWriter
Copy link

One thing that would help making teleporters (Because I'm a lazy bum!) is an @ shortcut that is the same as typing the coordinate of the command block. (to make range-searching easier) that way the only coordinate you need to type is the destination.

@AdeonWriter
Copy link

Nevermind, just realized that's what they default to.

Copy link

ghost commented Sep 17, 2012

Can you make it so we can use relative coordinates for tp command? For example to teleport everyone 10 blocks up. Or maybe teleport everyone 10 blocks above the sender.

@odensc
Copy link

odensc commented Sep 20, 2012

@iaconic
Copy link

iaconic commented Sep 21, 2012

An option for relative coordinates would be awesome, maybe use a capital X/Y/Z to get the coords.
ex. @p[,Y+10,] would get closest player to 10 blocks above command block

@kentfredric
Copy link

@ShareDVI I strongly suggest that multiple commands in the command block is a bad idea.

It'd be wiser in my opinion to be able to have a default server command that executes a predefined script that has been uploaded to the server somehow, which has access to all the @* data in the script.

Mostly, because scripts will get unweildy and complicated, and if your only interface to edit these scripts is Minecraft, well, I can see "oops, dialog closed and I lost all my chages" being a real nightmare, let alone the question "how do I version this code in git?".

Perhaps it would also be nice to have a standard feature in the client side that allows users to select a file on their local machine, and upload it over the minecraft protocol, and store it on the server, in order to associate that script with the command block.

Additionally, it may be nice to be able to grant people some kind of "read only" access to various command blocks so they can see what code it runs.

@Luka4ever
Copy link

i would suggest you add a @e selector that selects all entities, this could allow teleporting items and mobs

@DaanV2
Copy link

DaanV2 commented Sep 21, 2012

@Dinnerbone, he this might be more of a gimmick but would you allow Command blocks to add Velocity to Players? so that you can launch them, or boost them further along?

@Floedekage
Copy link

We need a rotation variable for the /tp command.

@Webmetz
Copy link

Webmetz commented Sep 21, 2012

I think it would be nice if command blocks could target mobs as well, or rather, target specific targets.
A way to do that is through an optional variable t.

t - Valid targets. Defaults to Player. Other EntityIDs can be specified, and multiple can be specified if separated with |. You can also use player names as input by specifying them in quotation marks.

Here is an example which would target the closest creature
@p[t=Bat|Blaze|CaveSpider|Chicken|Cow|Creeper|EnderDragon|Enderman|Ghast|Giant|LavaSlime|MushroomCow|Ozelot|Pig|PigZombie|Player|Sheep|Silverfish|Skeleton|Slime|SnowMan|Spider|Squid|Villager|VillagerGolem|Witch|WitherBoss|Wolf|Zombie]

Here is an example which would target all hostile non-boss mobs
@A[t=Blaze|CaveSpider|Creeper|Enderman|Ghast|Giant|LavaSlime|PigZombie|Silverfish|Skeleton|Slime|Spider|VillagerGolem|Witch|Zombie]

Here is one that selects randomly between Tom, Dick, and Harry.
@r[t="Tom"|"Dick"|"Harry"]

@king92197
Copy link

Any idea as to why I can't /tp everybody to certain Coordinates? I'm using the command "/tp @A[180,84,23,64]". It should /tp everybody in a 64 Block Radius to those coordinates, but it won't work for some reason. Anybody know why? I think it has to do with teleporting everybody at once, but I'm not sure.

@WolfieMario
Copy link

Say, where did @f go?

Also, I agree with others here that a relative teleportation feature would be a great addition. I've actually come up with many situations where relative teleportation would be handy. I'd just paste those here, but it's rather long, so I'll link to my suggestion thread instead. I hope there's no problem with that; I'd rather not thread-whore, but the list itself is just excessively long. It's in the spoiler at the end of the op (I don't know how to use spoilers on github, else I would):

http://www.minecraftforum.net/topic/1494864-new-command-move-aka-relative-teleportation/

@acidnine
Copy link

acidnine commented Oct 3, 2012

12w39b additions:
( download: http://assets.minecraft.net/12w39b/minecraft.jar )

l=level
lm=minimum level
rm=minimum radius

Set player level with "xp 10L @p" then remove with "xp -100L @p"...

Source: Sethbling via http://www.youtube.com/watch?v=1X3d6egPEus

@wenjinghuan999
Copy link

It would be nice if I can know whether a command is successfully executed, for example output a redstone signal on the opposite side

@Webmetz
Copy link

Webmetz commented Oct 28, 2012

Posted the original version these on http://www.minecraftforum.net/topic/1487156-new-command-block-commands-list/page__gopid__18816142#entry18816142

Would be nice to have the ability to target mobs.
Creatures (Passive, Hostile, Player):
@nc Nearest
@ac All
@rc Random
@fc Farthest
Passive (Animals, Villagers, etc)
@np Nearest
@ap All
@rp Random
@fp Farthest
Hostile (Skeletons, Zombies, Etc)
@nh Nearest
@ah All
@rh Random
@fh Farthest
EntityNames (Specify an Entity name, or comma delimited list of entity names. Eg. 'Cow,Sheep,Chicken')
@n'EntityNames' Nearest
@A'EntityNames' All
@r'EntityNames' Random
@f'EntityNames' Farthest

/equip (target) (item | north | south | west | east | up | down)
If the item is equipment, it attempts to equip it on the target in its logical spot, causing whatever is equipped in that slot to go into inventory if it has one and dropped if it doesn't or doesn't have a free spot.
Extra Info: If a direction is chosen, it will choose the first valid item from adjacent container on that side and apply it to the target without consuming it.

/apply (target) (item | north | south | west | east | up | down)
If the item is a consumable item (food, potion, not thrown item), it applies the effects of it instantly to the targets.
Extra Info: If a direction is chosen, it will choose the first valid item from adjacent container on that side and apply it to the target without consuming it.

/give (target) (item | north | south | west | east | up | down)
Gives an item to the target. If the target is a NPC, it will attempt to put it in its hand
Extra Info: If a direction is chosen, it will choose the first valid item from adjacent container on that side and apply it to the target without consuming it.

/spawner state (on | 1 | off | 0 | toggle) (north | south | west | east | up | down)
Will set the state of a spawner, preventing it from acting normally. If a direction is not specified, targets all adjacent spawners (if command block), or the targeted spawner (if player).

/spawner set (entityID) (north | south | west | east | up | down)
Overwrites the entity of a spawner. If a direction is not specified, targets all adjacent spawners (if command block), or the targeted spawner (if player).

/spawner trigger (north | south | west | east | up | down)
Triggers a spawner to prematurely spawn. If a direction is not specified, targets all adjacent spawners (if command block), or the targeted spawner (if player).

Someone else posted the original version these on http://www.minecraftforum.net/topic/1487156-new-command-block-commands-list/#entry18116528 I modified them slightly.

/spawn (entityID) (x) (y) (z) (number to spawn)
Spawns an entity. Spawns 1 if a number is not specified.

/block place (block ID) (x) (y) (z)
Places a block at the specified coordinates with a block matching the block ID.

/block set (block ID) (x) (y) (z)
Replaces a block at the specified coordinates with a block matching the block ID. Can be used to remove a block by setting 0 as the block ID.

Note on above, would be nice to be able to do a set of coordinates. Perhaps using {[x,y,z],[x,y,z]} format in order to target multiple locations.

@Durandle
Copy link

you guys do know that the move command is redundant /move 10 2 10 is the same as /tp ~10 ~2 ~10 since 1.4.4 or earlier

@Durandle
Copy link

@king92197
the problem probably is that you haven't specified a location to send everyone to the command "/tp @A[180,84,23,64]" translates to "teleport everyone in radius of 64 blocks from location 180,84,23 to ..." see the problem?

@ZeroErrors
Copy link

I found something that would be useful,
If you were to have wildcard's for the coordinates for example @A[,0,,2] this will get all the players with a y value of 2 or less.
You could use something like '/tp @A[,0,,2] 0 65 0' and teleport everyone that is at y=2 or less so they don't fall into the void.

@tschoffelen
Copy link

"number above 0. Default 0". Shouldn't that be 'number 0 or higher' or something like that?

@MTandi
Copy link

MTandi commented Feb 18, 2013

An implementation of selected player variables can add a lots of new possibilities and minimize amount of command blocks needed for some commands.

For example we can use one command block in re-spawn area to send players in different places depending on class.
/tp @r[0,0,0,5] 10 10 Class*10
Where "Class" is score from scoreboard (or their Level). It acts like "~" in tp command. Players with class 1 will be teleported at z=10, with class 2 at z=20 etc.

It will be also possible to arrange players on pedestal in order of their kills or experience at the end of the match.

If we need 3 players to stay in correct order depending on their role, we can use:
/testfor @A[0,0,Role*10,5].
And it will output signal strength of 3 if all players stay in their places.

And lots more.

@Sidneys1
Copy link

Updated fork here (as of MC 1.8). No pull request feature on Gist, Dinnerbone needs to update this.

@SkadetteTayne
Copy link

how do you make a command block only say something once when the person gets within your specified range of the command block?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment