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]

Reach the compartment before it closes in Agent A: A Puzzle in Disguise Reach the compartment before it closes in Agent A: A Puzzle in Disguise

Posted On: July 9, 2023
In chapter 3, there is a button on the ground to the right of a platform in the center of the room. Clicking the button opened a compartment on the left side of the platform. The compartment keeps clo...[More]


Can guards find and arrest you in casing mode in a public area during a searching phase? Can guards find and arrest you in casing mode in a public area during a searching phase?

Posted On: September 10, 2023
In Payday 3, certain things can cause a Searching phase, such as a teammate being cuffed. During this phase, if you're caught in a private area in casing mode you will be cuffed instead of escorte...[More]


N++ System Requirements on Mac N++ System Requirements on Mac

Posted On: March 17, 2024
I'm looking at N++ (https://store.steampowered.com/app/230270/N_NPLUSPLUS/) and it doesn't list the system requirements for a mac.This question is not about whether my specific computer can run N++, b...[More]


Hogwarts Legacy Help 100% please Hogwarts Legacy Help 100% please

Posted On: July 29, 2023
Can somebody please walk me through what I'm missing for the platinum? I'm missing 1 revelio page in hogwarts and I don't know which one it is, I've tried guides and everything, I just...[More]


In Valheim, Do Fuling villages respawn? In Valheim, Do Fuling villages respawn?

Posted On: February 16, 2023
After clearing out a Fuling village, it looks like a good place to set up a base as long as they don't come back. Will the Fulings respawn after a while or is it a safe once the village is clear? ...[More]


What Hogwarts tips do you wish you'd known when you started? What Hogwarts tips do you wish you'd known when you started?

Posted On: March 26, 2023
For example, I had to Google how to jump on my broom after the flying class as don't recall it saying to hold LB and press B. (Edit: this was after I purchased the broom and had been playing for a...[More]


Why does Nobody Comes to Fika not unlock in Crusader Kings 3? Why does Nobody Comes to Fika not unlock in Crusader Kings 3?

Posted On: May 26, 2023
I started a game of Crusader Kings 3 as a count of Fika. I diverged the culture from Sao in 937 and have been busy spreading it since. However, I'm up to 42 counties converted with no achievement ...[More]


Where can I find pearls in Witcher 3? Where can I find pearls in Witcher 3?

Posted On: March 5, 2023
I am playing Witcher 3 from after patch 1.05. Is it possible to buy shells (pearls) from a merchant, or do I have to find them somewhere? Question from user Purple Rabbit at gaming.stackexchange...[More]


How to get past the old man in Viridian City in Pokemon Leaf Green? How to get past the old man in Viridian City in Pokemon Leaf Green?

Posted On: March 20, 2024
It's been a while since I last played Pokémon Leaf green.I am playing it with my nephew and he asked me how to get to first Gym (Brock) to get the Boulder badge.Here is the problem:.An old man is lyi...[More]


Can I use Xbox 360 controllers with Xbox Classic (first generation of Xbox)? Can I use Xbox 360 controllers with Xbox Classic (first generation of Xbox)?

Posted On: November 12, 2023
This is a tricky question and I can't find reliable answer anywhere on the Internet. I love my old Xbox Classic (the first Xbox console from 2001). Unfortunately both my original pads have died...[More]