Using - execute command, how do I check if a block is one of multiple possibilities?

[BACK]
Using - execute command, how do I check if a block is one of multiple possibilities?
Posted On: April 8, 2024

Using an /execute command, I want to check if a certain block is, for example, either oak_fence, OR iron_bars.


However, in my specific case, I can't just use two command blocks to check for either one separately. I tried doing so, like this:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence run tag @s remove tagA.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Note: I set both command blocks to "Repeat", "Unconditional", and "Always active".


The result is not what I expected, because:.


if the block is oak_fence, the tag should be left on, however the second command removes it.


if the block is iron_bars, the tag should be left on, however the first command removes it.


What I need is to check, in a single command, for the tag to be removed only when the block is neither oak_fence OR iron_bars.


A possible solution I've thought of, but haven't tested yet, could be: setting up another 2 tags, check_oak_fence and check_iron_bars, which are given to players standing on either oak_fence or iron_bars.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ oak_fence run tag @s add check_oak_fence.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ iron_bars run tag @s add check_iron_bars.


And then checking for those 2 tags in the as portion of the /execute command, which apparently does permit an OR gate, like this:.


/execute as @a[tag=!check_oak_fence, tag=!check_iron_bars].


I also tested this question's only answer, modifying it so it checks the same block twice:.


/execute if block ~ ~-1 ~ oak_fence if block ~ ~-1 ~ iron_bars.


But that obviously can't work, because that's an AND gate, meaning it checks if a block is simultaneously two types of block at once, which is impossible, thus it can never return true.


Question from user Gaetano96 at gaming.stackexchange.com.


Answer:

You essentially want:.


not(OF or IB).


which, using De Morgan's law, is equal to:.


(not OF) and (not IB).


Giving that, you should be able to chain the last command you found, but with inverted conditions:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Answer from user pinckerman at gaming.stackexchange.com.


[BACK]
Using - execute command, how do I check if a block is one of multiple possibilities?
Posted On: April 8, 2024

Using an /execute command, I want to check if a certain block is, for example, either oak_fence, OR iron_bars.


However, in my specific case, I can't just use two command blocks to check for either one separately. I tried doing so, like this:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence run tag @s remove tagA.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Note: I set both command blocks to "Repeat", "Unconditional", and "Always active".


The result is not what I expected, because:.


if the block is oak_fence, the tag should be left on, however the second command removes it.


if the block is iron_bars, the tag should be left on, however the first command removes it.


What I need is to check, in a single command, for the tag to be removed only when the block is neither oak_fence OR iron_bars.


A possible solution I've thought of, but haven't tested yet, could be: setting up another 2 tags, check_oak_fence and check_iron_bars, which are given to players standing on either oak_fence or iron_bars.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ oak_fence run tag @s add check_oak_fence.


/execute as @a[tag=!tagA] at @s if block ~ ~-1 ~ iron_bars run tag @s add check_iron_bars.


And then checking for those 2 tags in the as portion of the /execute command, which apparently does permit an OR gate, like this:.


/execute as @a[tag=!check_oak_fence, tag=!check_iron_bars].


I also tested this question's only answer, modifying it so it checks the same block twice:.


/execute if block ~ ~-1 ~ oak_fence if block ~ ~-1 ~ iron_bars.


But that obviously can't work, because that's an AND gate, meaning it checks if a block is simultaneously two types of block at once, which is impossible, thus it can never return true.


Question from user Gaetano96 at gaming.stackexchange.com.


Answer:

You essentially want:.


not(OF or IB).


which, using De Morgan's law, is equal to:.


(not OF) and (not IB).


Giving that, you should be able to chain the last command you found, but with inverted conditions:.


/execute as @a[tag=tagA] at @s unless block ~ ~-1 ~ oak_fence unless block ~ ~-1 ~ iron_bars run tag @s remove tagA.


Answer from user pinckerman at gaming.stackexchange.com.


[BACK]

What is the True Ending in Hogwarts Legacy? What is the True Ending in Hogwarts Legacy?

Posted On: July 19, 2023
What is the True Ending in Hogwarts Legacy after you've completed the main storyline? The answer in this question explains the main storyline endings, but I'm looking for the so-called &quo...[More]


How are the structure decks in Yu-Gi-Oh 5Ds World Championship 2010: Reverse of Arcadia unlocked? How are the structure decks in Yu-Gi-Oh 5Ds World Championship 2010: Reverse of Arcadia unlocked?

Posted On: April 2, 2023
In Yu-Gi-Oh! 5D's World Championship 2010: Reverse of Arcadia, I've unlocked a couple randomly (as far as I can tell), but I'd like to be able to buy them all. Does anyone know a way to un...[More]


Will a Star Fragment disappear if I use fast travel in Tears of the Kingdom? Will a Star Fragment disappear if I use fast travel in Tears of the Kingdom?

Posted On: May 29, 2023
I saw a Star Fragment land a fair distance away from me while exploring at night. I was going to run towards it, when I noticed it had landed right next to a tower I could fast travel to. If I fast...[More]


Villager breeder not working, showing angry particles: 1.17.1 Villager breeder not working, showing angry particles: 1.17.1

Posted On: June 15, 2023
I've built a villager breeder following this tutorial: . It worked for a while before it stopped working, as villagers show angry particles whenever they try to breed. I have broken and plac...[More]


What language is Space Engineers programmed in? What language is Space Engineers programmed in?

Posted On: July 21, 2023
I've tried searching online for this - but I always end up in the in-game programming language (C#) sites, but I'm curious what the game itself is programmed in. I would assume a game like thi...[More]


Bad graphics in Hogwarts Legacy Bad graphics in Hogwarts Legacy

Posted On: June 30, 2023
I just downloaded Hogwarts Legacy today on my PS4, but can't really enjoy it because the graphics are so bad. Shadows flicker and everything looks grainy. Its like the graphics settings are really...[More]


I’m completely stuck I’m completely stuck

Posted On: November 4, 2023
I think I’m on act 2, but sorry if I’m not for the tags, but anyway, I’ve been trying all day to complete this bit where you have to kill the Inquisitor person, I went into the porta...[More]


Marked as a quest item. Reading it never updated my journal? Marked as a quest item. Reading it never updated my journal?

Posted On: March 13, 2026
I've had sooo many playthroughs and this quest item never made sense. I think I have a memory of it working in early patches - lately I haven't triggered anything from it. Not even dialogue reactions....[More]


How do I find: inactive jump gate At the beginning of Kingdoms End in X4: Foundations? How do I find: inactive jump gate At the beginning of Kingdoms End in X4: Foundations?

Posted On: August 31, 2023
How do I do this? Its somewhere in the Great Reef system, if I leave the mission changes to travel to Great Reef. There's nothing on the map. The mission description provides no hints. No...[More]


What is the Font Used in Pokemon Conquest? What is the Font Used in Pokemon Conquest?

Posted On: January 26, 2023
What's the font used in Pokemon Conquest's dialogue? More specifically, since I assume it's some proprietary font compiled in the game, where have I seen it before? It looked extremely familiar as soo...[More]