Riding a pig / horse with a cape causes it to not behave as expected
The bug
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildly around to random locations on the player's body.
Code analysis
Code analysis / fix by [Mod] bemoty can be found in this comment.
Linked Issues
is duplicated by2
Created Issue:
Riding a pig with a cape causes it to violently spin around
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildy around to random locations on the player's body.
is duplicated by
Riding a pig / horse with a cape causes it to violently spin around
is duplicated by
relates to
relates to
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildy around to random locations on the player's body.
Code analysis / fix by [Mod] bemoty in this comment .
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildy around to random locations on the player's body.
Code analysis / fix by [Mod] bemoty in this comment.
The bug
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildly around to random locations on the player's body.
Code analysis
Code analysis / fix by [Mod] bemoty in this comment.
The bug
Whenever a player wearing a cape rides a pig moving at a velocity higher than stationary, the cape will glitch out and spin wildly around to random locations on the player's body.
Code analysis
Code analysis / fix by [Mod] bemoty can be found in this comment.
relates to
relates to
The following is based on a decompiled version of Minecraft 1.12 using MCP 9.40pre-1. (Also, can confirm for Minecraft version 1.12 and 1.12.1)
The method responsible for capes being rendered on players' backs is net.minecraft.client.renderer.entity.layers.LayerCape.doRenderLayer(). In this method, there are a lot of different values which calculate a cape's physics on every game tick. The only two values which are important in this case are float f2 and float f3. f2 is the vertical rotation of the cape which starts from the player's back at 0 (positive Y/positive Pitch). This value has already been clamped by a Mojangster using a simple if-statement, so it can't be lower than zero (negative Y/negative Pitch) and therefore can't glitch through the player character when moving backwards.
if (f2 < 0.0F)
{
f2 = 0.0F;
}
f3 is the horizontal rotation of the cape, starting from the center of the players' backs. This value decrements when moving to the right (negative X/negative Yaw) and increments when moving to the left (positive X/positive Yaw). To stop the cape from glitching into the player character or detach from its anchor point, those two values need to be clamped in the between two values where the cape doesn't glitch out. (This also fixes MC-5037)
public void doRenderLayer(...) { if (...) { if (...) { // ... float f2 = (float)(d0 * d3 + d2 * d4) * 100.0F; float f3 = (float)(d0 * d4 - d2 * d3) * 100.0F; // Clamping f2 and f3 ... f2 = MathHelper.clamp(f2, 0.0F, 150.0F); f3 = MathHelper.clamp(f3, -20.0F, 20.0F); float f4 = entitylivingbaseIn.prevCameraYaw + (entitylivingbaseIn.cameraYaw - entitylivingbaseIn.prevCameraYaw) * partialTicks; f1 = f1 + MathHelper.sin((entitylivingbaseIn.prevDistanceWalkedModified + (entitylivingbaseIn.distanceWalkedModified - entitylivingbaseIn.prevDistanceWalkedModified) * partialTicks) * 6.0F) * 32.0F * f4; if (entitylivingbaseIn.isSneaking()) { f1 += 25.0F; } // ... } } }
For f2 I used 0.0F as the minimum value so it doesn't glitch into the players body when the player's moving backwards (I basically just replaced the if-statement here) and 150.0F as the maximum value so it doesn't look like the cape extends from the player's head when the player's sprint-flying. After a few tests, I decided to use 20.0F and -20.0F as the bounds for f3 because it simply looked the best IMO. However, since this is only my opinion and therefore might not apply to everyone, please make sure to alter those values at your convenience.
This is how flying looks like with clamped values.
As always, this might not be the best solution for this issue but it might give one an idea of how it could be fixed. ![]()


confirmed
1.5 and 13w11a.
I have a Crowdin Translator cape and I can make a video of this.
Also happens with horses in 13w16a Snapshot.
confirmed for 14w32b
Behavior has slightly changed during the latest versions. On Singleplayer, riding with a pig seems to be working fine with a cape, with a horse, it makes the cape drift to the left. I am currently unable to test for Multiplayer, but this issue still exists to a certain extent.
Is this still a problem in Minecraft 1.11?
Confirmed cape drifting in 1.11.
Can confirm for 1.12 and 1.12.1.
Fixed for horses, not fixed for pigs (as of 17w50a)