VOOZH about

URL: https://minecraft.wiki/w/Commands/testfor

⇱ /testfor – Minecraft Wiki


/testfor

From Minecraft Wiki
Jump to navigation Jump to search
This feature is exclusive to Bedrock Edition.
 
This page describes content that has been removed from Java Edition.
 
This feature was present in earlier versions of Java Edition, but has since been removed.
/testfor
Permission level
required
  • 2 ‌[JE only]
  • 1 ‌[BE only]
Restrictions Cheat only
{
 "title": "<code>/testfor</code>",
 "rows": [
 {
 "field": "\n* 2 ‌<sup class=\" nowrap Inline-Template \" title=\"\">[<i><span title=\"This statement only applies to Java Edition\">(link to Java Edition article, displayed as JE) only</span></i>]</sup>\n* 1 ‌<sup class=\" nowrap Inline-Template \" title=\"\">[<i><span title=\"This statement only applies to Bedrock Edition\">(link to Bedrock Edition article, displayed as BE) only</span></i>]</sup>",
 "label": "(link to Permission level article, displayed as Permission level<br>required)"
 },
 {
 "field": "(link to Cheat article, displayed as Cheat) only<br>",
 "label": "(link to Commands#Restrictions article, displayed as Restrictions)"
 }
 ],
 "invimages": [],
 "images": []
}

Counts entities (players, mobs, items, etc.) matching specified conditions.

Syntax

[edit | edit source]
testfor <victim: target>

Arguments

[edit | edit source]

victim: target: CommandSelector<Actor>

Specifies the entities to test.
Must be a player name or a target selector.

Result

[edit | edit source]
CommandTriggerBedrock Edition
AnyThe command is incomplete, or any argument is not specified correctly. Unparseable
victim: target fails to resolve to one or more entities (named players must be online). Failed
OtherwiseSuccessful

Output

[edit | edit source]
CommandEditionSituationSuccess Count
AnyBedrock EditionOn fail0
On successthe number of the specified entities.

Examples

[edit | edit source]
  • To test if Alice is online: testfor Alice
  • To count the number of players in Survival mode within a 3-block radius of (0,64,0): testfor @a[x=0,y=64,z=0,r=3,m=0]
  • To count the number of zombies within a 20-block radius of (0,64,0): testfor @e[x=0,y=64,z=0,r=20,type=zombie]
  • To check if a random player has iron ingots in their inventory testfor @r[hasitem={item=iron_ingot}]
  • To check if a random player does not have iron ingots in their inventory testfor @r[hasitem={item=iron_ingot},quantity=0]
  • To check if a random is holding iron ingots in their inventory testfor @r[hasitem={item=iron_ingot},location=slots.weapon.mainhand]

History

[edit | edit source]

Java Edition

[edit | edit source]
Java Edition
1.513w03aAdded /testfor.
1.814w02aAdded dataTag argument to /testfor.
/testfor is no longer exclusive to command blocks.
14w07a/testfor can now test for partial NBT tag matches.
1.1317w45aRemoved /testfor.

Bedrock Edition

[edit | edit source]
Pocket Edition
1.0.5alpha 1.0.5.0Added /testfor.

External links

[edit | edit source]

Navigation

[edit | edit source]
Retrieved from "https://minecraft.wiki/w/Commands/testfor?oldid=3249743"

Navigation menu