PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
5.03k stars 911 forks source link

Error after updating bot to 1.21.1 #3488

Open i240c opened 5 hours ago

i240c commented 5 hours ago

Versions

Detailed description of a problem

Tried joining my minecraft server after updating to 1.21 but for some reason gave an error so I made a fresh project with just join code but it still gave the same error. The bot worked in the server on previous version.

What did you try yet?

I have no idea what causes it so I don't know what to try

Your current code

import mineflayer from "mineflayer";
import chalk from "chalk";
import { readFile } from 'fs/promises';

// Setup global bot arguments
let botArgs = {
    host: 'hiddenIpAddress',
    port: '25565',
    version: '1.21.1'
};

// Bot class
class MCBot {

    // Constructor
    constructor(username, password, auth) {
        this.username = username;
        this.password = password;
        this.auth = auth;
        this.host = botArgs["host"];
        this.port = botArgs["port"];
        this.version = botArgs["version"];

        // Initialize the bot
        this.initBot();
    }

    // Init bot instance
    initBot() {
        this.bot = mineflayer.createBot({
           // "username": this.username,
          //  "password": this.password,
            "auth": this.auth,
            "host": this.host,
            "port": this.port,
            "version": this.version
        });

        // Add to list
        botNames.push(this.bot.username);

        // Initialize bot events
        this.initEvents();
    }

    // Logger
    log(...msg) {
        console.log(`[${this.bot.username}]`, ...msg);
    }

    // Chat intake logger
    chatLog(username, ...msg) {
        if (!botNames.includes(username)) {
            this.log(chalk.ansi256(98)(`<${username}>`), ...msg)
        }
    }

    // Init bot events
    initEvents() {

        this.bot.on('login', async () => {
            let botSocket = this.bot._client.socket;
            this.log(chalk.ansi256(34)(`Logged in to ${botSocket.server ? botSocket.server : botSocket._host}`));
        });

        this.bot.on('end', async (reason) => {
            this.log(chalk.red(`Disconnected: ${reason}`));

            // Bot peacefully disconnected
            if (reason == "disconnect.quitting") {
                return
            }
            // Unhandled disconnections
            else {
                //
            }

            // Attempt to reconnect
            setTimeout(() => this.initBot(), 5000);
        });

        this.bot.on('spawn', async () => {
            this.log(chalk.ansi256(46)(`Spawned in`));
        });

        this.bot.on('chat', async (username, jsonMsg) => {
            this.chatLog(username, jsonMsg);
        });

        this.bot.on('error', async (err) => {

            // Connection error
            if (err.code == 'ECONNREFUSED') {
                this.log(`Failed to connect to ${err.address}:${err.port}`)
            }
            // Unhandled errors
            else {
                this.log(`Unhandled error: ${err}`);
            }
        });
    }
}

const ACCOUNT = JSON.parse(
    await readFile(
        new URL('./ACCOUNT.json', import.meta.url)
    )
);

let bots = [];
let botNames = [];
for (const ACC of ACCOUNT) {
    let newBot = new MCBot(ACC.username, ACC.password, ACC.auth)
    bots.push(newBot);
};

/* Error code

Error: Read error for undefined : Invalid tag: 117 > 20
    at Object.compound (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:16:21)
    at Object.nbtSwitch (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:4310:47)
    at Object.anonymousNbt (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:77:64)
    at eval (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:136:56)
    at Object.SlotComponent (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:729:9)
    at eval (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:748:49)
    at eval (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:753:15)
    at eval (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:771:13)
    at Object.Slot (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:773:9)
    at Object.ingredient (eval at compile (C:\Users\240c\source\repos\KohukeExpress\node_modules\protodef\src\compiler.js:262:12), <anonymous>:998:32) {
  field: 'play.toClient'
}

*/



## Expected behavior
The bot should just join the server and stay there
rom1504 commented 4 hours ago

Ok something wrong with SlotComponent and paper server