Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-268414

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • None
    • 24w06a
    • None
    • Confirmed
    • Commands

      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;
      }
      

            Unassigned Unassigned
            Rob23 Rob23
            Votes:
            5 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: