This commit is contained in:
2025-05-04 19:22:31 -04:00
parent ddc6f2d167
commit 7c26d2f0a3
15 changed files with 958 additions and 318 deletions

View File

@ -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);
}
}