Mojira Archive
MC-72028

Lightning occasionally deals damage twice

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 2
  • boltLivingTime: Initialized to a random integer between 1 and 3 (both inclusive)

Every time a lightning bolt is updated it does the following:

  1. Reduce lightningState by 1
  2. If lightningState < 0
    1. If boltLivingTime: Set dead
    2. Else if lightningState < random integer between -9 and 0 (both inclusive)
      1. Reduce boltLivingTime by 1
      2. Set lightningState to 1
  3. 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.