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

Handle entity hand swapping (swapping off-hand and main hand) #3097

Merged
merged 1 commit into from
Jul 22, 2023

Conversation

PondWader
Copy link
Contributor

Fixes #3095

@@ -338,6 +339,12 @@ function inject (bot) {
// entity status
const entity = fetchEntity(packet.entityId)
const eventName = entityStatusEvents[packet.entityStatus]

if (eventName === 'entityHandSwap' && entity.equipment) {
[entity.equipment[0], entity.equipment[1]] = [entity.equipment[1], entity.equipment[0]]
Copy link
Member

Choose a reason for hiding this comment

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

is this valid syntax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes

Choose a reason for hiding this comment

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

Just asking, is it possible to check if an item in the offhand like a shield is being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't really the place to ask for help. I'd recommend you join the Discord: https://discord.com/invite/GsEFRM8
Or if that's not possible for you you can use the discussions: https://github.com/PrismarineJS/mineflayer/discussions

Anyway since you've already asked, you have to use the entity metadata like so:

function getActiveHand (entity) {
    switch (entity.metadata[8]) {
        case undefined: 
        case 0:
        case 2: return 'none'
        case 1: return 'hand'
        case 3: return 'offhand'
    }
}

@rom1504 rom1504 merged commit a80d69a into PrismarineJS:master Jul 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

entity.equipment and entity.heldItem not accurate when switching with offhand
4 participants