Replies: 1 comment
-
SOLVEDI ASKED THE MITHICAL GPT AND HE DID IT (We all getting replaced 😭) Here's the code:const mine_flayer = require("mineflayer");
// Create bot
const bot = mine_flayer.createBot({
host: 'localhost',
port: 25565,
username: 'runCommandBot'
});
// On spawn event
bot.once("spawn", () => {
// Add a custom chat pattern to detect "Counted: <number>" messages
bot.chatAddPattern(
/^Counted: (\d+)/,
"GetCounted",
"Run when there's a count on chat"
);
// Start counting diamond ores when the bot spawns
countDiamondOres();
});
// Handler to log the count
const get_count = (rank, username, message) => {
console.log(`Diamond Ore Count: ${message}`);
};
// Function to count diamond ores
function countDiamondOres() {
// Array with number of chunk radius
const chunkSizes = [4, 6, 8, 12, 16];
// Iterate through the radius array
let chunkIndex = 0;
let y = 1;
// Recursive function to go through each chunk size and Y-level
function processNextChunk() {
if (chunkIndex >= chunkSizes.length) {
console.log("Finished counting diamond ores.");
return;
}
let x = chunkSizes[chunkIndex] * 16;
// Run commands for current Y level
bot.chat(`//pos1 ${x - 1},${y},${x - 1}`); // Sets 1st position
bot.chat(`//pos2 -${x},${y},-${x}`); // Sets 2nd position
bot.chat(`//count diamond_ore`); // Counts diamond_ore on the range given
// Print position
console.log(`Checking position: (${x},${y},${x})`);
// Listen for the count result
bot.once('GetCounted', (count) => {
console.log(`Diamond ores found: ${count}`);
// Move to the next Y level
y++;
if (y > 16) {
y = 1;
chunkIndex++;
}
// Continue to the next chunk or Y level after a short delay
setTimeout(processNextChunk, 1000); // 1 second delay to avoid flooding
});
}
// Start processing chunks
processNextChunk();
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Im doing a bot that can run a command (right now, is //pos1, //pos2 and //count from WorldEdit to count diamond ores)
This is my code right now:
The bot works as intended, it runs the command and it then logs the server answer for the //count in the console, but there are two probelms with the console logs:
console.log(``(${x},${y},${x}):``);
(line 44) is not executing on each iteration for some reason, it runs all at the beginning.bot.on('GetCounted', get_count);
(line 45) is running 75 times per iteration, resulting into 5625 outputs instead of the expected 75.I am not a JavaScript guy, so there might be some concepts im lacking off and things I might have done wrong, thats why im here to ask what is going wrong on here.
Thanks for the help.
Beta Was this translation helpful? Give feedback.
All reactions