Skip to content

Commit

Permalink
Set sequence field correctly in activateItem (#3445)
Browse files Browse the repository at this point in the history
* updating activateItem

* updating activateItem

* fix lint

* moved sequence upward

* moved sequence upward

* removed comment, these tests passing feel like roulette.

* reorganized

---------

Co-authored-by: extremeheat <extreme@protonmail.ch>
  • Loading branch information
GenerelSchwerz and extremeheat authored Nov 16, 2024
1 parent 3d6e234 commit fdba037
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/plugins/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function inject (bot, { hideErrors }) {
const windows = require('prismarine-windows')(bot.version)

let eatingTask = createDoneTask()
let sequence = 0

let nextActionNumber = 0 // < 1.17
let stateId = -1
Expand All @@ -43,6 +44,7 @@ function inject (bot, { hideErrors }) {
bot.inventory = windows.createWindow(0, 'minecraft:inventory', 'Inventory')
bot.currentWindow = null
bot.usingHeldItem = false

Object.defineProperty(bot, 'heldItem', {
get: function () {
return bot.inventory.slots[bot.QUICK_BAR_START + bot.quickBarSlot]
Expand Down Expand Up @@ -111,6 +113,8 @@ function inject (bot, { hideErrors }) {

function activateItem (offHand = false) {
bot.usingHeldItem = true
sequence++

if (bot.supportFeature('useItemWithBlockPlace')) {
bot._client.write('block_place', {
location: new Vec3(-1, 255, -1),
Expand All @@ -123,17 +127,26 @@ function inject (bot, { hideErrors }) {
} else if (bot.supportFeature('useItemWithOwnPacket')) {
bot._client.write('use_item', {
hand: offHand ? 1 : 0,
sequence,
rotation: { x: 0, y: 0 }
})
}
}

function deactivateItem () {
bot._client.write('block_dig', {
const body = {
status: 5,
location: new Vec3(0, 0, 0),
face: 5
})
}

if (bot.supportFeature('useItemWithOwnPacket')) {
body.face = 0
body.sequence = 0
}

bot._client.write('block_dig', body)

bot.usingHeldItem = false
}

Expand Down

0 comments on commit fdba037

Please sign in to comment.