Skip to content

Fix blockAtEntityCursor returning null when yaw or pitch is 0 - #3970

Open
SirYadav1 wants to merge 1 commit into
PrismarineJS:masterfrom
SirYadav1:fix/blockAtEntityCursor-zero-yaw-pitch
Open

Fix blockAtEntityCursor returning null when yaw or pitch is 0#3970
SirYadav1 wants to merge 1 commit into
PrismarineJS:masterfrom
SirYadav1:fix/blockAtEntityCursor-zero-yaw-pitch

Conversation

@SirYadav1

Copy link
Copy Markdown

Fixes #3935

bot.blockAtEntityCursor() (and blockAtCursor) incorrectly returned null whenever the entity had yaw === 0 or pitch === 0, because the guard used truthiness checks (!entity.yaw / !entity.pitch). A value of 0 is a perfectly valid orientation (e.g. looking level = pitch 0, facing north = yaw 0), so the ray trace was being skipped.

Change

lib/plugins/ray_trace.js — replaced the truthiness guard with explicit null checks:

// before
if (!entity.position || !entity.height || !entity.pitch || !entity.yaw) return null
// after
if (entity.position == null || entity.height == null || entity.pitch == null || entity.yaw == null) return null

Test

Added blockAtEntityCursor handles zero yaw and pitch (#3935) to test/internalTest.js. It places a column of gold blocks in the cursor direction, sets yaw = 0 and pitch = 0, and asserts the block is returned. The test fails on the old code (returns null) and passes on the fix, across all tested versions (1.21.4 – 26.1).

Verification

Also verified against a live 1.21.11 Paper server (intel-node2.zyphron.cloud:20013): with the fix the ray cast is actually executed instead of early-returning.

…rineJS#3935)

The truthiness check (!entity.yaw / !entity.pitch) treated a
legitimate zero value as missing, causing the ray trace to be
skipped and the function to incorrectly return null.

Use null checks (== null) instead so yaw=0 / pitch=0 are valid.

Fixes PrismarineJS#3935
@SirYadav1
SirYadav1 force-pushed the fix/blockAtEntityCursor-zero-yaw-pitch branch from 88fbb85 to 3b88ad6 Compare August 18, 2026 16:53
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