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]

Why are expected delivery times given as a range? Why are expected delivery times given as a range?

Posted On: January 22, 2023
On the "Current job" screen in the Route Advisor, the expected delivery time is always given as a range, e.g. "Fri 21:50 - Sat 2:00".Why is that? I know the second time is the actual deadline and if y...[More]


Do you pay a gold tax when beating the final boss in Heroes Of Hammerwatch? Do you pay a gold tax when beating the final boss in Heroes Of Hammerwatch?

Posted On: March 10, 2023
Throughout the game, you can deposit your found gold and ore in elevators to take to the surface, at a tax rate that depends on how much gold you have collected. I decided to be brave, and do an entir...[More]


In Ben 10 Alien Force, How do you defeat the two huge snakes that come out of the wall? In Ben 10 Alien Force, How do you defeat the two huge snakes that come out of the wall?

Posted On: April 2, 2023
In Ben 10: Alien Force – Vilgax Attacks (Xbox 360), how do you defeat the two huge snakes that come out of the wall? Question from user Bravax at gaming.stackexchange.com. Answer: It se...[More]


Anyone know how often the Hogwarts Express comes to the station? Anyone know how often the Hogwarts Express comes to the station?

Posted On: March 3, 2023
I’m getting in game screen shots and want a picture with the train. Question from user Giezho at HogwartsLegacyGaming at reddit.com. Answer: Best way to find it is to go to the train st...[More]


Why am I unable to equip the Drakefire Pistols in Warhammer Vermintide 2? Why am I unable to equip the Drakefire Pistols in Warhammer Vermintide 2?

Posted On: May 29, 2023
I just received a pair of the Drakefire Pistols, but they are obscured by a red cancel icon and I can't equip them. I'm sure that the dwarf was able to equip them in the first Vermintide, and ...[More]


Statement from Larian Statement from Larian

Posted On: November 27, 2023
Regarding patch 4:. " In Patch 4 we introduced a fix that would prevent the Scrying Eyes in Moonrise Towers from immediately calling the guards on you when stealing, even if you were sneaking,...[More]


What is the terminal velocity of a sheep? What is the terminal velocity of a sheep?

Posted On: August 25, 2015
I am thinking of an alternative timing mechanism; I am building a trap and I wanted to try something different to set it off. I want to drop a sheep from n blocks high so that I have a delay before...[More]


Hogwarts Legacy is Excellent but lacking? Hogwarts Legacy is Excellent but lacking?

Posted On: April 17, 2023
Anyone else love the game but just feel they could have expanded on a lot of things? Beast taming could have been a proper side thing yet I'm just feeding them for materials, once I've gott...[More]


Please help me with Hogwarts Legacy Please help me with Hogwarts Legacy

Posted On: April 23, 2023
I was on my way to meet Jackdaw at the forbidden forest when I fell into this tomb, iv tried loading my different save points but iv spent so long in here that they are all putting me in the same spot...[More]


What devices can you play Sonic Mania on? What devices can you play Sonic Mania on?

Posted On: January 24, 2023
I asked this question because Sonic Mania can probably be played on a few devices.Question from user Dark sonic at gaming.stackexchange.com.Answer:From the Wikipedia article on Sonic Mania, the game i...[More]