The bug
Mobs with multiple states have their hitboxs shifted when they spawn (except for the first basic state).
How to reproduce
Press
F3
+B
to make hitboxes visibleUse 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:
and
Pufferfish:
Slime:
Code analysis
Code analysis by @unknown can be found in this comment.
Linked issues
is duplicated by 4
Attachments
Comments 17
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 }=)
Relates to MC-9568
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).
Can reproduce with