Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Minecraft:Commands/testfor: Difference between revisions

From SAS Gaming Wiki
SyncBot (talk | contribs)
Fix template calls: add MC/ prefix
SyncBot (talk | contribs)
Sync: updated from Minecraft
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{MC/Exclusive|bedrock}}
{{exclusive|bedrock}}
{{outdated|edition=java}}  
{{outdated|edition=java|This command was merged with the {{cmd|execute}} command in [[Minecraft:Java Edition 17w45a]].}}  
{{Infobox command
{{Infobox command
|name=testfor
|name=testfor
Line 9: Line 9:
}}
}}


Counts entities (players, mobs, items, etc.) matching specified conditions.
Counts [[Minecraft:entities]] ([[Minecraft:players]], [[Minecraft:mobs]], [[Minecraft:items]], etc.) matching specified conditions.


==Syntax==
==Syntax==
Line 17: Line 17:
==Arguments==
==Arguments==


{{MC/Argument|be=1|victim: target|CommandSelector<Actor>}}
{{argument|be=1|victim: target|CommandSelector<Actor>}}
: Specifies the entities to test.
: Specifies the entities to test.
: {{MC/Arg desc|be=actor}}
: {{arg desc|be=actor}}


==Result==
==Result==
Line 31: Line 31:
== Output ==
== Output ==


{{MC/Output table|onlybe=1}}
{{Output table|onlybe=1}}
{{MC/Output table|On fail|0}}
{{Output table|On fail|0}}
{{MC/Output table|On success|the number of the specified entities.}}
{{Output table|On success|the number of the specified entities.}}
{{MC/Output table}}
{{Output table}}


==Examples==
==Examples==
Line 48: Line 48:
=== ''Java Edition'' ===
=== ''Java Edition'' ===
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine|java}}
|{{HistoryLine|java}}
|{{HistoryLine||1.5|dev=13w03a|Added {{MC/Cmd|testfor|link=none}}.}}
|{{HistoryLine||1.5|dev=13w03a|Added {{cmd|testfor|link=none}}.}}
|{{HistoryLine||1.8|dev=14w02a|Added {{MC/Cd|dataTag}} argument to {{MC/Cmd|testfor|link=none}}.
|{{HistoryLine||1.8|dev=14w02a|Added {{cd|dataTag}} argument to {{cmd|testfor|link=none}}.
|{{MC/Cmd|testfor|link=none}} is no longer exclusive to command blocks.}}
|{{cmd|testfor|link=none}} is no longer exclusive to command blocks.}}
|{{HistoryLine|||dev=14w07a|{{MC/Cmd|testfor|link=none}} can now test for partial NBT tag matches.}}
|{{HistoryLine|||dev=14w07a|{{cmd|testfor|link=none}} can now test for partial NBT tag matches.}}
|{{HistoryLine||1.13|dev=17w45a|Removed {{MC/Cmd|testfor|link=none}}.}}
|{{HistoryLine||1.13|dev=17w45a|Removed {{cmd|testfor|link=none}}.}}
}}
}}


=== ''Bedrock Edition'' ===
=== ''Bedrock Edition'' ===
{{HistoryTable
{{HistoryTable
|{{MC/HistoryLine|pocket}}
|{{HistoryLine|pocket}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{MC/Cmd|testfor|link=none}}.}}
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{cmd|testfor|link=none}}.}}
}}
}}


Line 67: Line 67:


== Navigation ==
== Navigation ==
{{MC/Navbox commands}}
{{Navbox commands}}


de:Befehl/testfor
[[Minecraft:de:Befehl/testfor]]
es:Comandos/testfor
[[Minecraft:es:Comandos/testfor]]
ja:コマンド/testfor
[[Minecraft:ja:コマンド/testfor]]
pt:Comandos/testfor
[[Minecraft:pt:Comandos/testfor]]
ru:Команды консоли/testfor
[[Minecraft:ru:Команды консоли/testfor]]
zh:命令/testfor
[[Minecraft:zh:命令/testfor]]

Latest revision as of 11:05, 12 October 2026

Template:Exclusive Template:Outdated Template:Infobox command

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

Syntax

testfor <victim: target>

Arguments

Template:Argument

Specifies the entities to test.
Template:Arg desc

Result

Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table

Output

Template:Output table Template:Output table Template:Output table Template:Output table

Examples

  • 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

Java Edition

Template:HistoryTable

Bedrock Edition

Template:HistoryTable

External links

Navigation

Template:Navbox commands

Minecraft:de:Befehl/testfor Minecraft:es:Comandos/testfor Minecraft:ja:コマンド/testfor Minecraft:pt:Comandos/testfor Minecraft:ru:Команды консоли/testfor Minecraft:zh:命令/testfor