mojira.dev
MC-199483

Players that are forced to sneak in small areas receive damage when stepping on magma blocks

The Bug:

Players that are forced to sneak in small areas receive damage when stepping on magma blocks.

Steps to Reproduce:

  1. Build the setup as shown in the attachment below.

[media]
  1. While sneaking and holding the sneak key, stand on top of the magma block.

  2. Stop holding the sneak key.

  3. Take note as to whether or not players that are forced to sneak in small areas receive damage when stepping on magma blocks.

Observed Behavior:

Players that are forced to sneak in small areas receive damage when stepping on magma blocks.

Expected Behavior:

Players that are forced to sneak in small areas would not receive damage when stepping on magma blocks.

Code Analysis:

Code analysis by @unknown can be found below.

The following is based on a decompiled version of Minecraft 1.19.2 using MCP-Reborn.

net.minecraft.world.level.block.MagmaBlock.java

public class MagmaBlock extends Block {
   ...
   public void stepOn(Level level, BlockPos blockPos, BlockState blockState, Entity entity) {
      if (!entity.isSteppingCarefully() && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity)entity)) {
         entity.hurt(DamageSource.HOT_FLOOR, 1.0F);
      }
      super.stepOn(level, blockPos, blockState, entity);
   }
   ...

If we look at the above class, we can see that in order for the player to receive damage from stepping on magma blocks, the isSteppingCarefully() boolean must return false. This boolean returns true if the shift key is held down or is toggled and returns false if the shift key isn't held down or isn't toggled. The game doesn't check if the player is being forced to sneak in small areas before allowing them to receive damage from stepping on magma blocks, therefore resulting in this problem occurring.

Fix:

Simply altering the existing "if" statement within this piece of code to check if the player is being forced to sneak in small areas before allowing them to receive damage from stepping on magma blocks will resolve this problem. We can achieve this through the use of the isCrouching() boolean.

Current "if" statement:

if (!entity.isSteppingCarefully() && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity)entity))

Fixed "if" statement:

if (!entity.isCrouching() && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity)entity))

Linked issues

Attachments

Comments 9

[Mod] markderickson

Hi there!

I can confirm.

FACS01

By the resolution of MC-195636 and MC-151547 I would say Working as Intended.

But I would like all of the tickets to be fixed really.

A Duck

You are not really sneaking though, you can still sneak. This position has no sneaking properties.

Avoma

Can confirm in 1.17.

Avoma

Can confirm in 1.17.1.

Avoma

Can confirm in 1.18.

Avoma

Can confirm in 1.18.1.

Avoma

I can confirm this behavior in 1.18.2 and 1.19 Pre-release 3. Here's a code analysis regarding this issue.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.19 Pre-release 3 using Mojang mappings.

net.minecraft.world.level.block.MagmaBlock.java

public class MagmaBlock extends Block {
   ...
   public void stepOn(Level level, BlockPos blockPos, BlockState blockState, Entity entity) {
      if (!entity.isSteppingCarefully() && entity instanceof LivingEntity && !EnchantmentHelper.hasFrostWalker((LivingEntity)entity)) {
         entity.hurt(DamageSource.HOT_FLOOR, 1.0f);
      }
      super.stepOn(level, blockPos, blockState, entity);
   }
   ...

If we look at the above class, we can see that in order for the player to receive damage from stepping on magma blocks, the isSteppingCarefully() boolean must be false. This boolean returns true if the shift key is held down and returns false if the shift key isn't held down. Because of this, if the player is in the sneaking state but isn't holding down the shift key, they will receive damage from magma blocks.

Avoma

Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂

[media][media]

bugsbugsbugs

Avoma

(Unassigned)

Community Consensus

Player

magma_block

1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 1, 1.16.4 Pre-release 2, ..., 1.20.1, 1.21, 1.21.3, 1.21.4, 25w08a

Retrieved