Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating activateItem #3445

Merged
merged 9 commits into from
Nov 16, 2024
19 changes: 16 additions & 3 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 @@ -122,17 +126,26 @@ function inject (bot, { hideErrors }) {
})
} else if (bot.supportFeature('useItemWithOwnPacket')) {
bot._client.write('use_item', {
hand: offHand ? 1 : 0
hand: offHand ? 1 : 0,
sequence
})
}
}

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, you can supply extra fields on packets without any problems. If the field is not used on a particular version it will be ignored. I'm curious why the sequence is always 0 here, is it being reset or just fixed to 0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just fixed to zero. I have no idea to be honest. It doesn't change the sequence count.

I decided to add a feature support there since I wasn't sure if the face affected anything and just wanted to be as legitimate as possible without disrupting the original face (5)'s implementation.

}

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

bot.usingHeldItem = false
}

Expand Down
Loading