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

Coding error at net.minecraft.world.entity.Entity.resetPos()

    XMLWordPrintable

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 20w48a
    • 20w49a
    • None
    • Plausible
    • Entities
    • Important

    Description

      Code analysis:

      Since the minecraft team is adding support for changing the world height there are more methods calling for the minimum (and maximum) world height. At net.minecraft.world.entity.Entity.resetPos(), a 'for' is asking if a number 'y' is lower and higher than the minimum world height, that number increases:

       

          protected void resetPos() {
              if (this.level == null) {
                  return;
              }
              for (double y = this.getY(); y > (double)this.level.getMinBuildHeight() && y < (double)this.level.getMinBuildHeight(); y += 1.0) {
                  this.setPos(this.getX(), y, this.getZ());
                  if (this.level.noCollision(this)) {
                      break;
                  }
              }
              this.setDeltaMovement(Vec3.ZERO);
              this.xRot = 0.0f;
          }
      

      >This causes client-side bugs at the player's Y when logging in or respawning.

      The solution is easy, just change the 'less than' conditional to 'y < (double)this.level.getMaxBuildHeight()'

       

      After fixing, it would look like this:

       

           protected void resetPos() {
              if (this.level == null) {
                  return;
              }
              for (double y = this.getY(); y > (double)this.level.getMinBuildHeight() && y < (double)this.level.getMaxBuildHeight(); y += 1.0) {
                  this.setPos(this.getX(), y, this.getZ());
                  if (this.level.noCollision(this)) {
                      break;
                  }
              }
              this.setDeltaMovement(Vec3.ZERO);
              this.xRot = 0.0f;
          }
      

       

       

      Attachments

        Activity

          People

            panda4994 [Mojang] Panda
            ISRosillo14 Ismael Rosillo
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              CHK: