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]

The best Steam region to buy games The best Steam region to buy games

Posted On: November 13, 2023
what's the cheapest region on Steam to buy online games? I'm trying to undestand how do resellers purchase games and sell them at a higher pricing. What's the method of purchasing th...[More]


How to Farm and Harvest Crops Properly How to Farm and Harvest Crops Properly

Posted On: July 8, 2021
Mom always told me to eat my vegetables. Contrary to popular belief, a diet consisting entirely of steak is unhealthy and expensive. Eating meat is for rich people, and since you’re probably not...[More]


Hey guys! I really need help with Hogwarts Legacy Hey guys! I really need help with Hogwarts Legacy

Posted On: March 11, 2023
Hey guys! I really need help, I have the game on PC but am not very tech savvy, so don’t really understand them. My laptop normally runs games really well, sims 4, Skyrim (on high I think) but t...[More]


Sheathe wand Sheathe wand

Posted On: September 15, 2023
If there are going to be any dlc or a second game , i beg you game developers to make a button to sheathe the wand or to have it in your hand until you manually put it back . It is a nice little detai...[More]


Ask anything Ask anything

Posted On: September 28, 2024
My brother brought it and i am planning on playing it too, but before that i wanted to do this and make fun of it when i finish it so.Question from user Choice_Knowledge_577 at BaldursGate3 at reddit....[More]


For Hogwarts Legacy Should I Use PS4 or Switch? For Hogwarts Legacy Should I Use PS4 or Switch?

Posted On: April 15, 2023
So I've been waiting for this game for ages, and I really want to play it. I have a PS4 and a Switch, and I was thinking of getting the Switch version once it comes out, because honestly it's ...[More]


WHY IS SALAMI A WEAPON?!? WHY IS SALAMI A WEAPON?!?

Posted On: March 25, 2025
i don’t even know what to say…should i start beating up the steel watch with salami now????Question from user Bellaswannabe at BaldursGate3 at reddit.com.Answer:Yes start beating people up with th...[More]


YO-KAI WATCH 2: Fleshy Souls - What donuts should I pick? YO-KAI WATCH 2: Fleshy Souls - What donuts should I pick?

Posted On: March 19, 2023
Right at the beginning of the game you are asked to choose between Soul Donuts and Spirit Donuts. Does this have any actual affect on the game? Does it matter what you pick? Question from user user...[More]


Is it possible to do The Pitt without a slave outfit in Fallout 3? Is it possible to do The Pitt without a slave outfit in Fallout 3?

Posted On: June 19, 2023
I found the slave camp before I found The Pitt guy. I killed the slavers, freed the slaves, talked to The Pitt guy and didn't choose the right dialog options. Then went back to Megaton to do a who...[More]


Does a physical copy of Batman: Arkham City Armored Edition need any extra install size on Wii U? Does a physical copy of Batman: Arkham City Armored Edition need any extra install size on Wii U?

Posted On: March 25, 2023
Does a physical copy of Batman: Arkham City Armored Edition need any extra install size on Wii U, and how much needed space it takes? . I'm asking because i want to get it but i only have left ...[More]