2

I know that you can use exclamation marks in Minecraft commands to check for an entity that does not have a specific tag. For example, you can use /kill @e[type=!Player] to kill all entities except for the player. I have, however, encountered two problems with using exclamation marks that I can't find a solution for.

For my first problem, I've set up a series of command blocks to summon shootable fireballs above the player’s head when a certain item is being held;

/scoreboard players add @a Fireball 1 {SelectedItem:{tag:{display:{Name:"Summon Fireball"}}}}
/execute @a[score_Fireball_min=1,score_Fireball=1] ~ ~ ~ /summon Fireball ~ ~2.5 ~ {direction:[0.0,0.0,0.0]}
/scoreboard players set @a Fireball 0

I used a comparator and a redstone torch so that the last command would activate when the first command would deactivate, that is, when the player is not holding the item. The problem is, that when I move far away from the setup, the redstone stops working, leaving me unable to summon any new fireballs. Instead, I'm trying to use a command block to check when anything except for item is being held;

/scoreboard players set @a Fireball 0 {SelectedItem:{tag:{display:{Name:!"Summon Fireball"}}}}

I’ve either put it at the wrong place, or you simply can’t use exclamation marks in NBT tags. Could someone tell me where I should put the exclamation mark, or in the latter case, how I can check for anything except for a specific item?

Further, I’ve tried using exclamation marks to set the score of all entities, including the ones with a blank score, but except for the ones with a score of 2 or higher, to 0;

/scoreboard players set @e[score_arrows_min!=2] Arrows 0
/scoreboard players set @a Arrows 1 {SelectedItem:{tag:{display:{Name:"Rain of Arrows"}}}}
/scoreboard players set @e[type=Arrow] Arrows 2 {inGround:1b}

The code does change the scores of entities without scores to 0, but it doesn’t exclude the arrows with a score of 2. Could anyone tell me what I’m doing wrong here?

  • Just an FYI, an exclamation is commonly used as the NOT operator in programming and mathematics. See here. Just a fun fact. :) – Vemonus Oct 20 '16 at 18:54
  • I know. I'm also trying to develop an app for a school project. I came across it there. – Jaïr Paalman Oct 20 '16 at 18:55
1

or you simply can’t use exclamation marks in NBT tags

This is the case unfortunately. Using ! for negation only works in selectors, and even then only for certain arguments (type, name, tag, team, m).


The problem is, that when I move far away from the setup, the redstone stops working, leaving me unable to summon any new fireballs. Instead, I'm trying to use a command block to check when anything except for item is being held;

If I'm understanding correctly, this problem won't be solved by changing your commands if they already do the correct thing when you're near them.

You should instead move your contraption to spawn chunks (which are always loaded) or keep the chunks your contraption is in loaded with a chunk loader.


how I can check for anything except for a specific item?

Your original commands will leave players not holding the item with a score of 0, meaning you can do something like:

/scoreboard players add @a Fireball 1 {SelectedItem:{tag:{display:{Name:"Summon Fireball"}}}}
/execute @a[score_Fireball_min=1,score_Fireball=1] ~ ~ ~ /summon Fireball ~ ~2.5 ~ {direction:[0.0,0.0,0.0]}
/execute @a[score_Fireball_min=0,score_Fireball=0] ~ ~ ~ /say I'm not holding the fireball summon item
/scoreboard players set @a Fireball 0

You can rearrange these commands slightly to have players be left with 0 or 1 at the end of the tick depending on whether they're holding the fireball, if you want:

/scoreboard players set @a Fireball 0
/scoreboard players add @a Fireball 1 {SelectedItem:{tag:{display:{Name:"Summon Fireball"}}}}
/execute @a[score_Fireball_min=1,score_Fireball=1] ~ ~ ~ /summon Fireball ~ ~2.5 ~ {direction:[0.0,0.0,0.0]}
/execute @a[score_Fireball_min=0,score_Fireball=0] ~ ~ ~ /say I'm not holding the fireball summon item

Further, I’ve tried using exclamation marks to set the score of all entities, including the ones with a blank score, but except for the ones with a score of 2 or higher, to 0;

The score_... argument also unfortunately doesn't accept ! for negation. You'll instead need to do this in multiple steps:

  1. Add 0 to all scores, turning null scores to 0: /scoreboard players add @e[type=Arrow] Arrows 0
  2. Do the command for arrows with Arrows score less than 2: @e[score_Arrows=1]
  3. Do the command for arrows with Arrows score more than 2: @e[score_Arrows_min=3]
  • Thank you for your quick response. I'd like to add, though, that the Fireball score was meant to be a counter. It would only spawn a fireball once. You'd have to let go of the item first, before you could summon another one. This is to prevent multiple Fireballs from hitting each other. Could you help me find a way to only set the counter back to 0 when the player lets go of the item? – Jaïr Paalman Oct 20 '16 at 20:51
  • Try /scoreboard players tag @a remove HoldingFireball -> /scoreboard players tag @a add HoldingFireball {SelectedItem:{tag:{display:{Name:"Summon Fireball"}}}} -> /scoreboard players set @a[tag=!HoldingFireball] Fireball 0 -> /scoreboard players add @a[tag=HoldingFireball] Fireball 1. This uses a HoldingFireball scoreboard tag to track whether a player is holding a fireball or not, and then your Fireball score should work as expected. – SirBenet Oct 20 '16 at 22:35
  • I already did that, but I didn't want to use two extra command blocks. I'm using multiple summons like this on a low end PC, so I try to keep everything as small as possible. – Jaïr Paalman Oct 21 '16 at 9:33
1

Minecraft 1.13 merged NBT tags into the selector syntax, making this easy:

/scoreboard players set @a[nbt=!{SelectedItem:{tag:{display:{Name:"\"Summon Fireball\""}}}}] Fireball 0

(1.13 also changed the syntax for item display names, so that they now need to be quoted, hence the \" in the selector.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.