PrismarineJS / node-minecraft-protocol

Parse and serialize minecraft packets, plus authentication and encryption.
https://prismarinejs.github.io/node-minecraft-protocol/
BSD 3-Clause "New" or "Revised" License
1.2k stars 241 forks source link

Cannot read properties of undefined (reading 'overworld') #1274

Closed dvsloth closed 6 months ago

dvsloth commented 6 months ago

Versions

Detailed description of a problem

Upon the Bot's attempt to connect to a Minecraft server running version 1.20.2, an error is encountered, accompanied by the following error code.

E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\minecraft-protocol\src\transforms\framing.js:67 } else { throw e } ^ TypeError: Cannot read properties of undefined (reading 'overworld') at handleRespawnPacketData (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\mineflayer\lib\plugins\game.js:46:63) at Client. (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\mineflayer\lib\plugins\game.js:75:5) at Client.emit (node:events:531:35) at emitPacket (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\minecraft-protocol\src\client.js:83:12) at FullPacketParser. (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\minecraft-protocol\src\client.js:112:9) at FullPacketParser.emit (node:events:519:28) at addChunk (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:279:12) at readableAddChunk (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:262:11) at Readable.push (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:228:10) at Transform.push (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_transform.js:132:32)

Current code

const express = require('express');
const http = require('http');
const socketIO = require('socket.io');
const mineflayer = require('mineflayer');
const { pathfinder, Movements } = require('mineflayer-pathfinder');
const pvp = require('mineflayer-pvp').plugin;
const { GoalNear } = require('mineflayer-pathfinder').goals;

const app = express();
const server = http.createServer(app);
const io = socketIO(server);

const bot = mineflayer.createBot({
  host: 'localhost',
  port: '25565',
  auth: 'microsoft',
  username: 'ImAFriendlyBot',
  version: '1.20.2'
});

bot.loadPlugin(pathfinder);
bot.loadPlugin(pvp);

let pvpMode = false;
let followMode = false;
let targetPlayer = null;

let target = null;

bot.on('death', () => {
  bot.chat('/tellraw @a ""');
  bot.chat('/tellraw @a ["",{"text":"Bot has Died..","color":"dark_gray"}]');
  bot.chat('/tellraw @a ""');
  bot.chat('/tellraw @a ["",{"text":"Bot is Respawning..","color":"dark_red"}]');
  bot.chat('/tellraw @a ""');
});

