diff --git a/src/worldInteractions.ts b/src/worldInteractions.ts index 777200ca..5ce428d2 100644 --- a/src/worldInteractions.ts +++ b/src/worldInteractions.ts @@ -14,6 +14,7 @@ import destroyStage9 from 'minecraft-assets/minecraft-assets/data/1.10/blocks/de import { Vec3 } from 'vec3' import { LineMaterial, Wireframe, LineSegmentsGeometry } from 'three-stdlib' +import { Entity } from 'prismarine-entity' import { hideCurrentModal, isGameActive, showModal } from './globalState' import { assertDefined } from './utils' import { options } from './optionsStorage' @@ -95,7 +96,7 @@ class WorldInteraction { if (e.button === 0) { // left click bot.attack(entity) } else if (e.button === 2) { // right click - void bot.activateEntity(entity) + this.activateEntity(entity) } } }) @@ -158,6 +159,35 @@ class WorldInteraction { bot.on('game', upLineMaterial) } + activateEntity (entity: Entity) { + // mineflayer has completely wrong implementation of this action + if (bot.supportFeature('armAnimationBeforeUse')) { + bot.swingArm('right') + } + bot._client.write('use_entity', { + target: entity.id, + mouse: 2, + // todo do not fake + x: 0.581_012_585_759_162_9, + y: 0.581_012_585_759_162_9, + z: 0.581_012_585_759_162_9, + // x: raycastPosition.x - entity.position.x, + // y: raycastPosition.y - entity.position.y, + // z: raycastPosition.z - entity.position.z + sneaking: bot.getControlState('sneak'), + hand: 0 + }) + bot._client.write('use_entity', { + target: entity.id, + mouse: 0, + sneaking: bot.getControlState('sneak'), + hand: 0 + }) + if (!bot.supportFeature('armAnimationBeforeUse')) { + bot.swingArm('right') + } + } + updateBlockInteractionLines (blockPos: Vec3 | null, shapePositions?: Array<{ position; width; height; depth }>) { assertDefined(viewer) if (blockPos && this.interactionLines && blockPos.equals(this.interactionLines.blockPos)) { @@ -251,6 +281,7 @@ class WorldInteraction { //@ts-expect-error bot.lookAt = (pos) => { } //@ts-expect-error + // TODO it still must 1. fire block place 2. swing arm (right) bot.activateBlock(cursorBlock, vecArray[cursorBlock.face], delta).finally(() => { bot.lookAt = oldLookAt }).catch(console.warn)