Skip to content

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

Merged
rom1504 merged 1 commit into
PrismarineJS:masterfrom
PondWader:offhand
Jul 22, 2023
Merged

Handle entity hand swapping (swapping off-hand and main hand)#3097
rom1504 merged 1 commit into
PrismarineJS:masterfrom
PondWader:offhand

Conversation

@PondWader
Copy link
Copy Markdown
Contributor

Fixes #3095

Comment thread lib/plugins/entities.js
const eventName = entityStatusEvents[packet.entityStatus]

if (eventName === 'entityHandSwap' && entity.equipment) {
[entity.equipment[0], entity.equipment[1]] = [entity.equipment[1], entity.equipment[0]]
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown

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
Copy Markdown
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