bot.on('chat', (username, message) => {
  const target = bot.players[username]?.entity;
  const lowerCaseMessage = message.toLowerCase();
  if (lowerCaseMessage === '@pvpmode') {
    pvpMode = !pvpMode;
    targetPlayer = username;
    if (pvpMode) {
      const targetMessage = JSON.stringify([
        { text: 'Now Targetting: ', color: 'red' },
        { text: username, color: 'green' }
      ]);
      bot.chat('/give ImaFriendlyBot diamond_sword 1')
      bot.chat('/tellraw @a ""');
      bot.chat('/tellraw @a ["",{"text":"PvP Mode Activated","color":"dark_red"}]');
      bot.chat(`/tellraw @a ${targetMessage}`);
      bot.chat('/tellraw @a ""');
      bot.pvp.attack(bot.players[username].entity);
    } else {
      const targetMessage1 = JSON.stringify([
        { text: 'No Longer Targetting: ', color: 'red' },
        { text: username, color: 'green' }
      ]);
      bot.chat('/tellraw @a ""');
      bot.chat('/tellraw @a ["",{"text":"PvP Mode Deactivated","color":"green"}]');
      bot.chat(`/tellraw @a ${targetMessage1}`);
      bot.chat('/tellraw @a ""');
      bot.chat('/clear')
      bot.pvp.stop();
    }
} else if (lowerCaseMessage === '@followmode') {
    followMode = !followMode;
    if (followMode && target) {
      const followMessage = JSON.stringify([
        { text: 'Now Following: ', color: 'gold' },
        { text: username, color: 'green' }
      ]);
      bot.chat('/tellraw @a ""');
      bot.chat(`/tellraw @a ${followMessage}`);
      bot.chat('/tellraw @a ""');
      const mcData = require('minecraft-data')(bot.version);
      const defaultMove = new Movements(bot, mcData);
      bot.pathfinder.setMovements(defaultMove);
      bot.on('physicTick', () => {
        if (followMode && target) {
          const distanceToPlayer = bot.entity.position.distanceTo(target.position);
          console.log(`Distance to player: ${distanceToPlayer}`);
          if (distanceToPlayer > 1) {
            console.log(`Setting goal to player's position: ${target.position}`);
            bot.pathfinder.setGoal(new GoalNear(target.position.x, target.position.y, target.position.z, 1));
          }
        }
      });
    } else {
      const followMessage1 = JSON.stringify([
        { text: 'Stopped Following: ', color: 'gold' },
        { text: username, color: 'green' }
      ]);
      bot.chat('/tellraw @a ""');
      bot.chat(`/tellraw @a ${followMessage1}`);
      bot.chat('/tellraw @a ""');
      bot.pathfinder.setGoal(null);
    }
  } else if (lowerCaseMessage === '@leave') {
    bot.chat('/tellraw @a ""');
    bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Bot is Leaving the game..","color":"green"}]');
    bot.chat('/tellraw @a ""');
    setTimeout(() => {
      bot.quit('Goodbye');
    }, 1000);
   } else if (lowerCaseMessage.startsWith('@help')) {
    if (lowerCaseMessage === '@help utils') {
        bot.chat('/tellraw @a ""');
        bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Utils Help","color":"green"},{"text":"]----","color":"dark_gray"}]');
        bot.chat('/tellraw @a ["",{"text":"1","color":"red"},{"text":".","color":"gray"},{"text":" @Reload ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Reload Bot Changes","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"2","color":"red"},{"text":".","color":"gray"},{"text":" @ClearChat ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Clear the Chat","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @Debug ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Bot Debug Information","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @Sudo <ARGS> ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Make the Bot run commands/Say what you want","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Utils Help","color":"green"},{"text":"]----","color":"dark_gray"}]');
        bot.chat('/tellraw @a ""');
      } else {
        bot.chat('/tellraw @a ""');
        bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Help","color":"green"},{"text":"]----","color":"dark_gray"}]');
        bot.chat('/tellraw @a ["",{"text":"1","color":"red"},{"text":".","color":"gray"},{"text":" @Help/@Help Utils ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"This Help Command/Utils Help Command","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"2","color":"red"},{"text":".","color":"gray"},{"text":" @PvPMode ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Activate PvP Mode","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @FollowMode ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Activate Head Follow Mode","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"5","color":"red"},{"text":".","color":"gray"},{"text":" @Leave ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Make the Bot leave the Game","color":"dark_aqua"}]');
        bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Help","color":"green"},{"text":"]----","color":"dark_gray"}]');
        bot.chat('/tellraw @a ""');
        bot.chat('/tellraw @a ["",{"text":"Note: Commands are NO LONGER case SeNsItIvE!","color":"green"}]');
      }
    } else if (lowerCaseMessage.startsWith('@sudo ')) {
      const echoMessage = message.slice(6);

      if (!echoMessage.startsWith('/')) {
        for (let i = 0; i < 40; i++) {
          bot.chat('/tellraw @a ""');
        }
      }

      bot.chat(echoMessage);

    } else if (lowerCaseMessage.startsWith('@ride')) {
    bot.chat('');
  } else if (lowerCaseMessage === '@reload') {
    bot.chat('/tellraw @a ""');
    bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Bot is Reloading...","color":"green"}]');
    bot.chat('/tellraw @a ""');

    setTimeout(() => {
      require('fs').writeFileSync('./restart.txt', 'restart');
    }, 1000);
  } else if (lowerCaseMessage === '@clearchat') {
    for (let i = 0; i < 40; i++) {
      bot.chat('/tellraw @a ""');
    }
    bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Chat has been Cleared!","color":"green"}]')
  } else if (lowerCaseMessage.startsWith('@debug')) {
    const locationInfo = `X: ${bot.entity.position.x.toFixed(2)}, Y: ${bot.entity.position.y.toFixed(2)}, Z: ${bot.entity.position.z.toFixed(2)}`;
    const healthInfo = `Health: ${bot.health}`;
    const foodInfo = `Food: ${bot.food}`;
    const isRaining = `Raining: ${bot.isRaining}`;
    const headRotation = `Pitch: ${bot.entity.pitch.toFixed(2)}, Yaw: ${bot.entity.yaw.toFixed(2)}`;
    const heldItem = bot.heldItem ? `Held Item: ${bot.heldItem.name}` : 'Held Item: None';
    const playerEntity = bot.players['player'] ? bot.players['player'].entity : null;
    const distanceFromPlayer = playerEntity ? `Distance: ${bot.entity.position.distanceTo(playerEntity.position).toFixed(2)}` : 'Player not found';
    const nearestPlayer = `Nearest Player: ${bot.nearestEntity(entity => entity.type === 'player').username}`;

    bot.chat('/tellraw @a ""');
    bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Debug","color":"red"},{"text":"]----","color":"dark_gray"}]');
    bot.chat(`/tellraw @a ["",{"text":"Click for Location Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"Bot Location: ${locationInfo}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Health Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${healthInfo}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Food Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${foodInfo}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Weather Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${isRaining}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Head Rotation Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${headRotation}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Held Item Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${heldItem}\\"}"}}]`);
    bot.chat(`/tellraw @a ["",{"text":"Click for Nearest Player Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${nearestPlayer}\\"}"}}]`);
    bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Debug","color":"red"},{"text":"]----","color":"dark_gray"}]');
    bot.chat('/tellraw @a ""');
  }
});

