|
|
const mineflayer = require('mineflayer') |
|
|
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder') |
|
|
const GoalBlock = goals.GoalBlock |
|
|
|
|
|
console.log('= Bot Starting =') |
|
|
|
|
|
let Botusername = 'Buse_AI'; |
|
|
|
|
|
const bot = mineflayer.createBot({ |
|
|
host: "xdrakensmp.aternos.me", |
|
|
|
|
|
username: Botusername, |
|
|
version: "1.21.4", |
|
|
auth: 'offline' |
|
|
}); |
|
|
|
|
|
const mcData = require('minecraft-data')(bot.version) |
|
|
|
|
|
|
|
|
bot.loadPlugin(pathfinder) |
|
|
|
|
|
|
|
|
bot.once('spawn', () => { |
|
|
console.log('Bot oyuna bağlandı!') |
|
|
const defaultMove = new Movements(bot, mcData) |
|
|
bot.pathfinder.setMovements(defaultMove) |
|
|
}) |
|
|
|
|
|
|
|
|
const farmArea = { |
|
|
start: { x: 591, y: 103, z: -2928 }, |
|
|
end: { x: 595, y: 103, z: -2936 } |
|
|
} |
|
|
|
|
|
|
|
|
async function checkAndHarvestCrops() { |
|
|
|
|
|
for (let x = farmArea.start.x; x <= farmArea.end.x; x++) { |
|
|
for (let z = farmArea.start.z; z <= farmArea.end.z; z++) { |
|
|
const block = bot.blockAt(bot.vec3(x, farmArea.start.y, z)) |
|
|
|
|
|
if (!block) continue |
|
|
|
|
|
|
|
|
if (block.name === 'wheat' || block.name === 'carrots' || block.name === 'potatoes') { |
|
|
if (block.metadata === 7) { |
|
|
try { |
|
|
await bot.pathfinder.goto(new GoalBlock(x, farmArea.start.y, z)) |
|
|
await bot.dig(block) |
|
|
console.log(`${block.name} hasadı yapıldı!`) |
|
|
|
|
|
|
|
|
const seedItem = bot.inventory.items().find(item => { |
|
|
return item.name === block.name + '_seeds' || item.name === block.name |
|
|
}) |
|
|
|
|
|
if (seedItem) { |
|
|
await bot.equip(seedItem, 'hand') |
|
|
await bot.placeBlock(block, new bot.vec3(0, 1, 0)) |
|
|
console.log(`Yeni ${block.name} ekildi!`) |
|
|
} |
|
|
} catch (err) { |
|
|
console.log(`Hata: ${err.message}`) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
setInterval(checkAndHarvestCrops, 10000) |
|
|
|
|
|
|
|
|
bot.on('message', (message) => { |
|
|
console.log('Mesaj alındı:', message.toString()) |
|
|
|
|
|
if (message.toString() === '1') { |
|
|
console.log('1 komutu alındı') |
|
|
bot.chat('Merhaba!') |
|
|
} |
|
|
|
|
|
if (message.toString() === 'hasat başlat') { |
|
|
console.log('Hasat komutu alındı') |
|
|
checkAndHarvestCrops() |
|
|
bot.chat('Hasat başlatılıyor...') |
|
|
} |
|
|
}) |
|
|
|
|
|
|
|
|
bot.on('error', (err) => { |
|
|
console.log(`Bot hatası: ${err.message}`) |
|
|
}) |
|
|
|
|
|
bot.on('kicked', (reason) => { |
|
|
console.log(`Bot kicklendi: ${reason}`) |
|
|
}) |
|
|
|
|
|
bot.on('end', () => { |
|
|
console.log('Bot bağlantısı kesildi') |
|
|
}) |