-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
Cannot read properties of undefined (reading 'overworld') #1274
Comments
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 <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":" @***@***.*** 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
<#1274>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAR437X5HEJCS2MAQRFXD6DYL5YCPAVCNFSM6AAAAABBHFUCZKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA3DANBZG43TKMQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
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.
The text was updated successfully, but these errors were encountered: