mindcraft/tasks/construction_tasks/get_blueprint.js

56 lines
2.1 KiB
JavaScript
Raw Normal View History

2025-04-04 13:49:12 -07:00
import mineflayer from 'mineflayer';
import { worldToBlueprint, blueprintToTask } from '../../src/agent/task_types/construction_tasks.js';
import fs from 'fs';
import { start } from 'repl';
const bot = mineflayer.createBot({
host: 'localhost', // Replace with your server IP or hostname
port: 55916, // Replace with your server port
username: 'andy', // Replace with your bot's username
// password: 'your_bot_password' // Only if the server has online-mode=true
});
bot.on('spawn', async () => {
console.log("Bot spawned. Starting blueprint check...");
// set this to be minX, minY, minZ
2025-04-04 13:49:12 -07:00
const startCoord = {
2025-04-10 14:04:55 -07:00
x: -124,
2025-04-04 13:49:12 -07:00
y: 1,
2025-04-10 14:04:55 -07:00
z: 133,
2025-04-04 13:49:12 -07:00
}
bot.chat(`/tp andy ${startCoord.x} ${startCoord.y} ${startCoord.z}`);
2025-04-10 14:04:55 -07:00
const yOffset = 2;
const xOffset = 30;
const zOffset = 20;
2025-04-04 13:49:12 -07:00
2025-04-10 14:04:55 -07:00
const taskFilePath = '/Users/isadorawhite/izzy_mindcraft/mindcraft/tasks/construction_tasks/custom/flower_three_agents.json';
const task_name = "flower_three_agents";
2025-04-04 13:49:12 -07:00
setTimeout(async () => {
let task_blueprint = await worldToBlueprint(startCoord, yOffset, xOffset, zOffset, bot);
2025-04-09 16:34:11 -07:00
for (let i = 0; i < task_blueprint.levels.length; i++) {
2025-04-04 13:49:12 -07:00
// Perform operations on each level
2025-04-09 16:34:11 -07:00
const level = task_blueprint.levels[i];
2025-04-04 13:49:12 -07:00
console.log("Level coordinates:", level.coordinates);
2025-04-09 16:34:11 -07:00
const new_coordinates = [level.coordinates[0], -60 + i, level.coordinates[2]];
2025-04-04 13:49:12 -07:00
level.coordinates = new_coordinates;
console.log("New coordinates:", level.coordinates);
}
console.log("Blueprint generated:", task_blueprint.levels[0].coordinates);
2025-04-09 16:34:11 -07:00
const task = blueprintToTask(task_blueprint, 3);
2025-04-04 13:49:12 -07:00
const task_collection = {}
task_collection[task_name] = task;
fs.writeFileSync(taskFilePath, JSON.stringify(task_collection, null, 2), (err) => {
if (err) {
console.error('Error writing task to file:', err);
} else {
console.log('Task dumped to file successfully.');
}
});
}, 5000); // Delay of 5 seconds (5000 milliseconds)
});