bot.on('error', console.log);
bot.on('kicked', console.log);

app.use(express.static('public'));

io.on('connection', (socket) => {
  const HEAD_MOVEMENT_INCREMENT = 0.5;
  let yawDelta = 0;
  let pitchDelta = 0;

  console.log('A user connected');

  socket.on('keyPress', (key) => {
    if (isValidControl(key)) {
      bot.setControlState(key, true);
    } else if (isHeadMovementControl(key)) {
      handleHeadMovement(key, true);
    } else {
      console.log(`Invalid control: ${key}`);
    }
  });

  socket.on('keyRelease', (key) => {
    if (isValidControl(key)) {
      bot.setControlState(key, false);
    } else if (isHeadMovementControl(key)) {
      handleHeadMovement(key, false);
    } else {
      console.log(`Invalid control: ${key}`);
    }
  });

  function isHeadMovementControl(key) {
    return ['up', 'down', 'p1', 'p2'].includes(key);
  }

  function handleHeadMovement(key, isPressed) {
    switch (key) {
      case 'up':
        yawDelta = isPressed ? HEAD_MOVEMENT_INCREMENT : 0;
        break;
      case 'down':
        yawDelta = isPressed ? -HEAD_MOVEMENT_INCREMENT : 0;
        break;
      case 'p1':
        pitchDelta = isPressed ? HEAD_MOVEMENT_INCREMENT : 0;
        break;
      case 'p2':
        pitchDelta = isPressed ? -HEAD_MOVEMENT_INCREMENT : 0;
        break;
    }

    bot.look(bot.entity.yaw + yawDelta, bot.entity.pitch + pitchDelta, true);
  }

  function isValidControl(key) {
    const validControls = ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak'];
    return validControls.includes(key);
  }

  socket.on('mouseClick', () => {
    const entityFilter = (entity) => entity.type !== 'player';
    const nearestEntity = bot.nearestEntity(entityFilter);

    if (nearestEntity) {
      bot.attack(nearestEntity);
    }
  });

  socket.on('rightClick', () => {
    const npc = bot.nearestEntity(); // Get the nearest entity
    if (npc) {
      bot.attack(npc); // Attack the entity
    }
  });

  socket.on('disconnect', () => {
    console.log('User disconnected');
  });
});

