Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
public class VelocityUtil {

public static short toLegacyVelocity(double value) {
return (short) Math.max(Short.MIN_VALUE, Math.min(Short.MAX_VALUE, (long) (value * 8000)));
// Round instead of truncating toward zero. The 1.21.9+ LP-vector encoding is lossy: 0.4 b/t
// decodes as 0.39998779, and (long)(value * 8000) floors that to 3199 instead of 3200. Rounding
// restores the intended legacy short and matches a native 1.8 server, which sends 0.4 directly
// as (int)(0.4 * 8000) = 3200.
return (short) Math.max(Short.MIN_VALUE, Math.min(Short.MAX_VALUE, Math.round(value * 8000)));
}

}