Skip to content

activateBlock default face direction (UP) silently fails for 2-block-tall blocks (bamboo_door etc.) #3851

@jerry1091

Description

@jerry1091

Bug description

bot.activateBlock(block) defaults to direction = new Vec3(0, 1, 0) (UP — click the top face). For any 2-block-tall block — specifically bamboo_door and other door types — this is wrong: clicking the top face of the lower half fails because the upper half already occupies y+1. The server silently rejects the interaction. The door does not open.

Single-block interactables (fence gates, buttons, levers, trapdoors) are unaffected because nothing occupies the block above them.

Root cause

In lib/plugins/inventory.js:

async function activateBlock (block, direction, cursorPos) {
  direction = direction ?? new Vec3(0, 1, 0)  // <-- always UP when omitted

For a 2-block-tall door, Vec3(0, 1, 0) maps to face 1 (top face of lower half). The server rejects "click top face of lower half" because the upper door half already occupies that space. The interaction is silently discarded — no error, the door just doesn't open.

Reproduction

// Bot standing to the east of a bamboo door at (30, 75, -8)
const doorBlock = bot.blockAt(new Vec3(30, 75, -8))

// BUG: silently fails — sends face=1 (UP), server rejects
await bot.activateBlock(doorBlock)

// FIX: explicitly pass the correct approach face
await bot.activateBlock(doorBlock, new Vec3(1, 0, 0))  // east face — bot is east of door

Proposed fix

Auto-detect the correct face from the bot's position relative to the block when direction is not provided. Use the bot's midpoint Y to compare against the block's center Y, so horizontal interactions near the bot's height don't get misclassified as UP/DOWN:

async function activateBlock (block, direction, cursorPos) {
  if (direction == null) {
    const botPos = bot.entity.position
    const dx = botPos.x - (block.position.x + 0.5)
    const dz = botPos.z - (block.position.z + 0.5)
    const dy = (botPos.y + (bot.entity.height ?? 1.8) * 0.5) - (block.position.y + 0.5)
    const adx = Math.abs(dx)
    const ady = Math.abs(dy)
    const adz = Math.abs(dz)
    if (adx >= adz && adx >= ady) direction = new Vec3(dx > 0 ? 1 : -1, 0, 0)
    else if (adz >= adx && adz >= ady) direction = new Vec3(0, 0, dz > 0 ? 1 : -1)
    else direction = new Vec3(0, dy > 0 ? 1 : -1, 0)
  }

This is backward-compatible: callers who already pass an explicit direction are unaffected. Only callers relying on the default (which was already broken for doors) get the new behavior.

Environment

  • mineflayer: 4.33.0
  • Minecraft server: 1.21.11 (Paper, offline-mode)
  • Blocks confirmed broken with default direction: bamboo_door (and all other 2-block door variants by the same logic)
  • Blocks unaffected: bamboo_fence_gate, oak_fence_gate, buttons, levers, trapdoors

Related

I have a working fix and am happy to submit a PR if the approach looks good to maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions