102 lines
2.2 KiB
JavaScript
102 lines
2.2 KiB
JavaScript
const mc = require('minecraft-protocol');
|
|
|
|
const bot = mc.createClient({
|
|
host: 'kaboom.pw',
|
|
//host: 'chipmunk.land',
|
|
port: 25565,
|
|
username: "Position",
|
|
version: '1.20.4',
|
|
});
|
|
|
|
bot.position = { x: 0, y: 0, z: 0 }
|
|
|
|
bot.on('login', () => {
|
|
console.log('Bot Spawn!') // very basic
|
|
setInterval(() => {
|
|
bot.chat(`Now Pos: ${bot.position.x} ${bot.position.y} ${bot.position.z}`);
|
|
}, 1000);
|
|
});
|
|
|
|
bot.on('error', (error) => {
|
|
console.log(error);
|
|
});
|
|
|
|
bot.on("position", (packet) => {
|
|
bot.chat(`Pos: ${packet.x} ${packet.y} ${packet.z} Flags: ${packet.flags}`);
|
|
|
|
// different movement flags
|
|
switch (packet.flags) {
|
|
case 31: // Move on x, y, z
|
|
bot.position = {
|
|
x: bot.position.x + packet.x,
|
|
y: bot.position.y + packet.y,
|
|
z: bot.position.z + packet.z
|
|
};
|
|
break;
|
|
|
|
case 30: // Move on y, z
|
|
bot.position = {
|
|
x: packet.x,
|
|
y: bot.position.y + packet.y,
|
|
z: bot.position.z + packet.z
|
|
};
|
|
break;
|
|
|
|
case 29: // Move on x, z
|
|
bot.position = {
|
|
x: bot.position.x + packet.x,
|
|
y: packet.y,
|
|
z: bot.position.z + packet.z
|
|
};
|
|
break;
|
|
|
|
case 28: // Move on z
|
|
bot.position = {
|
|
x: packet.x,
|
|
y: packet.y,
|
|
z: bot.position.z + packet.z
|
|
};
|
|
break;
|
|
|
|
case 27: // Move on x, y
|
|
bot.position = {
|
|
x: bot.position.x + packet.x,
|
|
y: bot.position.y + packet.y,
|
|
z: packet.z
|
|
};
|
|
break;
|
|
|
|
case 26: // Move on y
|
|
bot.position = {
|
|
x: packet.x,
|
|
y: bot.position.y + packet.y,
|
|
z: packet.z
|
|
};
|
|
break;
|
|
|
|
case 25: // Move on x
|
|
bot.position = {
|
|
x: bot.position.x + packet.x,
|
|
y: packet.y,
|
|
z: packet.z
|
|
};
|
|
break;
|
|
case 24:
|
|
case 0:
|
|
bot.position = {
|
|
x: packet.x,
|
|
y: packet.y,
|
|
z: packet.z
|
|
};
|
|
break;
|
|
default: // Full teleport, no movement
|
|
|
|
bot.position = {
|
|
x: packet.x,
|
|
y: packet.y,
|
|
z: packet.z
|
|
};
|
|
|
|
// throw new Error(`Invaild flags: ${packet.flags}`) // i think this should work...
|
|
}
|
|
});
|