The bug
Lightning sometimes does damage multiple times, instead of only once (which would be the expected behavior).
To reproduce
Summon a zombie pigman
Summon a Lightning bolt nearby with
/summon minecraft:lightning_bolt
The pigman will sometimes take damage twice.
Code analysis
Based on 1.11 decompiled using MCP 9.35 rc1
Lightning bolts have two fields which are important for the following:
lightningState
: Initialized to 2boltLivingTime
: Initialized to a random integer between 1 and 3 (both inclusive)
Every time a lightning bolt is updated it does the following:
Reduce
lightningState
by 1If
lightningState
< 0If
boltLivingTime
: Set deadElse if
lightningState
< random integer between -9 and 0 (both inclusive)Reduce
boltLivingTime
by 1Set
lightningState
to 1
If
lightningState
>= 0: Deal damage to entities
This means a lightning bolt can try to deal damage to entities up to 8 times with the last strike being in the 35th tick after the lightning bolt was created. This allows it to deal 20 damage to a player which would kill him.
Linked issues
Attachments
Comments 21
Clarified the report:
This is probably caused by the fact that lightning tries to do damage every tick, and since mobs/players have a "damage immunity" of 1/2 second (when the mob turns red after taking damage), and the lightning lasted longer than a 1/2 second, the lightning damaged the mob again.
Could it just be a simple random double strike? I tried testing it and it seems if any when I do hear a rapid dmg given its definitely at random times not consistent. I mean lightning does strike multiple times sometimes in the same bolt. And the best I can repeatedly try and repo this is about 1 in 20ish strikes. typical mobs are only taking 4 strikes to die (thats 20 hearts) with the occasional 3rd hit this was done in water so there is no fire dot possible to conflict with the dmg given.
Could it just be a simple random double strike?
No. If you summon a lightning bolt, you are summoning one entity. It should not deal damage multiple times. It is however possible that the lightning bolt constantly deals damage for a set amount of time.
I think it's intentional. Lightning in real life sometimes strikes multiple times, and I think that minecraft lightning is working the same way.
Damage that was dealt to mobs does not get applied after the damage immunity is over. If the game can't apply it at that moment, it never applies it.