mojira.dev
MC-101297

Distance swum statistic doesn't increment in lava

The bug

The swimming statistic only counts swimming in water, not lava. This is annoying for adventure maps, and also means that hunger will never decrease while the player is swimming or walking in lava.

Code analysis

Code analysis by @unknown:

The following is based on a decompiled version of MC 1.12 using MCP 9.40pre-1.

The issue is that in the method net.minecraft.entity.player.EntityPlayer.addMovementStat() the if-statement for incrementing the SWIM_ONE_CM stat only checks if the player is in water and therefore doesn't increment the stat when the player is in lava. Thus a very, very simple fix is to add a check if the player is in lava (EntityPlayer.isInLava()) to the if-statement using the OR operator (||).

else if (this.isInWater() || this.isInLava())
{
    int j = Math.round(MathHelper.sqrt(p_71000_1_ * p_71000_1_ + p_71000_5_ * p_71000_5_) * 100.0F);

    if (j > 0)
    {
        this.addStat(StatList.SWIM_ONE_CM, j);
        this.addExhaustion(0.01F * (float)j * 0.01F);
    }
}

Linked issues

Attachments

Comments 10

Can confirm for MC 1.12.1.

This is also the case for stat.diveOneCm. Should we add that to this bug report instead of making a new one?

Confirmed for Minecraft 1.12.2 and 17w46a.

Added the code analysis to the description of the report to allow helpers to edit it, if necessary.

Can confirm for 1.13.1-pre2.

Can confirm for 1.13.1.

Confirmed for 1.13.2-pre1.

Confirmed in 20w15a, plz fix for nether update! Bemoty says it's really easy 🙂

Can confirm in 20w49a.

This report should be changed to talk about minecraft.custom:minecraft.walkon_water_one_cm instead of minecraft.custom:minecraft.swim_one_cm, the swimming stat only increases in the "new" 1.14 swimming mechanic; distance swum became distance walked in/under water instead.

Can confirm in 21w05b.

KingSupernova

(Unassigned)

Confirmed

Statistics

stat.swimOneCm, statistics

Minecraft 1.9.3 Pre-Release 1, Minecraft 1.10.2, Minecraft 16w43a, Minecraft 1.12, Minecraft 1.12.1, ..., 1.15.2, 20w15a, 20w49a, 21w05b, 1.21.1

Retrieved