idk
This commit is contained in:
@ -3,6 +3,14 @@
|
||||
const conf = require('../conf');
|
||||
const {sleep} = require('../utils');
|
||||
|
||||
|
||||
function faceEntity(bot, entity) {
|
||||
if (!entity) return; // Check if entity is valid
|
||||
|
||||
const targetPosition = entity.position.offset(0, entity.height * 0.5, 0); // Focus on the middle of the entity
|
||||
bot.bot.lookAt(targetPosition);
|
||||
}
|
||||
|
||||
class Swing{
|
||||
constructor(args){
|
||||
this.bot = args.bot;
|
||||
@ -29,6 +37,7 @@ class Swing{
|
||||
}
|
||||
|
||||
unload(){
|
||||
console.log('Swing.unload');
|
||||
clearInterval(this.intervalStop);
|
||||
this.intervalStop = null;
|
||||
this.onReadyListen();
|
||||
@ -46,14 +55,19 @@ class Swing{
|
||||
async swing(){
|
||||
this.intervalStop = setInterval(async ()=>{
|
||||
try{
|
||||
// console.log('attacking');
|
||||
await this.bot.bot.attack(
|
||||
this.bot.bot.nearestEntity(
|
||||
entity => entity.name.toLowerCase() === 'guardian'
|
||||
)
|
||||
);
|
||||
}catch(error){}
|
||||
}, 1010);
|
||||
let entity = this.bot.bot.nearestEntity(entity =>{
|
||||
// console.log('looking for entity name', entity.name, entity.name?.toLowerCase());
|
||||
return entity.name?.toLowerCase() === "guardian"
|
||||
});
|
||||
|
||||
if(entity && this.bot.isWithinRange(entity.position, 3)){
|
||||
faceEntity(this.bot, entity);
|
||||
await this.bot.bot.attack(entity);
|
||||
}
|
||||
}catch(error){
|
||||
console.log('Swing.swing interval error:', error);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user