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) <noreply@anthropic.com>
This commit is contained in:
roberts 2026-03-30 15:14:19 -05:00
parent b60cc8a987
commit 7199acf149

View file

@ -523,6 +523,16 @@ export default function inject(bot: BedrockBot) {
} }
function itemUseOnEntity(target: any, type: number) { function itemUseOnEntity(target: any, type: number) {
const typeStr = ['attack', 'interact'][type]; 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 = { const transaction = {
transaction: { transaction: {
legacy: { legacy: {
@ -534,10 +544,9 @@ export default function inject(bot: BedrockBot) {
entity_runtime_id: target.id, entity_runtime_id: target.id,
action_type: typeStr, action_type: typeStr,
hotbar_slot: bot.quickBarSlot, hotbar_slot: bot.quickBarSlot,
held_item: bot.heldItem, held_item: heldItem,
player_pos: bot.entity.position, player_pos: bot.entity.position,
click_pos: { click_pos: {
// in case with interact its pos on hitbox of entity that is being interacted with
x: 0, x: 0,
y: 0, y: 0,
z: 0, z: 0,