Detect lightning strikes

Detect lightning strikes - Strikes of Lightning in the Night Sky

I'm trying to add some custom mob conversions like those of villagers/witches and pigs/pigmen (but here it is a block that turns into an mob, not a mob to a mob). What I can't seem to figure out about this is how to detect whether that lightning hit the block or not.

Note: I would like to not use fire as an indicator, as someone could light the block on fire (unless fire from lightning has a data tag that I can use to distinguish it from flint and steel).



Best Answer

We cannot select LightningBolt in a target selector so we cannot detect all mobs around a lightning bolt. Instead we can detect all mobs that have a lightning bolt around them.

Setup:

/scoreboard objectives add Selector dummy
/scoreboard objectives add Initiated dummy
/scoreboard objectives add Marker dummy
/scoreboard objectives add Charged dummy
/scoreboard objectives add Change dummy
/scoreboard objectives add Kill dummy

Clock:

/scoreboard players set <Select Original Mob> Selector 1
/execute @e[score_Selector_min=1,score_Initiated=0] ~ ~ ~ summon Creeper ~ ~ ~ {CustomName:Marker,CustomNameVisible:0,Invulnerable:1,NoAI:1,Silent:1,PersistenceRequired:1}
/scoreboard players set @e[type=Creeper] Marker 1 {CustomName:Marker,CustomNameVisible:0,Invulnerable:1,NoAI:1,Silent:1,PersistenceRequired:1}
/scoreboard players set @e[score_Selector_min=1,score_Initiated=0] Initiated 1
/execute @e[score_Selector_min=1,score_Initiated=1] ~ ~ ~ tp @e[type=Creeper,r=1,c=1,score_Marker_min=1] @e[score_Selector_min=1,score_Initiate=1,r=0,c=1]
/scoreboard players set @e[type=Creeper,score_Marker_min=1] Charged 1 {CustomName:Marker,CustomNameVisible:0,Invulnerable:1,NoAI:1,Silent:1,PersistenceRequired:1,powered:1}
/execute @e[type=Creeper,score_Charged_min=1] ~ ~ ~ scoreboard players set @e[score_Selector_min=1,score_Initiate=1,r=1,c=1] Change 1
/scoreboard players set @e[type=Creeper,score_Marker_min=1] Kill 1
/execute @e[type=Creeper,score_Marker_min=1] ~ ~ ~ execute @e[score_Selector_min=1,score_Initiate=1,r=0] ~ ~ ~ scoreboard players set @e[type=Creeper,score_Marker_min=1] Kill 0
/tp @e[type=Creeper,score_Marker_min=1,score_Kill_min=1] ~ ~-600 ~
/scoreboard players set @e[score_Selector_min=1,score_Initiate=1] Initiate 0
/execute @e[score_Selector_min=1,score_Initiate=0] ~ ~ ~ execute @e[type=Creeper,r=1,c=1,score_Marker_min=1] ~ ~ ~ scoreboard players set @e[score_Selector_min=1,score_Initiate=0,r=0,c=1] Initiate 1
<Run command on entities with Change score of 1>
  1. Original Mobs Selected
  2. Creeper summoned on non-Initiated Selected mobs
  3. Mark the summoned Creeper
  4. Set the non-Initiated mobs to Initiated
  5. Tp the Creeper to the corresponding mob
  6. Mark Charged Creepers
  7. Mark Mobs that are selected, initiated, and have a charged creeper near them
  8. Reset kill score for all creepers
  9. Set kill score of all creepers that have a valid mob near them to 0
  10. Discard the remaining Creepers
  11. Reset Initiate score
  12. Set Initiate Score of all valid mobs that have a valid creeper near them to 1
  13. Run your command on the mobs marked with Change to swap the mobs.



Pictures about "Detect lightning strikes"

Detect lightning strikes - Free stock photo of abstract, art, background
Detect lightning strikes - Photo of Thunderstorm
Detect lightning strikes - Photo of Lightning





How Storms Are Tracked (DIY Lightning Detector Hack)




More answers regarding detect lightning strikes

Answer 2

Well, I guess your thing could work but I just use this:

/execute @e[type=lightning_bolt, r=100] 
/execute @e[type=lightning_bolt:1,charged:false]~ ~ ~ detect ~ ~ ~ minecraft:grass 

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Gerhard, Heorhii Heorhiichuk, Rodrigo Souza, Philippe Donn