The bug
While swimming in lava you deal always critical hits unless you sprint or touch the ground.
Code analysis
Based on 1.11.2 decompiled using MCP 9.35 rc1
The method net.minecraft.entity.player.EntityPlayer.attackTargetEntityWithCurrentItem(Entity)
only tests if the player is in water and because lava does not reset the fall distance you can always deal critical hits.
Additional code analysis by @unknown can be found in this comment.
Attachments
Comments 14
I can also confirm this behavior in 1.18.1.
Here's a code analysis of this issue that includes a bit more detail. (I'm aware that a code analysis has already been done above, but I'd just like to provide some additional information if that's okay and to make it crystal clear as to why this problem is occurring). The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn.
Code Analysis:
net.minecraft.world.entity.player.Player.java
public abstract class Player extends LivingEntity {
...
public void attack(Entity p_36347_) {
...
boolean flag2 = flag && this.fallDistance > 0.0F && !this.onGround && !this.onClimbable() && !this.isInWater() && !this.hasEffect(MobEffects.BLINDNESS) && !this.isPassenger() && p_36347_ instanceof LivingEntity;
flag2 = flag2 && !this.isSprinting();
if (flag2) {
f *= 1.5F;
}
...
//flag = Full weapon cooldown
//flag2 = Critical attack
In order to perform a critical attack, certain criteria must be met as shown in the above class. The criteria are as follows:
The player must be falling.
The player must not be on the ground.
The player must not be on any climbable blocks.
The player must not be in water.
The player must not have the blindness effect.
The player must not be riding an entity.
The player must not be sprinting.
If we look at the above code, we can see that no checks are carried out to see whether or not the player is in lava, and since lava doesn't reset your fall distance, you are constantly able to perform critical attacks when moving downwards and inside of this liquid.
Can confirm for MC 1.12.1.