const PORT = 3000;
server.listen(PORT, () => {
  console.log(`Server running on http://localhost:${PORT}`);
});

Expected behavior

The bot joining the server like normal like before recent update

Additional context

This bot was working perfectly fine before the 1.20.2 support update, and has remained completely unaltered when updating.

rom1504 commented 6 months ago

Mineflayer does not support 1.20.2 yet

On Sat, Dec 30, 2023, 2:55 AM NotSloth @.***> wrote:

Versions

  • minecraft-protocol: 1.45.0
  • server: vanilla/spigot/paper 1.20.2
  • node: 21.5.0

Detailed description of a problem

Upon the Bot's attempt to connect to a Minecraft server running version 1.20.2, an error is encountered, accompanied by the following error code.

TypeError: Cannot read properties of undefined (reading 'overworld') at handleRespawnPacketData (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\mineflayer\lib\plugins\game.js:46:63) at Client. (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\mineflayer\lib\plugins\game.js:75:5) at Client.emit (node:events:531:35) at emitPacket (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\minecraft-protocol\src\client.js:83:12) at FullPacketParser. (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\minecraft-protocol\src\client.js:112:9) at FullPacketParser.emit (node:events:519:28) at addChunk (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:279:12) at readableAddChunk (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:262:11) at Readable.push (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_readable.js:228:10) at Transform.push (E:\Desktop\Personal Projects\Julian\Python\McPortScanner\node_modules\protodef\node_modules\readable-stream\lib_stream_transform.js:132:32) Current code

