You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
5.1 KiB
164 lines
5.1 KiB
const mineflayer = require('mineflayer')
|
|
const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
|
|
const GoalFollow = goals.GoalFollow
|
|
const GoalBlock = goals.GoalBlock
|
|
const { Vec3 } = require('vec3')
|
|
const autoeat = require("mineflayer-auto-eat")
|
|
|
|
// to add forge modules https://github.com/PrismarineJS/mineflayer/pull/472
|
|
|
|
const options = {
|
|
host: "127.0.0.1",
|
|
port: 50500,
|
|
username: 'V5-Bot'
|
|
}
|
|
|
|
var mc = require('minecraft-protocol');
|
|
var autoVersionForge = require('minecraft-protocol-forge').autoVersionForge;
|
|
var client = mc.createClient(options);
|
|
|
|
autoVersionForge(client);
|
|
|
|
const bot = mineflayer.createBot(options)
|
|
bot.loadPlugin(pathfinder)
|
|
bot.loadPlugin(autoeat)
|
|
|
|
function delay(time) { // delay function
|
|
return new Promise(resolve => setTimeout(resolve, time));
|
|
}
|
|
|
|
function followPlayer(username){
|
|
const playerToFollow = bot.players[username]
|
|
/*if (!playerFH) {
|
|
bot.chat(`I can't see ${playerFH} !`)
|
|
return
|
|
}*/
|
|
const mcData = require('minecraft-data')(bot.version)
|
|
const movements = new Movements(bot, mcData)
|
|
movements.scafoldingBlocks = []
|
|
bot.pathfinder.setMovements(movements)
|
|
const goal = new GoalFollow(playerToFollow.entity, 2)
|
|
bot.pathfinder.setGoal(goal, true) // true # for checking Goal position each frame
|
|
}
|
|
|
|
function locateEmeraldBlock(){
|
|
const mcData = require('minecraft-data')(bot.version)
|
|
const movements = new Movements(bot, mcData)
|
|
movements.scafoldingBlocks = []
|
|
bot.pathfinder.setMovements(movements)
|
|
const emeraldBlock = bot.findBlock({
|
|
matching: mcData.blocksByName.emerald_block.id,
|
|
maxDistance: 32
|
|
})
|
|
|
|
if (!emeraldBlock){
|
|
bot.chat("I can't see any emerald blocks!")
|
|
return
|
|
}
|
|
const x = emeraldBlock.position.x
|
|
const y = emeraldBlock.position.y + 1
|
|
const z = emeraldBlock.position.z
|
|
const goal = new GoalBlock(x, y, z)
|
|
bot.pathfinder.setGoal(goal)
|
|
}
|
|
|
|
function lightUp() {
|
|
const mcData = require('minecraft-data')(bot.version)
|
|
const movements = new Movements(bot, mcData)
|
|
movements.scafoldingBlocks = []
|
|
bot.pathfinder.setMovements(movements)
|
|
|
|
const isAir = bot.findBlock({
|
|
matching: mcData.blocksByName.air.id,
|
|
maxDistance: 32
|
|
})
|
|
const x = isAir.position.x
|
|
const y = isAir.position.y - 1
|
|
const z = isAir.position.z
|
|
const potentialLightableBlock = bot.blockAt({
|
|
x,
|
|
y,
|
|
z
|
|
})
|
|
if (potentialLightableBlock.transparent === false && isAir.light <= 7){
|
|
bot.equip(bot.inventory.findInventoryItem('torch'))
|
|
bot.placeBlock('torch',isAir.position)
|
|
}
|
|
}
|
|
|
|
|
|
bot.once('spawn', () => {
|
|
bot.chat('I am connected')
|
|
//delay(1000).then(() => bot.chat("...And I am The Bot."));
|
|
|
|
bot.autoEat.options = {
|
|
priority: "foodPoints",
|
|
bannedFood: ['beetroot', 'cake', 'carrot', 'chorus_fruit', 'golden_carrot', 'honey_bottle', 'poisonous_potato', 'potato', 'pufferfish', 'beef', 'chicken', 'cod', 'mutton', 'porkchop', 'rabbit', 'salmon', 'rotten_flesh', 'spider_eye', 'suspicious_stew', 'sweet_berries', 'tropical_fish', "golden_apple", "enchanted_golden_apple"],
|
|
eatingTimeout: 2
|
|
}
|
|
|
|
setInterval(() => {
|
|
if (bot.health >=6){
|
|
const mobFilter = e => (e.type === 'mob' && (e.mobType === 'Slime' || e.mobType === 'Zombie' || e.mobType === 'Spider'))
|
|
const mob = bot.nearestEntity(mobFilter)
|
|
if (!mob) return
|
|
const pos = mob.position.offset(0,mob.height,0)
|
|
const dist = pos.distanceTo(bot.entity.position)
|
|
bot.lookAt(pos, true)
|
|
if (dist >= 20) return
|
|
if (dist <= 10 && bot.inventory.findInventoryItem('diamond_sword')) {
|
|
bot.equip(bot.inventory.findInventoryItem('diamond_sword'))
|
|
}
|
|
//console.log(dist)
|
|
if (dist <= 5){
|
|
bot.attack(mob)
|
|
}// else{
|
|
// console.log('is not Fighting')
|
|
//}
|
|
}
|
|
}, 800)
|
|
})
|
|
|
|
bot.on("autoeat_started", () => {
|
|
console.log("Auto Eat started!")
|
|
})
|
|
|
|
bot.on("autoeat_stopped", () => {
|
|
console.log("Auto Eat stopped!")
|
|
bot.sw
|
|
})
|
|
|
|
bot.on("health", () => {
|
|
if (bot.food === 20) bot.autoEat.disable()
|
|
// Disable the plugin if the bot is at 20 food points
|
|
else bot.autoEat.enable() // Else enable the plugin again
|
|
})
|
|
|
|
bot.on('chat', (username, message) => {
|
|
|
|
if (message === 'hi') bot.chat(`Hi ${username}!`);
|
|
if (message === (`${bot.username} off`)){
|
|
bot.chat(`Bye ${username}!`)
|
|
bot.quit()
|
|
}
|
|
if (message === 'bot spawnpoint') {
|
|
bot.chat(`${bot.spawnPoint.x} ${bot.spawnPoint.y} ${bot.spawnPoint.z}`)
|
|
}
|
|
if (message === 'bot follow me') {
|
|
followPlayer(username)
|
|
}
|
|
if (message === 'bot stop follow') {
|
|
bot.chat(`CU later ${username}`)
|
|
bot.pathfinder.stop()
|
|
}
|
|
if (message === 'bot find emerald block') {
|
|
locateEmeraldBlock()
|
|
}
|
|
if (message === 'bot light up') {
|
|
lightUp()
|
|
}
|
|
/*if (message === 'bot stop find') {
|
|
bot.chat(`Ok...`)
|
|
bot.pathfinder.stop()
|
|
}*/
|
|
})
|