Minecraft Java Edition – Run Command if Player is NOT Matching DataTag

minecraft-commandsminecraft-java-edition

I have a huge problem: I want to set a players HPLUranium score to 9 whenever he wears an anti-radiation suit – easy, I do this like that:

scoreboard players set @p HPLUranium 9 {Inventory:[{Slot:103b,id:minecraft:leather_helmet,tag:{display:{Name:Nuclear Helmet,color:10066328}}},{Slot:102b,id:minecraft:leather_chestplate,tag:{display:{Name:Nuclear Tunic,color:10066328}}},{Slot:101b,id:minecraft:leather_leggings,tag:{display:{Name:Nuclear Pants,color:10066328}}},{Slot:100b,id:minecraft:leather_boots,tag:{display:{Name:Nuclear Boots,color:10066328}}}]}

But the problem is… how do I make him LOSE this 9 whenever it's not true? Like Conditional command block but opposite, command block that only runs when the one behind him say "false".

I tried to make command block repeating setting HPLUranium to 0, and next to it Chain command block with command showed up there, but it was sometimes changing to 0 for… maybe a tick long when it should be 9, it may cause problems.

Any ideas how to run command if player IS NOT MATCHING DataTag?

Best Answer

Have a repeating command block with the following command and keep note of its coordinates:

testfor @p {Inventory:[{Slot:103b,id:minecraft:leather_helmet,tag:{display:{Name:Nuclear Helmet,color:10066328}}},{Slot:102b,id:minecraft:leather_chestplate,tag:{display:{Name:Nuclear Tunic,color:10066328}}},{Slot:101b,id:minecraft:leather_leggings,tag:{display:{Name:Nuclear Pants,color:10066328}}},{Slot:100b,id:minecraft:leather_boots,tag:{display:{Name:Nuclear Boots,color:10066328}}}]}

Then, have another repeating command block with the following command, replacing X, Y, and Z with the coordinates of the first repeating command block:

testforblock X Y Z command_block -1 {SuccessCount:0}

and it will point to a last repeating command block set to Conditional with the following command:

scoreboard players set @p HPLUranium 0

All command blocks should be set to Always Active.

When the first command block fails, the second command succeeds because the SuccessCount is 0. This causes the third command block to activate, because conditional command blocks activate when a command block pointing into them succeeds.

When the player is wearing the anti-radiation suit, the second command block will fail because SuccessCount will not be 0, and the player's HPLUranium score will not change.