TransWikia.com

Is there a OR operator in executing commands? (Java 1.14)

Arqade Asked on December 25, 2020

I have been running into roadblocks at the moment with the use of executing if and unless statements, not only that but also in using tags.

for example here I have a command block running through a few tags and I need it to cover 2 tags “crafting_block2” and “crafting_block1”
except it treats it more like a & operator if I use it like below.

/execute as @e[type=minecraft:armor_stand,tag=crafting_block] align xyz positioned ~0.5 ~0 ~0.5 unless entity @e[type=minecraft:villager,tag=crafting_block2,tag=crafting_block1] at @s run kill @s

So it would only execute if the armor stand has both of the tags, but I want it to execute when it has either of the tags.

I know I could apply another tag from the start to cover it all but is there a way to do this without the additional tag (and without the use of scoreboards). if there is a OR operator or something like that, that would be nice.

As well on top of that, I also want to know about a similar thing

execute as @e[type=minecraft:armor_stand,tag=Landmine] at @s align xyz positioned ~0.5 ~ ~0.5 if block ~ ~ ~ air run tp @s ~ ~-1 ~

for example here, I couldn’t quite get it to work on both cave air and normal air. Like as I said above if I tried to put another if statement in it treats it as if there if an AND operator and would only work if both are true (which is impossible in this case). In the end, I had to duplicate the entire command to compensate for this which is ridiculous.

2 Answers

Duplicating commands is a common thing, because there is no "OR" in commands.

In your first case you might be able to do something like "as @e[type=villager] unless entity @s[tag=block1] unless entity @s[tag=block2]" or other fancy tricks, but if that doesn't work in your case, then yes, you might need to use another tag. You can also do very fancy things, like custom predicates (in 1.15), but that's not worth it for such a small example.

Another thing that is also called "tag" (not to be confused with NBT tags, the tags that were formerly a part of the scoreboard command, name tags, the "tag" NBT tag of items or the German word for "day") can help for your second case. If you create a block tag (archive) with the name air and then check for "#air" instead of "air", you can match all blocks in that tag at once. Don't forget the namespace if your datapacks uses a different one than minecraft.

Correct answer by Fabian Röling on December 25, 2020

To check stuff in minecraft using commands, you have to use logic based on "and". When you check for stuff, everything will have to be true for it to return true. A mini class of logic: let p be a tag and q another tag. You want the command to be executed when either of those are true, or both, that's an "or", but minecraft only checks everything with "and". p | q | or v v v v f v f v v f f f

If you invert everything (!) and change it with and, it will look like this !p | !q | and f f f f v f v f f v v v As you can see, it's exactly the opposite. if you invert and, you will end up with the same order as in or, thus making an "or" operator based on "and" Answer: execute if @e[tag=p (or) tag=q] (this does not work, as there is no or) Is equivalent to this: execute unless @e[tag=!p,tag=!q] It will not execute if there is no tag p and no tag q. it will execute if there is tag p or tag q.

Answered by Andrés on December 25, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP