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]

Any useful strategies for finding a Nether Fortress in Minecraft? Any useful strategies for finding a Nether Fortress in Minecraft?

Posted On: June 20, 2023
Anyone have useful strategies for finding a Nether Fortress in Minecraft's Nether? I got into the nether and wandered around for quite a while, but didn't find anything. I'm not sure if...[More]


How do I transfer wares for a mission in X4 Foundations? How do I transfer wares for a mission in X4 Foundations?

Posted On: September 1, 2023
How do I transfer wares to finish a mission? I'm docked at the correct ship, but transfer wares is disabled in the menu. I'm at the correct ship:. And I have the antimatter cells in m...[More]


Cant click on two buttons at the same time on gaming mouse Cant click on two buttons at the same time on gaming mouse

Posted On: August 19, 2023
When I play Fortnite i want to build quick. I noticed that my gaming mouse "Star Raider CND-SGM1" doesn't recognize when I FIRST hold my left click and than I click on "back key&quo...[More]


Fire Emblem Engage - levelling past level 20? Fire Emblem Engage - levelling past level 20?

Posted On: April 3, 2024
Once my character hits level 20 on advanced class their stats stop growing. I see that I can use that silver seal to select the same advanced class so they keep growing. This disables the class skill ...[More]


Which BG3 NPCs would you like to fight in D&D? Which BG3 NPCs would you like to fight in D&D?

Posted On: November 20, 2023
I am currently organizing a D&D one shot/minigame for a large group, which consists of fighting a gauntlet of important characters from media, including games, movies and stuff even outside of D&a...[More]


How do I complete a Cargo Link quest? How do I complete a Cargo Link quest?

Posted On: October 28, 2023
One of my quests is to establish a Cargo Link for Uranium at Akila. (I can't find any further information in my mission logfile how to do that.). I have found the console near the landing zo...[More]


How do I pass the level 7 will find forward puzzle? How do I pass the level 7 will find forward puzzle?

Posted On: June 12, 2023
The objective is to delete all the red outlined characters. . It allows only 12 key presses and you enter from the bridge above (on either n, d or the space after "find)". Leaving the puz...[More]


Could Phoenix tears cure Anne? Could Phoenix tears cure Anne?

Posted On: September 1, 2023
I don’t know a whole lot about what Phoenix tears can and cannot cure, but when rewatching Chamber of Secrets, the thought came to me. Question from user Proud-Product-7748 at HogwartsLegacyG...[More]


How do I destroy the Harley Heads? How do I destroy the Harley Heads?

Posted On: September 5, 2023
I'm talking about the Harley Heads in the Steel Mill where if you press the button, you hear Harley talking through the intercom. I know I have to do something to them, because there's a count...[More]


Can I go back for clues later if I confront Risky Boots now? Can I go back for clues later if I confront Risky Boots now?

Posted On: April 27, 2024
Near the end of Shantae: Half Genie Hero, Uncle Mimic tells Shantae that she can either confront Risky Boots head on or search for four clues first to formulate a plan. I've been told that searching f...[More]