mojira.dev
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.

Linked issues

Attachments

Comments 21

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), the lightning damaged the mob right after the immunity ended.

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.

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.

11 more comments

Can confirm in 1.18.1.

Can confirm in 1.18.2.

Can confirm in 1.19.

Can confirm in 1.19.2.

Affects 1.20.1 Release Candidate 1

Sonicwave

(Unassigned)

Confirmed

Platform

Normal

Entities

damage, lightning, lightning_bolt

Minecraft 1.7.10, Minecraft 1.8, Minecraft 1.8.1-pre2, Minecraft 1.8.1-pre5, Minecraft 1.8.1, ..., 23w45a, 1.20.3 Release Candidate 1, 24w03b, 1.21, 1.21.4 Pre-Release 1

Retrieved