const express = require('express');const http = require('http');const socketIO = require('socket.io');const mineflayer = require('mineflayer');const { pathfinder, Movements } = require('mineflayer-pathfinder');const pvp = require('mineflayer-pvp').plugin;const { GoalNear } = require('mineflayer-pathfinder').goals; const app = express();const server = http.createServer(app);const io = socketIO(server); const bot = mineflayer.createBot({ host: 'localhost', port: '25565', auth: 'microsoft', username: 'ImAFriendlyBot', version: '1.20.2'}); bot.loadPlugin(pathfinder);bot.loadPlugin(pvp); let pvpMode = false;let followMode = false;let targetPlayer = null; let target = null; bot.on('death', () => { bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"Bot has Died..","color":"dark_gray"}]'); bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"Bot is Respawning..","color":"dark_red"}]'); bot.chat('/tellraw @a ""');}); bot.on('chat', (username, message) => { const target = bot.players[username]?.entity; const lowerCaseMessage = message.toLowerCase(); if (lowerCaseMessage === @.') { pvpMode = !pvpMode; targetPlayer = username; if (pvpMode) { const targetMessage = JSON.stringify([ { text: 'Now Targetting: ', color: 'red' }, { text: username, color: 'green' } ]); bot.chat('/give ImaFriendlyBot diamond_sword 1') bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"PvP Mode Activated","color":"dark_red"}]'); bot.chat(/tellraw @a ${targetMessage}); bot.chat('/tellraw @a ""'); bot.pvp.attack(bot.players[username].entity); } else { const targetMessage1 = JSON.stringify([ { text: 'No Longer Targetting: ', color: 'red' }, { text: username, color: 'green' } ]); bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"PvP Mode Deactivated","color":"green"}]'); bot.chat(/tellraw @a ${targetMessage1}); bot.chat('/tellraw @a ""'); bot.chat('/clear') bot.pvp.stop(); }} else if (lowerCaseMessage === @.') { followMode = !followMode; if (followMode && target) { const followMessage = JSON.stringify([ { text: 'Now Following: ', color: 'gold' }, { text: username, color: 'green' } ]); bot.chat('/tellraw @a ""'); bot.chat(/tellraw @a ${followMessage}); bot.chat('/tellraw @a ""'); const mcData = require('minecraft-data')(bot.version); const defaultMove = new Movements(bot, mcData); bot.pathfinder.setMovements(defaultMove); bot.on('physicTick', () => { if (followMode && target) { const distanceToPlayer = bot.entity.position.distanceTo(target.position); console.log(Distance to player: ${distanceToPlayer}); if (distanceToPlayer > 1) { console.log(Setting goal to player's position: ${target.position}); bot.pathfinder.setGoal(new GoalNear(target.position.x, target.position.y, target.position.z, 1)); } } }); } else { const followMessage1 = JSON.stringify([ { text: 'Stopped Following: ', color: 'gold' }, { text: username, color: 'green' } ]); bot.chat('/tellraw @a ""'); bot.chat(/tellraw @a ${followMessage1}); bot.chat('/tellraw @a ""'); bot.pathfinder.setGoal(null); } } else if (lowerCaseMessage === @.') { bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Bot is Leaving the game..","color":"green"}]'); bot.chat('/tellraw @a ""'); setTimeout(() => { bot.quit('Goodbye'); }, 1000); } else if @.')) { if (lowerCaseMessage === @. utils') { bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Utils Help","color":"green"},{"text":"]----","color":"dark_gray"}]'); bot.chat('/tellraw @a ["",{"text":"1","color":"red"},{"text":".","color":"gray"},{"text":" @Reload ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Reload Bot Changes","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"2","color":"red"},{"text":".","color":"gray"},{"text":" @ClearChat ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Clear the Chat","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @Debug ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Bot Debug Information","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @Sudo ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Make the Bot run commands/Say what you want","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Utils Help","color":"green"},{"text":"]----","color":"dark_gray"}]'); bot.chat('/tellraw @a ""'); } else { bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Help","color":"green"},{"text":"]----","color":"dark_gray"}]'); bot.chat('/tellraw @a ["",{"text":"1","color":"red"},{"text":".","color":"gray"},{"text":" @@. Utils ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"This Help Command/Utils Help Command","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"2","color":"red"},{"text":".","color":"gray"},{"text":" @PvPMode ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Activate PvP Mode","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"3","color":"red"},{"text":".","color":"gray"},{"text":" @FollowMode ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Activate Head Follow Mode","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"5","color":"red"},{"text":".","color":"gray"},{"text":" @Leave ","color":"aqua"},{"text":"-","color":"gray"},{"text":" ","color":"aqua"},{"text":"Make the Bot leave the Game","color":"dark_aqua"}]'); bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Help","color":"green"},{"text":"]----","color":"dark_gray"}]'); bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"Note: Commands are NO LONGER case SeNsItIvE!","color":"green"}]'); } } else if @.*** ')) { const echoMessage = message.slice(6);

  if (!echoMessage.startsWith('/')) {
    for (let i = 0; i < 40; i++) {
      bot.chat('/tellraw @a ""');
    }
  }

  bot.chat(echoMessage);

} else if ***@***.***')) {
bot.chat('');

} else if (lowerCaseMessage === @.***') { bot.chat('/tellraw @a ""'); bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Bot is Reloading...","color":"green"}]'); bot.chat('/tellraw @a ""');

