4

I was testing out this really fun command:

/execute at @e[type=arrow] run summon lightning_bolt.

It was really fun, summoning an entire line of lightning bolts, one after another, but what if I would only like to have the lightning strike after the arrow has hit something (like a block, not a mob), and I would only want lightning to strike an x amount of times.

There is this code that looks appealing, but I don't know how to use it.

/testfor @e[type=Arrow] {inGround:1b,player:1b}

Is there a way to do this? For example, I were to shoot an arrow, and lightning were to NOT be summoned yet, and when the arrow hits a block/player, I would want it to summon lightning 5 times, and make the arrow disappear, how would I write it in a command block/chain of command blocks?

Also, preferably, I would like to have only the arrows shot from a bow named (let's say it's named "text"), to be affected by this command. So that's another problem I have to deal with.

What I would also need it the arrangement of the command blocks, like which is facing which, and such and such.

The closest article I can find about this is this: How do I make a Lightning Bow in vanilla Minecraft?. But here's the thing, the answer just lists out a bunch of commands, doesn't really say the configuration of the command blocks.

Thanks for helping me, (if you did)!

(1.17.1 or 1.16.5)

1
+50

After reading @circusbaby23's answer, I decided to try it out myself and extend it to do multiple strikes with multiple arrows.

Fist of all, the scoreboard setup lacked a word, it should be

/scoreboard objectives add UseBow minecraft.used:bow

We'll then declare some other dummy objectives:

/scoreboard objectives add Timer dummy
/scoreboard objectives add Strike dummy

To support multiple arrows, I'm modifying the second chain command block to remove a point instead of setting the score to 0. This might have adverse effects I'm not aware of, so test this!

execute at @e[tag=lightningarrow,nbt={inGround:1b}] run scoreboard players remove @a UseBow 1

Now for the fun lightning stuff. Instead of summoning a lightning, we'll summon an invisible and invincible armor stand by modifying the third chain command block:

execute as @a[scores={UseBow=1..}] at @e[type=arrow,tag=lightningarrow,nbt={inGround:1b},limit=1] run summon minecraft:armor_stand ~ ~ ~ {Tags:["lightning"],Invulnerable:1b,Invisible:1b}

The rest is based off the idea that we spawn the lightning based on a timer and count how many times a lightning has been spawned. Then we kill the stand after a certain number of strikes. The following is a seperate chain of command blocks, starting with a repeating block leading into chain blocks.

[r] scoreboard players add @e[tag=lightning] Timer 1
 v
[c] execute as @e[tag=lightning,scores={Timer=1}] at @s run summon minecraft:lightning_bolt
 v
[c] execute as @e[tag=lightning,scores={Timer=1}] at @s run scoreboard players add @s Strike 1
 v
[c] execute as @e[tag=lightning,scores={Timer=5}] at @s run scoreboard players set @s Timer 0
 v
[c] kill @e[tag=lightning,scores={Strike=5}]

The order of these is probably suboptimal, perhaps someone else can improve on that. I'm also certain that you can link these two chains into one, but I'm not sure how. An issue with this solution is that if there's a "normal" arrow stuck in the ground, getting close to it with the lightning bow equipped starts the lightning. You'd need to kill these as well.

3
  • ??? Detect when an arrow is shot from a specific bow, wait until the it strikes a block and strike that location a number of times. What part am I missing? This is supposed to be an extension of @circusbaby23's answer, so I omitted the commands I didn't change. Oct 30 '21 at 19:26
  • I might have messed it up, but it seemed like it worked the first time, then it didn't work anymore
    – AlexJaynMF
    Oct 31 '21 at 0:37
  • Nevermind, it worked, great job!
    – AlexJaynMF
    Oct 31 '21 at 0:48
1

(Chain, unconditional, always active)

Kill @e[type=arrow,nbt={inGround:1b}] 

well get rid of the arrow.

(Repeat, unconditional, always active)

execute at @e[type=arrow,nbt={inGround:1b}] run summon minecraft:lightning_bolt 

well summon the lightning.

You can also add/replace player:1b

2
  • Great! That solves part of it, but how would one detect when to kill the arrow? As I said, what if I wanted to strike lightning 5 times, instead of just 1? I also still have the problem of having only arrows fired from a particular named bow?
    – AlexJaynMF
    Oct 26 '21 at 20:59
  • Tell me if it helped!! Oct 27 '21 at 13:08
1

This may help more

(in chat)

/scoreboard objectives UseBow minecraft.used:bow

(impulse)

give @p bow{CustomModelData:103,display:{Name:"[{\"text\":\"Lightning\",\"color\":\"yellow\",\"italic\":false},{\"text\":\" Bow\",\"color\":\"green\",\"italic\":false}]",Lore:["{\"text\":\"by JohnPaulInso\",\"color\":\"gray\",\"italic\":false}"]},Unbreakable:1,HideFlags:7}

(chain)

kill @e[tag=lightningarrow,nbt={inGround:1b}]

(chain)

execute at @e[tag=lightningarrow,nbt={inGround:1b}] run scoreboard players set @a UseBow 0

(chain)

execute as @a[scores={UseBow=1..}] at @e[type=arrow,tag=lightningarrow,nbt={inGround:1b},limit=1] run summon minecraft:lightning_bolt

(repeat)

execute at @a[scores={UseBow=1..},nbt={SelectedItem:{id:"minecraft:bow",Count:1b,tag:{CustomModelData:103,display:{Name:"[{\"text\":\"Lightning\",\"color\":\"yellow\",\"italic\":false},{\"text\":\" Bow\",\"color\":\"green\",\"italic\":false}]"}}}}] run data merge entity @e[type=arrow,limit=1,sort=nearest,distance=..2] {Tags:["lightningarrow"]}

This should solve all the problems but multiple lightning bolts.

2
  • 3
    For the future, you can always edit your previous answer to add further details, there's actually no need to post more than one.
    – pinckerman
    Oct 28 '21 at 12:57
  • Next time credit the original owner?
    – AlexJaynMF
    Oct 31 '21 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.