Skip to content

fix(ray_trace): don't treat zero yaw/pitch as missing in blockAtEntityCursor - #3965

Open
AnonymoDGH wants to merge 1 commit into
PrismarineJS:masterfrom
AnonymoDGH:fix/block-at-entity-cursor-zero
Open

fix(ray_trace): don't treat zero yaw/pitch as missing in blockAtEntityCursor#3965
AnonymoDGH wants to merge 1 commit into
PrismarineJS:masterfrom
AnonymoDGH:fix/block-at-entity-cursor-zero

Conversation

@AnonymoDGH

Copy link
Copy Markdown

Fixes #3935

Problem

bot.blockAtEntityCursor() validated the entity orientation with truthiness checks:

if (!entity.position || !entity.height || !entity.pitch || !entity.yaw) return null

Because 0 is falsy in JavaScript, a perfectly valid orientation with yaw === 0 or pitch === 0 (facing due south / looking level) was treated as if the value were missing, and the ray trace was skipped — the function returned null even though the entity was correctly oriented.

Fix

Validate with Number.isFinite instead of truthiness, so only genuinely missing (null/undefined) or non-finite (NaN/Infinity) values are rejected, while 0 is accepted:

if (!entity.position) return null
const { position, height, pitch, yaw } = entity
if (!Number.isFinite(height) || !Number.isFinite(pitch) || !Number.isFinite(yaw)) return null

This is equivalent to the issue's proposed two-part isMissing || isInvalid check but in a single condition, and it keeps the existing behavior for all invalid inputs.

Verified

  • Standalone check of the new validation across 11 cases: yaw=0, pitch=0, yaw=0 && pitch=0, normal values, and height=0 all proceed to the ray trace; missing height/pitch/yaw, NaN, Infinity, and missing position all return null.
  • Added a regression test to test/externalTests/rayTrace.js (which runs in CI): it builds a small stone wall ahead at eye level, sets yaw = 0 and pitch = 0, and asserts blockAtEntityCursor finds the wall instead of returning null.
  • standard lint passes on both changed files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blockAtEntityCursor() incorrectly returns null if either yaw or pitch are 0

1 participant