setTimeout(() => {
  require('fs').writeFileSync('./restart.txt', 'restart');
}, 1000);

} else if (lowerCaseMessage === @.') { for (let i = 0; i < 40; i++) { bot.chat('/tellraw @a ""'); } bot.chat('/tellraw @a ["",{"text":"[","color":"dark_gray"},{"text":"IFB","color":"dark_red"},{"text":"]:","color":"dark_gray"},{"text":" ","color":"dark_red"},{"text":"Chat has been Cleared!","color":"green"}]') } else if @.')) { const locationInfo = X: ${bot.entity.position.x.toFixed(2)}, Y: ${bot.entity.position.y.toFixed(2)}, Z: ${bot.entity.position.z.toFixed(2)}; const healthInfo = Health: ${bot.health}; const foodInfo = Food: ${bot.food}; const isRaining = Raining: ${bot.isRaining}; const headRotation = Pitch: ${bot.entity.pitch.toFixed(2)}, Yaw: ${bot.entity.yaw.toFixed(2)}; const heldItem = bot.heldItem ? Held Item: ${bot.heldItem.name} : 'Held Item: None'; const playerEntity = bot.players['player'] ? bot.players['player'].entity : null; const distanceFromPlayer = playerEntity ? Distance: ${bot.entity.position.distanceTo(playerEntity.position).toFixed(2)} : 'Player not found'; const nearestPlayer = Nearest Player: ${bot.nearestEntity(entity => entity.type === 'player').username};

bot.chat('/tellraw @a ""');
bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Debug","color":"red"},{"text":"]----","color":"dark_gray"}]');
bot.chat(`/tellraw @a ["",{"text":"Click for Location Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"Bot Location: ${locationInfo}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Health Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${healthInfo}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Food Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${foodInfo}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Weather Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${isRaining}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Head Rotation Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${headRotation}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Held Item Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${heldItem}\\"}"}}]`);
bot.chat(`/tellraw @a ["",{"text":"Click for Nearest Player Info","color":"yellow","clickEvent":{"action":"run_command","value":"/tellraw @a {\\"text\\":\\"${nearestPlayer}\\"}"}}]`);
bot.chat('/tellraw @a ["",{"text":"----[","color":"dark_gray"},{"text":"IFB Debug","color":"red"},{"text":"]----","color":"dark_gray"}]');
bot.chat('/tellraw @a ""');

}}); bot.on('error', console.log);bot.on('kicked', console.log); app.use(express.static('public')); io.on('connection', (socket) => { const HEAD_MOVEMENT_INCREMENT = 0.5; let yawDelta = 0; let pitchDelta = 0;

console.log('A user connected');

socket.on('keyPress', (key) => { if (isValidControl(key)) { bot.setControlState(key, true); } else if (isHeadMovementControl(key)) { handleHeadMovement(key, true); } else { console.log(Invalid control: ${key}); } });

socket.on('keyRelease', (key) => { if (isValidControl(key)) { bot.setControlState(key, false); } else if (isHeadMovementControl(key)) { handleHeadMovement(key, false); } else { console.log(Invalid control: ${key}); } });

function isHeadMovementControl(key) { return ['up', 'down', 'p1', 'p2'].includes(key); }

function handleHeadMovement(key, isPressed) { switch (key) { case 'up': yawDelta = isPressed ? HEAD_MOVEMENT_INCREMENT : 0; break; case 'down': yawDelta = isPressed ? -HEAD_MOVEMENT_INCREMENT : 0; break; case 'p1': pitchDelta = isPressed ? HEAD_MOVEMENT_INCREMENT : 0; break; case 'p2': pitchDelta = isPressed ? -HEAD_MOVEMENT_INCREMENT : 0; break; }

bot.look(bot.entity.yaw + yawDelta, bot.entity.pitch + pitchDelta, true);

}

function isValidControl(key) { const validControls = ['forward', 'back', 'left', 'right', 'jump', 'sprint', 'sneak']; return validControls.includes(key); }

socket.on('mouseClick', () => { const entityFilter = (entity) => entity.type !== 'player'; const nearestEntity = bot.nearestEntity(entityFilter);

if (nearestEntity) {
  bot.attack(nearestEntity);
}

});

socket.on('rightClick', () => { const npc = bot.nearestEntity(); // Get the nearest entity if (npc) { bot.attack(npc); // Attack the entity } });

socket.on('disconnect', () => { console.log('User disconnected'); });}); const PORT = 3000;server.listen(PORT, () => { console.log(Server running on http://localhost:${PORT});});

Expected behavior

The bot joining the server like normal like before recent update Additional context

This bot was working perfectly fine before the 1.20.2 support update, and has remained completely unaltered when updating.

— Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/node-minecraft-protocol/issues/1274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAR437X5HEJCS2MAQRFXD6DYL5YCPAVCNFSM6AAAAABBHFUCZKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DANBZG43TKMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>