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]

I absolutely hate Merlin trials in Hogwarts. I absolutely hate Merlin trials in Hogwarts.

Posted On: June 23, 2023
I have completed the main quests and I’ve still just done maybe 2 or 3 Merlin trials at max. Is it just me? Question from user Spiritualmatterhorn at HogwartsLegacyGaming at reddit. Answer...[More]


How do GameShark codes work? How do GameShark codes work?

Posted On: July 22, 2013
This has always boggled me. Obviously GameShark and Game Genie never got inside access to place their own cheats into every game. I don't think any developers gave them the source code to pour over fo...[More]


How do I find out the mythology and history of my Fortress? How do I find out the mythology and history of my Fortress?

Posted On: April 28, 2024
I've created a nice fortress with taverns, beds, dining room, etc, but how do I access some of the mythology of the world they are in?I have no idea of the context and the history of my world, but I'm...[More]


In Vampire Survivors, why are some Bestiary entries yellow? In Vampire Survivors, why are some Bestiary entries yellow?

Posted On: March 12, 2023
Why are Skeleton, Lionhead, Milk Elemental and Dragon Shrimp written in yellow font? There are more entries like, but I think they are less than 10% of all. Question from user arghtype at gaming.st...[More]


How do I sell off the junk in my ship for good? How do I sell off the junk in my ship for good?

Posted On: September 12, 2023
My current home ship was confiscated from some baddies and has some shielded cargo. I have upgraded a bit to increase my cargo capacity to safely store my belongings. However, I like collecting rocks ...[More]


What does a checkmarked item mean in Somnium? What does a checkmarked item mean in Somnium?

Posted On: May 9, 2023
When I replay a Somnium section sometimes some of the items will have a checkmark next to them. This can appear even if I haven't performed every possible action with that item. What does a che...[More]


What is the best class to RP as a doctor? What is the best class to RP as a doctor?

Posted On: May 7, 2025
So, I want to try and play as a doctor character but don't know what class would fit them best. Armor wise, I feel like they would only wear clothing and wield a staff. I was thinking cleric could fit...[More]


I caught an Eevee, which of its evolutions will it evolve into? I caught an Eevee, which of its evolutions will it evolve into?

Posted On: February 14, 2023
So I just caught an Eevee. Now, I need 25 candies to evolve it. The fact is that in the GameBoy color versions, that Pokémon needed a stone to evolve instead of experience. Depending of the sto...[More]


Where can I find the Slytherin Common Room in Hogwarts Legacy? Where can I find the Slytherin Common Room in Hogwarts Legacy?

Posted On: July 20, 2023
Where's the Slytherin Common Room? I'm trying to find it, but I'm struggling. I know it is somewhere in the basements if I'm not mistaken, but where? Where exactly is it? Does so...[More]


Fallout 4 wont launch after a December 2023 Xbox update Fallout 4 wont launch after a December 2023 Xbox update

Posted On: April 26, 2024
After the Xbox update on December 6th to version 10.0.25398.2917, I am unable to start Fallout 4 anymore. The loading screen is shown, but nothing else happens.I have already tried restarting my Xbox ...[More]