Minecraft:Commands/testfor: Difference between revisions
More actions
imported>LauraFii →History: split |
Fix template calls: add MC/ prefix |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{MC/Exclusive|bedrock}} | ||
{{outdated|edition=java}} | {{outdated|edition=java}} | ||
{{Infobox command | {{Infobox command | ||
| Line 9: | Line 9: | ||
}} | }} | ||
Counts | Counts entities (players, mobs, items, etc.) matching specified conditions. | ||
==Syntax== | ==Syntax== | ||
| Line 17: | Line 17: | ||
==Arguments== | ==Arguments== | ||
{{ | {{MC/Argument|be=1|victim: target|CommandSelector<Actor>}} | ||
: Specifies the entities to test. | : Specifies the entities to test. | ||
: {{ | : {{MC/Arg desc|be=actor}} | ||
==Result== | ==Result== | ||
| Line 31: | Line 31: | ||
== Output == | == Output == | ||
{{Output table|onlybe=1}} | {{MC/Output table|onlybe=1}} | ||
{{Output table|On fail|0}} | {{MC/Output table|On fail|0}} | ||
{{Output table|On success|the number of the specified entities.}} | {{MC/Output table|On success|the number of the specified entities.}} | ||
{{Output table}} | {{MC/Output table}} | ||
==Examples== | ==Examples== | ||
| Line 48: | Line 48: | ||
=== ''Java Edition'' === | === ''Java Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|java}} | |{{MC/HistoryLine|java}} | ||
|{{HistoryLine||1.5|dev=13w03a|Added {{ | |{{HistoryLine||1.5|dev=13w03a|Added {{MC/Cmd|testfor|link=none}}.}} | ||
|{{HistoryLine||1.8|dev=14w02a|Added {{ | |{{HistoryLine||1.8|dev=14w02a|Added {{MC/Cd|dataTag}} argument to {{MC/Cmd|testfor|link=none}}. | ||
|{{ | |{{MC/Cmd|testfor|link=none}} is no longer exclusive to command blocks.}} | ||
|{{HistoryLine|||dev=14w07a|{{ | |{{HistoryLine|||dev=14w07a|{{MC/Cmd|testfor|link=none}} can now test for partial NBT tag matches.}} | ||
|{{HistoryLine||1.13|dev=17w45a|Removed {{ | |{{HistoryLine||1.13|dev=17w45a|Removed {{MC/Cmd|testfor|link=none}}.}} | ||
}} | }} | ||
=== ''Bedrock Edition'' === | === ''Bedrock Edition'' === | ||
{{HistoryTable | {{HistoryTable | ||
|{{HistoryLine|pocket}} | |{{MC/HistoryLine|pocket}} | ||
|{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{ | |{{HistoryLine||1.0.5|dev=alpha 1.0.5.0|Added {{MC/Cmd|testfor|link=none}}.}} | ||
}} | }} | ||
| Line 67: | Line 67: | ||
== Navigation == | == Navigation == | ||
{{Navbox commands}} | {{MC/Navbox commands}} | ||
de:Befehl/testfor | |||
es:Comandos/testfor | |||
ja:コマンド/testfor | |||
pt:Comandos/testfor | |||
ru:Команды консоли/testfor | |||
zh:命令/testfor | |||
Latest revision as of 20:14, 9 April 2026
Script error: No such module "Exclusive". Template:Outdated Template:Infobox command
Counts entities (players, mobs, items, etc.) matching specified conditions.
Syntax
testfor <victim: target>
Arguments
victim: target: CommandSelector<Actor>
- Specifies the entities to test.
- {{#vardefine:onlyje|Template:IN,}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|inapplicability}}Template:Error{{#vardefine:onlyje|}}{{#vardefine:onlybe|}}{{#vardefine:je-arg|}}{{#vardefine:be-arg|}}
Result
Template:Result table Template:Result table Template:Result table Template:Result table Template:Result table
Output
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On fail}}{{#vardefine:output1-{{#var:output-table-lines}}|0}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}} {{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:situation-{{#var:output-table-lines}}|On success}}{{#vardefine:output1-{{#var:output-table-lines}}|the number of the specified entities.}}{{#vardefine:output2-{{#var:output-table-lines}}|N/A}}{{#vardefine:output3-{{#var:output-table-lines}}|N/A}}{{#vardefine:command-row-{{#var:commands-num}}|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-edition-row-{{#var:output-editions-num}}|Expression error: Unrecognized punctuation character "{".}}
{{#vardefine:output-table-lines|Expression error: Unrecognized punctuation character "{".}}{{#vardefine:output-table-lines|-2}}{{#vardefine:output-table-lines-now|}}{{#vardefine:command-num-now|}}{{#vardefine:command-line-now|}}{{#vardefine:commands-num|}}{{#vardefine:output-edition-num-now|}}{{#vardefine:output-edition-line-now|}}{{#vardefine:output-editions-num|}}{{#vardefine:je-outputs-dis|}}
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
Bedrock Edition
External links
de:Befehl/testfor es:Comandos/testfor ja:コマンド/testfor pt:Comandos/testfor ru:Команды консоли/testfor zh:命令/testfor