Can I run several commands after /execute, instead of just one?



  • I want to create a Minecraft datapack in which I can shoot an arrow and, when it reaches its target, summons a lightning bolt. Currently, I have this:

    execute at @e[type=Arrow] unless block ~ ~-1 ~ air run summon minecraft: lightning_bolt ~ ~ ~
    

    …but this infinitely summons lightning. I would like to make it so that the arrow is killed after the lightning is summoned, but I don't know how to run multiple commands in /execute at the same time.



  • While it isn't possible to use execute for multiple commands at once, you can create a second command to kill the arrow with a very similar execute command put into a chain command block.

    execute at @e[type=arrow] unless block ~ ~-1 ~ air run kill @e[type=arrow]
    

    It also works in a second repeating command block. For some reason though it depends in what order you activate the commands in a repeating command block, that being activating the summon loop then activating the kill loop, in that order, works, same if you power them at once. I don't know if data packs activate commands in order, or all at once, so just watch out for that.

    Also do remember that the command you made and this solution here is going to make every arrow strike, kill every arrow entity too. If you want to only make one bow shoot arrows and make them summon lightning you are going to require a different solution.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2