From 7199acf149dd08e092849b499a4584589c93bbe3 Mon Sep 17 00:00:00 2001 From: roberts Date: Mon, 30 Mar 2026 15:14:19 -0500 Subject: [PATCH] Fix attack crash: provide empty item when hand is empty The inventory_transaction packet for attacks includes held_item. When Doug has nothing in his hand, bot.heldItem is null, causing "Cannot read properties of null (reading 'network_id')". Fix: provide a proper empty item object with network_id=0 when heldItem is null. Attacks now send successfully. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../lib/mineflayer/lib/bedrockPlugins/entities.mts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bridge/lib/mineflayer/lib/bedrockPlugins/entities.mts b/bridge/lib/mineflayer/lib/bedrockPlugins/entities.mts index 0b3933a..f097e9e 100644 --- a/bridge/lib/mineflayer/lib/bedrockPlugins/entities.mts +++ b/bridge/lib/mineflayer/lib/bedrockPlugins/entities.mts @@ -523,6 +523,16 @@ export default function inject(bot: BedrockBot) { } function itemUseOnEntity(target: any, type: number) { const typeStr = ['attack', 'interact'][type]; + // Provide empty item if hand is empty to avoid serialization crash + const heldItem = bot.heldItem || { + network_id: 0, + count: 0, + metadata: 0, + has_stack_id: false, + stack_id: 0, + block_runtime_id: 0, + extra: { has_nbt: false, can_place_on: [], can_destroy: [] }, + }; const transaction = { transaction: { legacy: { @@ -534,10 +544,9 @@ export default function inject(bot: BedrockBot) { entity_runtime_id: target.id, action_type: typeStr, hotbar_slot: bot.quickBarSlot, - held_item: bot.heldItem, + held_item: heldItem, player_pos: bot.entity.position, click_pos: { - // in case with interact its pos on hitbox of entity that is being interacted with x: 0, y: 0, z: 0,