From 3b88ad606f1fcad3e3633ce732f714acb8fae016 Mon Sep 17 00:00:00 2001 From: SirYadav1 Date: Tue, 18 Aug 2026 22:23:12 +0530 Subject: [PATCH] Fix blockAtEntityCursor returning null when yaw or pitch is 0 (#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 #3935 --- lib/plugins/ray_trace.js | 2 +- test/internalTest.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/plugins/ray_trace.js b/lib/plugins/ray_trace.js index e45c83f019..dff155bfd9 100644 --- a/lib/plugins/ray_trace.js +++ b/lib/plugins/ray_trace.js @@ -55,7 +55,7 @@ module.exports = (bot) => { } bot.blockAtEntityCursor = (entity = bot.entity, maxDistance = 256, matcher = null) => { - if (!entity.position || !entity.height || !entity.pitch || !entity.yaw) return null + if (entity.position == null || entity.height == null || entity.pitch == null || entity.yaw == null) return null const { position, height, pitch, yaw } = entity const eyePosition = position.offset(0, height, 0) diff --git a/test/internalTest.js b/test/internalTest.js index 2c091bec31..8c622855b3 100644 --- a/test/internalTest.js +++ b/test/internalTest.js @@ -1312,5 +1312,33 @@ for (const supportedVersion of mineflayer.testedVersions) { }) }) }) + it('blockAtEntityCursor handles zero yaw and pitch (#3935)', (done) => { + // Place a vertical column of gold blocks in the -Z direction from the bot, + // so a level (pitch=0) ray along yaw=0 is guaranteed to hit one regardless of eye height. + const goldId = bot.registry.blocksByName.gold_block.id + server.on('playerJoin', (client) => { + client.write('login', bot.test.generateLoginPacket()) + const chunk = bot.test.buildChunk() + chunk.setBlockType(vec3(0, 65, 0), goldId) + chunk.setBlockType(vec3(0, 66, 0), goldId) + chunk.setBlockType(vec3(0, 67, 0), goldId) + client.write('map_chunk', generateChunkPacket(chunk)) + }) + bot.on('chunkColumnLoad', () => { + // Position the bot at (0.5, 65, 5.5) looking straight north (yaw=0) and level (pitch=0) + bot.entity.position = vec3(0.5, 65, 5.5) + bot.entity.height = 1.62 + bot.entity.yaw = 0 + bot.entity.pitch = 0 + const block = bot.blockAtEntityCursor(bot.entity, 256) + try { + assert.ok(block, 'blockAtEntityCursor must not return null when yaw=0 and pitch=0') + assert.strictEqual(block.type, goldId, 'should hit the gold block in the cursor') + done() + } catch (err) { + done(err) + } + }) + }) }) }