bot.js
Anonymous
JavaScript
10/15/2025 7:41 PM
1.5 KB
31
Indexable
Never
const mineflayer = require("mineflayer");
const readline = require("readline");
var isDigging = false;
async function dig() {
if (!isDigging) return;
if (bot.targetDigBlock != null) return;
const block = bot.blockAtCursor();
if (!block || !bot.canDigBlock(block)) return;
try {
await bot.dig(block);
} catch (error) {
if (error.message !== 'Digging aborted') console.error(error);
}
}
async function look(yaw, pitch) {
bot.off('physicsTick', dig);
await bot.look(yaw, pitch);
bot.on('physicsTick', dig);
}
const bot = mineflayer.createBot({
host: "localhost",
port: 25565,
username: 'player',
auth: 'offline',
version: "1.20.1",
});
bot.on('error', console.error);
bot.once('login', () => console.log('Logged in'));
bot.on('spawn', async () => { await bot.look(bot.entity.yaw, 0, true) });
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.on("line", (input) => {
const [ cmd, ...args ] = input.split(' ');
if (cmd === 'dig') {
isDigging = !isDigging;
if (isDigging) {
bot.on('physicsTick', dig);
console.log('Digging enabled');
}
else {
bot.off('physicsTick', dig);
console.log('Digging disabled');
}
} else if (cmd === 'look') {
if (args.length != 2) {
console.log('Usage: look <yaw> <pitch>');
return;
}
const yaw = args[0];
const pitch = args[1];
look(yaw, pitch)
}
});
Editor is loading...
Leave a Comment