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 I empty a soul gem in Skyrim? Can I empty a soul gem in Skyrim?

Posted On: May 1, 2023
I have several Grand Soul Gems filled with Petty Souls, which seems like a waste of a Grand Soul Gem. Is there a way to EMPTY the Soul Gem so I can refill it with a larger soul? I have the Dawng...[More]


Why cant I see the special world types in Minecraft even though I am pressing shift? Why cant I see the special world types in Minecraft even though I am pressing shift?

Posted On: June 23, 2023
I want to try to play special kind of worlds (like Floating Island and Debug), and I remember that in order to do that, you need to press shift while clicking on the World Type button on the Create Ne...[More]


Dynamic Lighting in (vanilla) Minecraft Dynamic Lighting in (vanilla) Minecraft

Posted On: August 25, 2023
I have already seen tutorials on Minecraft regarding dynamic lighting, but none of them seem fancy enough. What I'm thinking of is a way to make dynamic lighting that is clean and not destructi...[More]


Why cant I satisfy the Diamond Equipment challenge in Age of Empires 2? Why cant I satisfy the Diamond Equipment challenge in Age of Empires 2?

Posted On: June 30, 2023
I've tried to complete this challenge multiple times, but it never seems to complete. I have tried playing multiple single player skirmishes without cheats and completed all 15 blacksmith upgrades...[More]


In Farmville, Can I make friends with people who arent my social media friends? In Farmville, Can I make friends with people who arent my social media friends?

Posted On: May 25, 2023
I want friends! Friends seem awesome! I have a couple through people I know on Facebook, but not a lot of people I know are playing this game. Can I make friends any other way than connecting my socia...[More]


I don't like Gale I don't like Gale

Posted On: April 7, 2026
I know I'm not alone in this opinion either, but there's also a shocking amount of people who love Gale so I'm trying to understand the appeal. .Please understand, I have used Gale in my party all the...[More]


Are the Highlighted destructible items in Diablo 3 significant in any way? Are the Highlighted destructible items in Diablo 3 significant in any way?

Posted On: May 10, 2023
I've noticed that I come across destructibles (doors, barrels, other props) that have a kind of highlight, a double helix type of spiral with some effect. Do these items have any significance? ...[More]


How to unlock the Bandolier via ammo caches? How to unlock the Bandolier via ammo caches?

Posted On: March 17, 2024
Aside from buying the Bandolier as a tier3 item at the shop, I've read you can unlock it by other means, after accessing some secret exits in Chaos Generator and Marksman and hitting some switches. H...[More]


Is there a game called Sonic: The Next Level? Is there a game called Sonic: The Next Level?

Posted On: June 20, 2023
I've been watching the docuseries "High Score" on Netflix, and in episode 4, the Sega episode, there are several clips that refer to something called "Sonic: The Next Level" an...[More]


Crucio Crucio

Posted On: August 7, 2023
So I'm on the brink of level 18 and I've just talked to sebastian about crucio and he told me to wait for his owl post, how long do I have to wait for him to reach out to start the quest? Q...[More]