10

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).

  • 1
    You might be able to use something along the lines of /execute @a[type=LightningBolt] ~ ~ ~ detect ~ ~-1 ~ minecraft:<blockname> and have that output to another command block. – Mutantoe Aug 6 '15 at 18:59
  • @Mutantoe - Although you can /summon them, I don't think lightningbolt is a selectable entity. – SirBenet Aug 6 '15 at 22:15
  • @colorfusion yes, I tried "/execute @e[type=LightningBolt] say hi" on a 20gHz fill clock but when I summon a bolt there is no message in chat or output in the command block. – Judge2020 Aug 6 '15 at 22:57
  • How many individually blocks are you wanting to test for lightning strikes? Is it just a handful, or a more? – SirBenet Aug 7 '15 at 10:38
  • @colorfusion i'd like to target every block of one type (ex. cobblestone). As modDL showed, you can have an invisible creeper where you want and check to see if that creeper is charged or not on a fill clock, then run the commands based on that charged creeper. – Judge2020 Aug 8 '15 at 14:57
2

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.
| improve this answer | |
  • While this is a great idea on how to detect a mob struck by lightning, it does not detect blocks being struck. – MrLemon Aug 7 '15 at 8:18
  • I indicated that I was looking for a block being struck, but the creeper method seems like it could work. Is there a way to summon an invisible and noai one above all cobblestone in the world? – Judge2020 Aug 7 '15 at 23:04
0

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 
| improve this answer | |

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.