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]

Is this cheating in BG3 Honor Mode or fair game? Is this cheating in BG3 Honor Mode or fair game?

Posted On: August 27, 2025
I’m doing a Baldur’s Gate 3 Honor Mode run with three friends. We’ve made it all the way into Act 3 without glitches, cheese, or exploits — just raw pain and strategy.Here’s the problem: one...[More]


How can I kill adorable animals? How can I kill adorable animals?

Posted On: December 6, 2011
With version 1.0.4 of Terraria came fluffy little bunnies hopping in my fields and happy little goldfish swimming in my lakes, grateful for the sanctuary my base provides them against the horrors of t...[More]


Is there an in-world explanation why Aloy needs to learn skills again? Is there an in-world explanation why Aloy needs to learn skills again?

Posted On: April 14, 2023
I just finished playing Horizon: Zero Dawn on PC. While waiting for a PC version of Forbidden West, or ability to buy PlayStation 5, I have read the reviews and it looks like in Forbidden West Aloy ne...[More]


Command to say player coords in chat? Command to say player coords in chat?

Posted On: January 28, 2023
Trying to get a command that tells a player's coords in chat. I have a working command: /data get entity @s Pos, but I assume I would need to combine this with /tellraw?Question from user Aceplante at...[More]


Why will she not take Panteas Flute? Why will she not take Panteas Flute?

Posted On: January 17, 2023
I found Pantea's Flute before the quest was given to me. Now she will not accept it from me, and it says I still need to go find it. What do I do now? Is this a glitch? I have the game on PC if th...[More]


What blocks Barbarian spell casting? What blocks Barbarian spell casting?

Posted On: August 29, 2023
I have been experimenting with Karlach and a Heat build, as she has innate fire resistance. However I often encounter this when trying to use the Heat for extra fire damage. Casting spells is block...[More]


In Yupitergrad 2, How do I defeat the shield drone? In Yupitergrad 2, How do I defeat the shield drone?

Posted On: July 20, 2023
In Yupitergrad 2: the Lost Station, I have just acquired the miniguns, and now I am trying to get past the adjacent room that has a single, button-activated drone that is protected by a glowing shield...[More]


Consequences of poor performance early in the campaign Consequences of poor performance early in the campaign

Posted On: December 4, 2023
In vanilla DoW2's campaign, does wasting time before the Tyranids show up have any consequences? A friend and I have been playing vanilla DoW 2's coop campaign mode. However, we screwed up ...[More]


Is there an easier Whistle Sprint Alternative to execute in Tears Of The Kingdom? Is there an easier Whistle Sprint Alternative to execute in Tears Of The Kingdom?

Posted On: July 25, 2023
Whistle Sprinting is a glitch in Breath of the Wild where you hold the whistle button and tap the B button to continuously sprint without draining stamina. In Tears of the Kingdom, this glitch has ...[More]


How to catch Latios and Latias? How to catch Latios and Latias?

Posted On: September 20, 2023
I'm starting to play Pokemon Emerald! How can I catch or encounter Latios or Latias in the game? I want this Pokemon so bad! This is my childhood Pokemon because it can one shot Rayquaza! So cool!...[More]