mojira.dev
MC-103313

Hitbox of slime and magma cube is offset for some seconds

The bug

Mobs with multiple states have their hitboxs shifted when they spawn (except for the first basic state).

How to reproduce

  1. Press F3 + B to make hitboxes visible

  2. Use the following command

    /summon slime ~ ~ ~ {NoAI:1b,NoGravity:1b,Size:3}

    → The hitbox starts at the back of the baby animal, but then jumps into the middle.

Examples

  • Magma Cube:

[media]
  • and

[media]
  • Pufferfish:

[media]
  • Slime:

[media]

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 17

Can reproduce with

/summon Wolf ~ ~3 ~ {Age:-2000}

Please link to this comment in the description

The following is based on a decompiled version of Minecraft 1.10 using MCP 9.30.

The reason for this is that the method net.minecraft.entity.Entity.setSize(float, float) sets the bounding box based on the min values of the current bounding box. This means if the entity becomes smaller, its hitbox is offset in -x and -z direction; if it becomes larger its hitbox is offset in +x and +z direction. The case in which an entity becomes larger is handled by moving the entity in the according direction, however in case it becomes smaller the hitbox remains offset.

I would suggest centering the hitbox on the current position of the entity instead.

Suggested change (MCP 9.30, Minecraft 1.10)

protected void setSize(float width, float height)
{
    if (width != this.width || height != this.height)
    {
        // Replaced this
        //float f = this.width;
        //this.width = width;
        //this.height = height;
        //AxisAlignedBB axisalignedbb = this.getEntityBoundingBox();
        //this.setEntityBoundingBox(new AxisAlignedBB(axisalignedbb.minX, axisalignedbb.minY, axisalignedbb.minZ, axisalignedbb.minX + (double)this.width, axisalignedbb.minY + (double)this.height, axisalignedbb.minZ + (double)this.width));
        //
        //if (this.width > f && !this.firstUpdate && !this.worldObj.isRemote)
        //{
        //    this.moveEntity((double)(f - this.width), 0.0D, (double)(f - this.width));
        //}
         this.width = width;
         this.height = height;
         double halfWidth = width / 2d;

         this.setEntityBoundingBox(new AxisAlignedBB(this.posX - halfWidth, this.posY, this.posZ - halfWidth, this.posX + halfWidth, this.posY + height, this.posZ + halfWidth));
    }
}

Note: One problem which existed before and will still exist is that in case the entity becomes larger its hitbox might afterwards intersect with blocks allowing it to clip through them.

Confirmed for 16w41a: When baby mobs (e.g. Villagers) are in a confined space (e.g. 1x1 tube) they can gllitch out of it as soon as they grow up.

Thanks for the link to the correct bugpost, @unknown }=)

Related. Apparently the same thing happens for one tick after growing up.

7 more comments

Still in 1.14.1 Release

Still in 1.14.2 Pre-Release 1 and 1.14.2 Pre-Release 2

Fixed according to @unknown.

No, this is not fixed. The issue can be seen clearly following the reproduction steps. Nothing has changed here.

I found the issue why I couldn't reproduce it before: Apparently their hitbox now corrects itself as soon as they move. And because they normally start jumping pretty quickly after spawning, it can only be seen properly with NoAI.

Also, they can not suffocate because of this, even though it's not just a visual issue (persists after reloading).

FaRo1

Erik Broes

Confirmed

Entities, Hitboxes

baby, hitbox, magma_cube, slime

Minecraft 1.10, Minecraft 1.10.2, Minecraft 16w32a, Minecraft 16w32b, Minecraft 16w33a, ..., Minecraft 1.14.4 Pre-Release 3, Minecraft 1.14.4 Pre-Release 4, Minecraft 1.14.4 Pre-Release 5, Minecraft 1.14.4 Pre-Release 6, 1.14.4

Minecraft 16w43a, 19w34a

Retrieved