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]

Can you unlock secret stamps before beating the game in Storyteller? Can you unlock secret stamps before beating the game in Storyteller?

Posted On: November 24, 2023
After getting every crown in Storyteller, I unlocked a list of achievements called the Secret Stamp Collection. If I met the requirements for one of these stamps before beating the game, could I unloc...[More]


What's the worst way to re-class every companion? What's the worst way to re-class every companion?

Posted On: October 16, 2025
Everyone talks about the best way. .What would be the worst and/or most unhinged classes to give each companion. .My favorite would be making Minthara a Wizard.Question from user kikicandraw at Baldur...[More]


Is Hogwarts Legacy on Hard Difficulty really that difficult? Is Hogwarts Legacy on Hard Difficulty really that difficult?

Posted On: May 26, 2023
I finished downloading the game the other day and I haven’t had time to really start it. I like a bit of a challenge but I don’t want anything too crazy. Question from user Interesting-...[More]


How do you hire a Hacker in Game Dev Story? How do you hire a Hacker in Game Dev Story?

Posted On: April 13, 2024
I'm on my second playthrough of Game Dev Story, choosing the Hire option at least twice per game year and varying between "Word of Mouth", "Magazine Ad", and "Online Ad" — never seen a Hacker availa...[More]


How do you get to these chests in Hogwarts Legacy? How do you get to these chests in Hogwarts Legacy?

Posted On: August 22, 2023
In the gatehouse of the High Keep you can see a loft and Revelio reveals some chests up there but I can’t figure out how to reach them. It looks like you should be able to climb this pile of cra...[More]


Missing Field Guide Pages in Hogwarts Legacy Missing Field Guide Pages in Hogwarts Legacy

Posted On: August 15, 2023
Missing two from the Bell tower zone, one from the Astronomy, and one from the Great Hall. I went through two guides step by step for the Great Hall and then a video guide step by step for the Great H...[More]


Where can I contact roblox support (a real person)? Where can I contact roblox support (a real person)?

Posted On: September 19, 2023
Can someone tell me how to contact Roblox support? I don't mean roblox/support, that's just a bot. I want to talk to a real human who works in Roblox support. Question from user comand100vi...[More]


Cant click on two buttons at the same time on gaming mouse Cant click on two buttons at the same time on gaming mouse

Posted On: August 19, 2023
When I play Fortnite i want to build quick. I noticed that my gaming mouse "Star Raider CND-SGM1" doesn't recognize when I FIRST hold my left click and than I click on "back key&quo...[More]


Any way to fix Cathedral crash in Fallout 4? Any way to fix Cathedral crash in Fallout 4?

Posted On: March 24, 2023
I really searched it before on web. I can't get to the 3rd level in Cathedral (Master's Lair). All the solutions I found were from a very old thread in No Mutants Allowed. Nothing worked for m...[More]


Capturing and Transporting Your Villagers Capturing and Transporting Your Villagers

Posted On: June 23, 2021
Do you want your villagers to get eaten by zombies? No? Neither do I. These mindless simpletons may not look the part, but they’re one of the most valuable resources in the vast world of Minecra...[More]