The Bug:
If you crouch while holding a loaded crossbow, the arms follow the position of the crouching/sneaking player. It also happens when a player is loading a crossbow. It also affects bows.
Steps to Reproduce:
Have a loaded crossbow
Crouch/sneak
→ ❌ The player arms follow the position of crouching while holding a loaded crossbow
Code Analysis:
Code analysis by @unknown can be found in this comment.
Comparison:
[media]Linked issues
relates to 2
Attachments
Comments 12
Fix:
The following is based on a decompiled version of Minecraft 1.20.1 using MCP-Reborn.
To fix this, we will have to determine if the LivingEntity
is crouching. If so, we will add 0.35157994
to the x and y rot.
net.minecraft.client.model.AnimationUtils.java // Updated
@OnlyIn(Dist.CLIENT)
public class AnimationUtils {
public static void animateCrossbowHold(ModelPart p_102098_, ModelPart p_102099_, ModelPart p_102100_, LivingEntity livingEntity, boolean p_102101_) {
ModelPart modelpart = p_102101_ ? p_102098_ : p_102099_;
ModelPart modelpart1 = p_102101_ ? p_102099_ : p_102098_;
modelpart.yRot = (p_102101_ ? -0.3 F : 0.3 F) + p_102100_.yRot;
modelpart1.yRot = (p_102101_ ? 0.6 F : -0.6 F) + p_102100_.yRot;
modelpart.xRot = (-(float) Math.PI / 2 F) + p_102100_.xRot + 0.1 F - (livingEntity.isCrouching() ? 0.3517994 F : 0.0 F);
modelpart1.xRot = -1.5 F + p_102100_.xRot - (livingEntity.isCrouching() ? 0.3517994 F : 0.0 F);
}
public static void animateCrossbowCharge(ModelPart p_102087_, ModelPart p_102088_, LivingEntity p_102089_, boolean p_102090_) {
ModelPart modelpart = p_102090_ ? p_102087_ : p_102088_;
ModelPart modelpart1 = p_102090_ ? p_102088_ : p_102087_;
modelpart.yRot = p_102090_ ? -0.8 F : 0.8 F;
modelpart.xRot = -0.97079635 F - (p_102089_.isCrouching() ? 0.3517994 F : 0.0 F);
modelpart1.xRot = modelpart.xRot - (p_102089_.isCrouching() ? 0.3517994 F : 0.0 F);
float f = (float) CrossbowItem.getChargeDuration(p_102089_.getUseItem());
float f1 = Mth.clamp((float) p_102089_.getTicksUsingItem(), 0.0 F, f);
float f2 = f1 / f;
modelpart1.yRot = Mth.lerp(f2, 0.4 F, 0.85 F) * (float)(p_102090_ ? 1 : -1);
modelpart1.xRot = Mth.lerp(f2, modelpart1.xRot, (-(float) Math.PI / 2 F));
}
}
Since we added another parameter to the method, we must update any references to this method.
As an example:
net.minecraft.client.model.HumanoidModel.java // Updated
AnimationUtils.animateCrossbowHold(this.rightArm, this.leftArm, this.head, livingEntity, true);
There if you were to crouch whilst holding or charging up a crossbow, the elevation should remain consistent.
Yet again, we have another underlying issue of the opposite hand not connecting when looking up or down.
Can confirm in 20w48a.