test
Browse files
index.js
ADDED
@@ -0,0 +1,101 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
const mineflayer = require('mineflayer')
|
2 |
+
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
|
3 |
+
const GoalBlock = goals.GoalBlock
|
4 |
+
|
5 |
+
console.log('= Bot Starting =')
|
6 |
+
|
7 |
+
let Botusername = 'Buse_AI';
|
8 |
+
|
9 |
+
const bot = mineflayer.createBot({
|
10 |
+
host: "xdrakensmp.aternos.me",
|
11 |
+
//port: 25565,
|
12 |
+
username: Botusername,
|
13 |
+
version: "1.21.4",
|
14 |
+
auth: 'offline'
|
15 |
+
});
|
16 |
+
|
17 |
+
const mcData = require('minecraft-data')(bot.version)
|
18 |
+
|
19 |
+
// Pathfinder plugin'ini yükle
|
20 |
+
bot.loadPlugin(pathfinder)
|
21 |
+
|
22 |
+
// Bot başlatıldığında
|
23 |
+
bot.once('spawn', () => {
|
24 |
+
console.log('Bot oyuna bağlandı!')
|
25 |
+
const defaultMove = new Movements(bot, mcData)
|
26 |
+
bot.pathfinder.setMovements(defaultMove)
|
27 |
+
})
|
28 |
+
|
29 |
+
// Tarla koordinatları (5x5)
|
30 |
+
const farmArea = {
|
31 |
+
start: { x: 591, y: 103, z: -2928 }, // 591 103 -2928
|
32 |
+
end: { x: 595, y: 103, z: -2936 } // 595 103 -2936
|
33 |
+
}
|
34 |
+
|
35 |
+
// Ekinleri kontrol et ve hasat et
|
36 |
+
async function checkAndHarvestCrops() {
|
37 |
+
|
38 |
+
for (let x = farmArea.start.x; x <= farmArea.end.x; x++) {
|
39 |
+
for (let z = farmArea.start.z; z <= farmArea.end.z; z++) {
|
40 |
+
const block = bot.blockAt(bot.vec3(x, farmArea.start.y, z))
|
41 |
+
|
42 |
+
if (!block) continue
|
43 |
+
|
44 |
+
// Buğday, havuç, patates gibi olgun ekinleri kontrol et
|
45 |
+
if (block.name === 'wheat' || block.name === 'carrots' || block.name === 'potatoes') {
|
46 |
+
if (block.metadata === 7) { // Olgun ekin
|
47 |
+
try {
|
48 |
+
await bot.pathfinder.goto(new GoalBlock(x, farmArea.start.y, z))
|
49 |
+
await bot.dig(block)
|
50 |
+
console.log(`${block.name} hasadı yapıldı!`)
|
51 |
+
|
52 |
+
// Yeniden ek
|
53 |
+
const seedItem = bot.inventory.items().find(item => {
|
54 |
+
return item.name === block.name + '_seeds' || item.name === block.name
|
55 |
+
})
|
56 |
+
|
57 |
+
if (seedItem) {
|
58 |
+
await bot.equip(seedItem, 'hand')
|
59 |
+
await bot.placeBlock(block, new bot.vec3(0, 1, 0)) // Yeni ek
|
60 |
+
console.log(`Yeni ${block.name} ekildi!`)
|
61 |
+
}
|
62 |
+
} catch (err) {
|
63 |
+
console.log(`Hata: ${err.message}`)
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
}
|
68 |
+
}
|
69 |
+
}
|
70 |
+
|
71 |
+
// Her 30 saniyede bir tarla kontrolü yap
|
72 |
+
setInterval(checkAndHarvestCrops, 10000)
|
73 |
+
|
74 |
+
// Debug için mesaj olaylarını dinle
|
75 |
+
bot.on('message', (message) => {
|
76 |
+
console.log('Mesaj alındı:', message.toString())
|
77 |
+
|
78 |
+
if (message.toString() === '1') {
|
79 |
+
console.log('1 komutu alındı')
|
80 |
+
bot.chat('Merhaba!')
|
81 |
+
}
|
82 |
+
|
83 |
+
if (message.toString() === 'hasat başlat') {
|
84 |
+
console.log('Hasat komutu alındı')
|
85 |
+
checkAndHarvestCrops()
|
86 |
+
bot.chat('Hasat başlatılıyor...')
|
87 |
+
}
|
88 |
+
})
|
89 |
+
|
90 |
+
// Hata yakalama
|
91 |
+
bot.on('error', (err) => {
|
92 |
+
console.log(`Bot hatası: ${err.message}`)
|
93 |
+
})
|
94 |
+
|
95 |
+
bot.on('kicked', (reason) => {
|
96 |
+
console.log(`Bot kicklendi: ${reason}`)
|
97 |
+
})
|
98 |
+
|
99 |
+
bot.on('end', () => {
|
100 |
+
console.log('Bot bağlantısı kesildi')
|
101 |
+
})
|