-
Bug
-
Resolution: Fixed
-
1.17.1, 1.18 Release Candidate 3, 1.18, 1.18.1 Release Candidate 2, 22w11a, 22w12a, 22w18a, 22w45a
-
None
-
Confirmed
-
Entities
The bug
The shield attack vector is normalized incorrectly.
This issue does not affect unmodded clients since the dot product is checked against 0. It could however be an issue in the future and also impedes modding.
Code analysis
In the LivingEntity class within the isDamageSourceBlocked(damageSource) method the attack angle is calculated as:
net.minecraft.world.entity.LivingEntity.java (1.18-rc3, Mojang mappings, variable renamings)
... if (!damageSource.isBypassArmor() && this.isBlocking() && !isPiercingArrow && (sourcePosition = damageSource.getSourcePosition()) != null) { Vec3 targetRotation = this.getViewVector(1.0f); Vec3 sourceToTarget = sourcePosition.vectorTo(this.position()).normalize(); sourceToTarget = new Vec3(sourceToTarget.x, 0.0, sourceToTarget.z); if (sourceToTarget.dot(targetRotation) < 0.0) { return true; } ...
The problem is that sourceToTarget is normalized before its y coordinate is set to zero, which means that sourceToTarget is no longer normalized for the dot product calculation which leads to incorrect results.