-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
70 lines (54 loc) · 2.17 KB
/
main.js
File metadata and controls
70 lines (54 loc) · 2.17 KB
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
const mineflayer = require('mineflayer')
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
const bot = mineflayer.createBot({
host: 'localhost',
port: 41351,
username: 'Adolfhitler',
})
bot.loadPlugin(pathfinder)
// Fonction principale qui s'auto-appelle pour miner en boucle
async function mineLoop() {
const mcData = require('minecraft-data')(bot.version)
// 1. Chercher le bloc le plus proche (Stone ou Deepslate)
const targetBlock = bot.findBlock({
matching: (block) => block.name === 'oak_log',
maxDistance: 320
})
if (!targetBlock) {
console.log("Aucune pierre trouvée. Je cherche plus loin dans 2 secondes...")
setTimeout(mineLoop, 2000)
return
}
console.log(`Cible identifiée en ${targetBlock.position}`)
try {
// 2. Se déplacer jusqu'à être à portée de minage
// GoalLookAtBlock est parfait pour ça
await bot.pathfinder.goto(new goals.GoalLookAtBlock(targetBlock.position, bot.world))
// 3. Équiper le meilleur outil disponible pour ce bloc
// Indispensable pour ne pas miner à la main pendant 10 ans !
const tool = bot.pathfinder.bestHarvestTool(targetBlock)
if (tool) {
await bot.equip(tool, 'hand')
}
// 4. Regarder le centre du bloc et miner
await bot.lookAt(targetBlock.position.offset(0.5, 0.5, 0.5))
// On attend que le minage soit fini
await bot.dig(targetBlock)
console.log("Bloc miné !")
// 5. Recommencer immédiatement
mineLoop()
} catch (err) {
console.log("Erreur (chemin bloqué ou interruption) :", err.message)
// Petite pause en cas d'erreur pour éviter de spammer la console
setTimeout(mineLoop, 1000)
}
}
bot.once('spawn', () => {
const mcData = require('minecraft-data')(bot.version)
// Configuration des mouvements (sauter, monter des escaliers, etc.)
const defaultMove = new Movements(bot, mcData)
bot.pathfinder.setMovements(defaultMove)
console.log("Bot en place, début du travail...")
// Lancement de la première boucle
mineLoop()
})