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]

Does Echo Form stack with itself? Does Echo Form stack with itself?

Posted On: January 4, 2024
The description for the Power card Echo Form states. The first card you play each turn is played twice. What happens if you play Echo Form multiple times in a battle? Does the first card played ...[More]


What does shadow cache option exactly do in resident evil 4 remake? What does shadow cache option exactly do in resident evil 4 remake?

Posted On: April 10, 2023
Resident evil 4 remake on PC has the graphics option "shadow cache", what does it exactly do? The comparison picture they provide does not show any difference really. Is it dynamic or for mo...[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]


What is your toughest Hogwarts Legacy enemies so far? What is your toughest Hogwarts Legacy enemies so far?

Posted On: June 5, 2023
For me it's DUGBOG!!!. It is frustrating to run upon them in a swamp. If there are only one or two of them, it is tolerable, but if there are four, I will die right away. Levioso won't w...[More]


How do I know which version of Minecraft I have? How do I know which version of Minecraft I have?

Posted On: April 26, 2023
I don't know which version of Minecraft I have. I have regular Minecraft, not Java or anything else and I just don't know the version I have. Question from user Azalea at gaming.stackexchan...[More]


How to enable the lift to Engineering in Executive in System Shock? How to enable the lift to Engineering in Executive in System Shock?

Posted On: June 3, 2023
I'm in Executive trying to take the lift to Engineering but it is disabled and the PA says: "Elevator disabled. Biohazard emergency." I already went to the three groves and disabled t...[More]


How do I fix pink Hearthstone screen (android)? How do I fix pink Hearthstone screen (android)?

Posted On: January 18, 2023
Since the last update (16 March 2016) my Hearthstone screen is not as it used to be. I like pink, but not this much. How do I fix this? Question from user Mathias711 at gaming.stackexchange.com. ...[More]


Is there any difference between Super Mario Wonders characters? Is there any difference between Super Mario Wonders characters?

Posted On: November 4, 2023
The game explains that choosing any Yoshi or Nabbit lets you play an easier version since you can't be damaged. But what about the other characters? In Super Mario 3D World each one had a special ...[More]


Why remove redstone dust from my command block contraptions? Why remove redstone dust from my command block contraptions?

Posted On: December 29, 2023
Whenever I show my command block contraptions to my friends, they always comment that I should remove the redstone dust from them. They say it causes lag and that redstone can be unpredictable, but I&...[More]


Wake me up when September starts Wake me up when September starts

Posted On: June 3, 2024
Question from user ozangeo at BaldursGate3 at reddit.com.Answer:Ooh, publicly announcing that level of testing suggests that they’re going to add modding tools with some interesting functionality. I...[More]