3

How can you make a conditional command in datapacks?

ManKiind's Avatar ManKiind12/9/19 2:42 pm
3 emeralds 5.1k 9
12/17/2019 4:32 pm
ManKiind's Avatar ManKiind
I am aware of the If and Unless statements but I haven't figured out a way to make conditional lines as in the way it can be done with command blocks.

I am looking to make it where command two will not run unless command one successfully runs, any idea on how to accomplish this?
Posted by ManKiind's Avatar
ManKiind
Level 29 : Expert Miner
1

Create an account or sign in to comment.

9

1
12/17/2019 4:32 pm
Level 29 : Expert Miner
ManKiind
ManKiind's Avatar
solved
1
12/10/2019 12:35 am
Level 52 : Grandmaster Blob
HoboMaggot
HoboMaggot's Avatar
Yeah theres a few ways. They all require a 2nd command after the first before running the 2 commands. (Unless it is just detection)

If this is just detection of an entity:
/execute as <entity> run tag @s add DoThis

Then the 2 commands + removing the tag:
/execute as <entity>[tag=DoThis] run command1
/execute as <entity>[tag=DoThis] run command2

After those 2 remove the tag (put in the command after those 2 commands, as functions go from top-bottom):
/execute as <entity>[tag=DoThis] run tag @s remove DoThis


Without further elaboration, I cannot give you a proper guide.
1
12/09/2019 3:46 pm
Level 36 : Artisan Engineer
Chillo
Chillo's Avatar
The depends a little bit on the condition you're trying to archive.
As a tip: When running a command via "execute as", if a @ selector (which can also be filtered by nbt tags) returns no result, the command won't be executed.
2
12/09/2019 3:11 pm
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
You can change the second command block's state to "conditional", "chain" mode and "always active", then it will only execute its command if the command block pointing to it (the command block with the first command) has executed its command successfully.
2
12/09/2019 7:26 pm
Level 29 : Expert Miner
ManKiind
ManKiind's Avatar
Oop, I knew that this question was for datapacks. I guess I didn't specify, oops.
1
12/10/2019 7:37 am
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
Oh okay, unfortunately I don't know anything about data packs :/
2
12/09/2019 3:32 pm
Level 32 : Artisan Dragonborn
TobySuren
TobySuren's Avatar
yep- you beat me to it! If you want to take a Redstone signal from the first command then you can use a comparator going out of the block and into a repeater.
1
12/09/2019 4:00 pm
Level 87 : Elite Deity
Captain_JEK
Captain_JEK's Avatar
Yeah, that works but it makes large command block structures slow because the comparator has 1 redstone tick delay. Chained command blocks execute their command in the same tick as the command block that activated them.

I think another problem with comparators is that you need to reset them or the command block they're getting their signal from after the command has been executed successfully.
2
12/09/2019 4:32 pm
Level 32 : Artisan Dragonborn
TobySuren
TobySuren's Avatar
Fair point. You could also put a /setblock x y z redstone_block and a /setblock x y z air if you really wanted to.
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome