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:
parent
b60cc8a987
commit
7199acf149
1 changed files with 11 additions and 2 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue