mojira.dev
MC-268414

Low gravity causes entities to float mid-air and forces OnGround to be false

Setting the generic.gravity attribute of an entity to a value <= 0.0030612244302160993 (~ 3/980) will make them unable to fall without downwards momentum to start with and forces their OnGround tag to be false, even when the entity is on the ground. To players, this means that you can't jump and have inertia similarly to flying in creative mode.

Steps to reproduce:

  1. Set your generic.gravity attribute to a value below 0.0030612244302160993, e.g. 0.003:

    /attribute @s minecraft:generic.gravity base set 0.003
  2. Go onto the ground and check your OnGround tag:

    /data get entity @s OnGround
  3. Try to move around and jump

  4. Go into creative mode and fly into the air and then stop flying.

Expected behavior:

  • The OnGround tag should be true (1b).

  • You should be able to move around without inertia and jump.

  • You should be able to fall while in the air.

Actual behavior:

  • The OnGround tag is false (0b).

  • You feel a lot of inertia while moving, similarly to flying in creative mode

  • You stay in the air and can't fall down.

Code analysis:

net.minecraft.world.entity.LivingEntity

public void aiStep() {
    // ...
    if (!isEffectiveAi()) {
        setDeltaMovement(getDeltaMovement().scale(0.98)); // Line 2713
    }
    // ...
    if (Math.abs(motion.x) < 0.003) { // Line 2724
        xMotion = 0;
    }
    if (Math.abs(motion.y) < 0.003) {
        yMotion = 0;
    }
    if (Math.abs(motion.z) < 0.003) {
        zMotion = 0;
    }
    // ...
}

The motion of the entity is first multiplied by 0.98 and if the result in a particular direction turns out to be less than 0.003, the motion in that direction is removed. If this happens to be the negative y direction, the falling gets negated.

Potential fix:

Disable the cut-off for the y direction if the entity has gravity:

if (Math.abs(motion.y) < 0.003 && getGravity() == 0) {
    yMotion = 0;
}

Linked issues

Comments 0

No comments.

Rob23

(Unassigned)

Confirmed

Commands

24w06a

Retrieved