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]

What is the Concerned Citizen in The Witcher 3? What is the Concerned Citizen in The Witcher 3?

Posted On: June 8, 2023
In Novigrad I keep finding sheets of paper with messsages involving the "Eternal Fire" and Novigrad's church. They seem to be written by someone who is against Magic, Witches, Mages a...[More]


Can I turn off this Necromancer visual effect? Can I turn off this Necromancer visual effect?

Posted On: June 16, 2023
I was in a team with a Necromancer and one the skills was to create a patch of black smoke. However this skill seems to just obscure everything! My character, my loot, enemies and even chests. This...[More]


What is the use item in Sam and Max What is the use item in Sam and Max

Posted On: June 23, 2023
This question bothers me since I was a kid. In Sam and Max - Hit the Road, what is the green thing in the "use" icon? Is it a duck? Is it a toy? Question from user Keeper at stackex...[More]


How can I earn dungeon achievements in the regular version of Cookie Clicker? How can I earn dungeon achievements in the regular version of Cookie Clicker?

Posted On: September 13, 2023
There are four shadow achievements in Cookie Clicker which involve dungeons:. Getting even with the oven: Defeat the Sentient Furnace in the factory dungeons. Now this is pod-smashing: Defeat th...[More]


Do maps fill out while exploring underground? Do maps fill out while exploring underground?

Posted On: April 26, 2024
When a craftable map is held, exploring the world will fill out areas of the map with an image of the world surface. Will said map be updated the same way if held while exploring underground? Or will ...[More]


How many aspects can you hold in your inventory in Diablo 4? How many aspects can you hold in your inventory in Diablo 4?

Posted On: June 14, 2023
How many aspects can you hold in your inventory in Diablo 4? Is there a max? I can't find anything on the internet about this. Question from user Merl at stackexchange. Answer: Aspect ...[More]


I cant find Manaphy in Pokemon Legends Arceus I cant find Manaphy in Pokemon Legends Arceus

Posted On: July 13, 2023
I finished all the tasks, even unlocked the cave, but Manaphy isn't there. I already repeated the process many times, he's not there. Any help? Question from user Maria Zapata at stackex...[More]


How can I complete Desert Snakes in Forza Horizon 5? How can I complete Desert Snakes in Forza Horizon 5?

Posted On: April 3, 2023
I have been trying to complete the challenge in Forza Horizon 5 Rally Adventure, but although the timer starts when I leave Valle de Foráneos, I do not get a waypoint to follow. I have tried...[More]


How do I find my follower if and when they leave me? How do I find my follower if and when they leave me?

Posted On: August 25, 2022
I had parked my follower at an inn with a bunch of valuable items that I didn't want to carry. I guess I have been out a bit too long as this message appears: . Your follower tires of waiting and lea...[More]


Frequency of the Golden Bowser Train? Frequency of the Golden Bowser Train?

Posted On: January 28, 2023
Does anyone happen to know how often you can go to the Golden Bowser Train? For those that don't yet know, it is a level with nothing but coins, and is a great way to bolster your extra lives.Questio...[More]