Execute at a certain amount of entities in 1.9

Execute at a certain amount of entities in 1.9 - Crop dealer touching screen on smartphone with trading application

So basically what i am doing is executing at an entity but i want to execute at exactly two of the entities (if there are two entities it will execute the next command, and if there any other amount it won't)

The entity is a an empty bottle and it has a score of isB

This is the command

/execute @e[name=Marker2] ~ ~ ~ /execute @e[c=3,score_isB_min=1,score_isB=1] ~ ~ ~ /execute @e[score_isP_min=1] ~ ~ ~ /say hi

Unfotunately the command will execute with any amount of bottles



Best Answer

The c parameter is only maximum count and there in no minimum variant.

You will have to use multiple command blocks to count the number of targets and run commands if that number is reached. Since you're looking for an exact number, no more or less, you can rely on the SuccessCount tag of the command block.

Repeating>chain>conditional chain

  1. Get the number of required entities as the SuccessCount value. Since you want only 2, the number of times the command will be processed has been limited to 3 to reduce server lag. This way the SuccessCount value will either be 0-1 for 0-1 entities, 2 for the desired amount, or 3 for 3+ entities.

    /testfor @e[score_isB_min=1,score_isB=1,c=3]
    
  2. Check the SuccessCount value of the repeating command block. Change the coordinates as needed. If the value is 2, this /testforblock command will be successful.

    /testforblock ~1 ~ ~ minecraft:repeating_command_block -1 {SuccessCount:2}
    
  3. Conditional. If the /testforblock command was successful, this would be the command to run as a result, which would be your /execute command.

    /execute @e[name=Marker2] ~ ~ ~ /execute @e[score_isB_min=1,score_isB=1] ~ ~ ~ /execute @e[score_isP_min=1] ~ ~ ~ /say hi
    



Pictures about "Execute at a certain amount of entities in 1.9"

Execute at a certain amount of entities in 1.9 - Gold Round Coins on White Surface
Execute at a certain amount of entities in 1.9 - From above of crop anonymous economist calculating total amount of income using calculator app on cellphone near piles of greenbacks and notebook with pen
Execute at a certain amount of entities in 1.9 - Brown Cardboard Boxes on Brown Wooden Floor



How do you execute all entities in Minecraft?

The game processes these subcommands in order from front to end, for example, the following commands are different:
  • All entities move one block forward: execute as @e at @s run tp ^ ^ ^1.
  • All entities are teleported to one block in front of the executor: execute at @s as @e run tp ^ ^ ^1.


  • How many entities can be in a block?

    All living creatures in Minecraft are called entities, and there is a limit to how many of them can stay together in one place. This is a game rule called entity cramming that by default does not allow more than 24 mobs to stand on the same block.



    Counting Entities/Players in Minecraft 1.9-1.12




    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Liza Summer, Olya Kobruseva, Karolina Grabowska, cottonbro