Punching with a cast fishing rod in the off-hand detaches fishing line from rod
Open
38
The bug
When you punch the air with an item in the main hand and a cast fishing rod in the off-hand, the main hand (item) makes a punch animation as expected, but the off-hand (item) shouldn't move. As the rod itself remains still as expected, the cast fishing line of the rod in the off-hand moves strangely up and down the length of the rod.
It appears as if the fishing line thinks its rod is being used to punch, but it isn't as it is in the off-hand. The fishing line makes a similar movement to as if the rod were indeed in the punching hand. In the attached image you can see the the fishing line has moved down the rod while my main hand is punching something (and is at this point because of that just outside my view).
How to reproduce:
Put any fishing rod in the off-hand
Right-click to cast the line
Left-click to punch in the air ❌ notice how the off-hand and the rod in it don't animate, but its fishing line does
Code analysis
Code analysis by @unknown can be found in this comment.
At net.minecraft.client.render.entity.FishingBobberEntityRenderer.render() (Based on 21w05b yarn mappings) The fishing bobber gets the hand that is currently holding a fishing rod in it. It then uses the main hand's swing progress to determine the fishing line's animation when punching, which is currently used as part of the animation regardless of which hand is holding the fishing rod.
int j = lv.getMainArm() == Arm.RIGHT ? 1 : -1;
ItemStack lv6 = lv.getMainHandStack();
if (!lv6.isOf(Items.FISHING_ROD)) {
j = -j;
}
float h = lv.getHandSwingProgress(g);
float k = MathHelper.sin(MathHelper.sqrt(h) * (float)Math.PI);
This could be fixed by checking if the hand with the fishing rod is the same as the main hand, and if not then setting h to 0:
int j = lv.getMainArm() == Arm.RIGHT ? 1 : -1;
int j2 = j;
ItemStack lv6 = lv.getMainHandStack();
if (!lv6.isOf(Items.FISHING_ROD)) {
j = -j;
}
float h = j == j2 ? lv.getHandSwingProgress(g) : 0;
float k = MathHelper.sin(MathHelper.sqrt(h) * (float)Math.PI);
Confirmde for 17w17a