Skip to content

Commit fdba037

Browse files
Set sequence field correctly in activateItem (#3445)
* 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 <[email protected]>
1 parent 3d6e234 commit fdba037

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/plugins/inventory.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function inject (bot, { hideErrors }) {
2626
const windows = require('prismarine-windows')(bot.version)
2727

2828
let eatingTask = createDoneTask()
29+
let sequence = 0
2930

3031
let nextActionNumber = 0 // < 1.17
3132
let stateId = -1
@@ -43,6 +44,7 @@ function inject (bot, { hideErrors }) {
4344
bot.inventory = windows.createWindow(0, 'minecraft:inventory', 'Inventory')
4445
bot.currentWindow = null
4546
bot.usingHeldItem = false
47+
4648
Object.defineProperty(bot, 'heldItem', {
4749
get: function () {
4850
return bot.inventory.slots[bot.QUICK_BAR_START + bot.quickBarSlot]
@@ -111,6 +113,8 @@ function inject (bot, { hideErrors }) {
111113

112114
function activateItem (offHand = false) {
113115
bot.usingHeldItem = true
116+
sequence++
117+
114118
if (bot.supportFeature('useItemWithBlockPlace')) {
115119
bot._client.write('block_place', {
116120
location: new Vec3(-1, 255, -1),
@@ -123,17 +127,26 @@ function inject (bot, { hideErrors }) {
123127
} else if (bot.supportFeature('useItemWithOwnPacket')) {
124128
bot._client.write('use_item', {
125129
hand: offHand ? 1 : 0,
130+
sequence,
126131
rotation: { x: 0, y: 0 }
127132
})
128133
}
129134
}
130135

131136
function deactivateItem () {
132-
bot._client.write('block_dig', {
137+
const body = {
133138
status: 5,
134139
location: new Vec3(0, 0, 0),
135140
face: 5
136-
})
141+
}
142+
143+
if (bot.supportFeature('useItemWithOwnPacket')) {
144+
body.face = 0
145+
body.sequence = 0
146+
}
147+
148+
bot._client.write('block_dig', body)
149+
137150
bot.usingHeldItem = false
138151
}
139152

0 commit comments

Comments
 (0)