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

Problems with 1.21.1 and custom resource packs. #3524

Open
1 task done
NurKai3 opened this issue Dec 12, 2024 · 2 comments
Open
1 task done

Problems with 1.21.1 and custom resource packs. #3524

NurKai3 opened this issue Dec 12, 2024 · 2 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@NurKai3
Copy link

NurKai3 commented Dec 12, 2024

  • The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.23.0
  • server: paper 1.21.1
  • node: 20.18.1

Detailed description of a problem

As soon as the “bot” mineflayer connects to a server with a custom resource pack, there are errors.

“[2024-12-12T17:28:58.103Z] Error: Deserialization error for play.toClient : Read error for undefined : Invalid tag: 117 > 20”

What did you try yet?

All packages uninstalled, reinstalled and updated.

Your current code

const mineflayer = require('mineflayer');
const axios = require('axios');
const fs = require('fs');
const logFile = fs.createWriteStream('log.txt', { flags: 'a' }); // Datei für Logs
const logConsole = process.stdout; // Standard-Konsolenausgabe

console.log = (message) => {
  logFile.write(`[${new Date().toISOString()}] ${message}\n`);
  logConsole.write(`[${new Date().toISOString()}] ${message}\n`);
};

console.error = (message) => {
  logFile.write(`[${new Date().toISOString()}] ERROR: ${message}\n`);
  logConsole.write(`[${new Date().toISOString()}] ERROR: ${message}\n`);
};

process.env.DEBUG = 'minecraft-protocol'


function createAFKBot() {
  const bot = mineflayer.createBot({
    host: 'BlockBande.net', // Minecraft-Server-IP
    username: 'Gewaltvoll', // Benutzername
    auth: 'microsoft', // Authentifizierung
    port: 25565, // Port
    version: '1.21.1',
    maxBufferSize: 10485760  // Maximaler Pufferspeicher (10 MB)
  });

  // Verbindungsschluss-Handler mit Wiederverbindung 
  bot.on('end', () => {
    console.log('[AFK-Bot] Verbindung zum Server wurde getrennt. Versuche, die Verbindung wiederherzustellen...');
    
    // Versuche, die Verbindung alle 5 Sekunden wiederherzustellen
    const reconnectInterval = setInterval(() => {
      console.log('[AFK-Bot] Stelle Verbindung wieder her...');
      clearInterval(reconnectInterval); // Stoppe das Intervall, um den Bot nicht mehrfach zu erstellen

      // Erstelle eine neue Instanz des Bots, um die Verbindung wiederherzustellen
      createAFKBot(); // Neue Instanz des Bots erstellen
    }, 5000);
  });

  bot.on('login', () => {
    console.log("[AFK-Bot] Bot erfolgreich eingeloggt!");
  });

  // Behandle das Ressourcenpaket korrekt
  bot._client.on('resource_pack_send', (data) => { bot._client.write('resource_pack_receive', { hash: "Resourcepack",  result: 3 }); 
  bot._client.write('resource_pack_receive', { hash: "Resourcepack", result: 0 }) })

  bot.on('spawn', () => {
    console.log("[AFK-Bot] Bot ist gespawnt!");
    
    // Optional: AFK-Befehle ausführen, um nicht getrennt zu werden
    bot.chat('/home home');
    
    // Wiederhole den Befehl, um aktiv zu bleiben
    setInterval(() => {
      bot.chat('/home home'); // Wiederhole den Befehl alle 60 Sekunden
    }, 60000);
  });

  // Schließen der Verbindung bei Abbruch
  process.on('SIGINT', () => {
    console.log("[AFK-Bot] Bot wird beendet...");
    bot.quit();
    process.exit();
  });

  bot.on('error', (err) => {
    console.error("Bot Error:", err);
  });

 bot.on('packet', (err) => {
    if (err instanceof PartialReadError) {
      console.log('Unvollständiges Paket empfangen und ignoriert:', err);
      // Ignoriere den Fehler und fahre fort
    } else {
      console.error('Unbehandelter Fehler:', err);
    }
  });

  bot.on('debug', console.log); // Aktiviert detaillierte Debug-Protokollierung

  return bot;

 createAFKBot();
}
/*
Some code here, replace this
*/

Expected behavior

That it does not throw a complete error and then is not located correctly, so the bot crashes completely and immediately.

Additional context

On a vanilla server, without custom RP, the bot works without any problems

LOG:
[2024-12-12T17:28:50.843Z] [AFK-Bot] Verbindung zum Server wurde getrennt. Versuche, die Verbindung wiederherzustellen...
[2024-12-12T17:28:55.846Z] [AFK-Bot] Stelle Verbindung wieder her...
[2024-12-12T17:28:57.269Z] [AFK-Bot] Bot erfolgreich eingeloggt!
[2024-12-12T17:28:57.736Z] [AFK-Bot] Bot ist gespawnt!
[2024-12-12T17:28:58.103Z] Error: Deserialization error for play.toClient : Read error for undefined : Invalid tag: 117 > 20
[2024-12-12T17:28:58.104Z] ERROR: Bot Error:
[2024-12-12T17:31:07.548Z] [AFK-Bot] Bot wird beendet...

@NurKai3 NurKai3 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Dec 12, 2024
@wubushanyan
Copy link

        bot.on('resourcePack', (url, hash) => {
            console.log('Resource pack URL:', url, 'Hash:', hash);
            bot.acceptResourcePack();
        });

Try this maybe?

@NurKai3
Copy link
Author

NurKai3 commented Dec 13, 2024

        bot.on('resourcePack', (url, hash) => {
            console.log('Resource pack URL:', url, 'Hash:', hash);
            bot.acceptResourcePack();
        });

Try this maybe?

Unfortunately same error, nothing has changed. Thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

2 participants