File size: 2,829 Bytes
0dac627 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
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",
//port: 25565,
username: Botusername,
version: "1.21.4",
auth: 'offline'
});
const mcData = require('minecraft-data')(bot.version)
// Pathfinder plugin'ini yükle
bot.loadPlugin(pathfinder)
// Bot başlatıldığında
bot.once('spawn', () => {
console.log('Bot oyuna bağlandı!')
const defaultMove = new Movements(bot, mcData)
bot.pathfinder.setMovements(defaultMove)
})
// Tarla koordinatları (5x5)
const farmArea = {
start: { x: 591, y: 103, z: -2928 }, // 591 103 -2928
end: { x: 595, y: 103, z: -2936 } // 595 103 -2936
}
// Ekinleri kontrol et ve hasat et
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
// Buğday, havuç, patates gibi olgun ekinleri kontrol et
if (block.name === 'wheat' || block.name === 'carrots' || block.name === 'potatoes') {
if (block.metadata === 7) { // Olgun ekin
try {
await bot.pathfinder.goto(new GoalBlock(x, farmArea.start.y, z))
await bot.dig(block)
console.log(`${block.name} hasadı yapıldı!`)
// Yeniden ek
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)) // Yeni ek
console.log(`Yeni ${block.name} ekildi!`)
}
} catch (err) {
console.log(`Hata: ${err.message}`)
}
}
}
}
}
}
// Her 30 saniyede bir tarla kontrolü yap
setInterval(checkAndHarvestCrops, 10000)
// Debug için mesaj olaylarını dinle
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...')
}
})
// Hata yakalama
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')
}) |