forked from wmantly/mc-bot-town
		
	idk
This commit is contained in:
		| @ -24,10 +24,9 @@ class Ai{ | ||||
| 	} | ||||
|  | ||||
| 	async init(){ | ||||
| 		await this.start(); | ||||
| 		this.bot.on('onReady', async (argument)=>{ | ||||
| 			try{ | ||||
| 				await sleep(1000); | ||||
| 				await this.start(); | ||||
| 				let messages = ['']; | ||||
|  | ||||
| 				this.messageListener = this.bot.on('message', (message, type)=>{ | ||||
|  | ||||
| @ -101,6 +101,23 @@ module.exports =  { | ||||
| 			this.whisper(from, '?') | ||||
| 		} | ||||
| 	}, | ||||
| 	'come': { | ||||
| 		desc: `make bot come to you`, | ||||
| 		allowed: ['wmantly', 'useless666', 'tux4242'], | ||||
| 		async function(from, playerName){ | ||||
| 			const player = this.bot.players[playerName || from]; | ||||
|  | ||||
| 			if (!player || !player.entity) { | ||||
| 				this.whisper(from, `I can't see ${player}.`); | ||||
|  | ||||
| 				return; | ||||
| 			} | ||||
|  | ||||
| 			this.whisper(from, `Going to ${player}`); | ||||
| 			this.goTo({where: player.entity.position}); | ||||
|  | ||||
| 		} | ||||
| 	}, | ||||
|  | ||||
| 	'logon': { | ||||
| 		desc: `Have bot log on for 10 seconds'`, | ||||
|  | ||||
| @ -27,6 +27,11 @@ let sites = { | ||||
| 		desc: `Get an invite to the Farming outpost.`, | ||||
| 		allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', 'nootbot', 'VinceNL', 'Ethan63020', 'Ethan63021', 'KimiKava', 'kawiimeowz', 'RaindropCake24', 'AndyNyg', 'AndyNyg_II'], | ||||
| 	}, | ||||
| 	mega:{ | ||||
| 	        bot: 'ayay', | ||||
| 	        desc: `Get an invite to the Farming outpost 2.`, | ||||
| 	        allowed: ['wmantly', 'useless666', 'tux4242', 'pi_chef', '1_cut', '__Ethan63020', '__Ethan63021', 'VinceNL', 'nootbot'], | ||||
| 	}, | ||||
| 	guardian: { | ||||
| 		bot: 'art', | ||||
| 		desc: 'blah', | ||||
|  | ||||
							
								
								
									
										201
									
								
								nodejs/controller/craft_chests.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										201
									
								
								nodejs/controller/craft_chests.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,201 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const conf = require('../conf'); | ||||
| const {sleep, nextTick} = require('../utils'); | ||||
|  | ||||
| class CraftChests{ | ||||
| 	constructor(args){ | ||||
| 		this.bot = args.bot; | ||||
| 		this.interval = args.interval; | ||||
| 		this.target = args.target; | ||||
| 		this.intervalStop; | ||||
| 		this.isAction = true; | ||||
| 	} | ||||
|  | ||||
| 	init(){ | ||||
| 		return new Promise(async (resolve, reject)=>{ | ||||
| 			this.bot.on('onReady', async ()=>{ | ||||
| 				try{ | ||||
| 					await sleep(500); | ||||
| 					await this.bot.goTo({ | ||||
| 						where: this.bot.findBlockBySign('bot walk 2').position, | ||||
| 						range: 0, | ||||
| 					}); | ||||
|  | ||||
| 					await this.bot.goTo({ | ||||
| 						where: this.bot.findBlockBySign('bot walk 1').position, | ||||
| 						range: 0, | ||||
| 					}); | ||||
|  | ||||
| 					await this.bot.goTo({ | ||||
| 						where: this.bot.findBlockBySign('bot walk 2').position, | ||||
| 						range: 0, | ||||
| 					}); | ||||
|  | ||||
| 					let hasItems = await this.getItems(); | ||||
|  | ||||
| 					// while(hasItems){ | ||||
| 					// 	await this.craft(); | ||||
| 					// 	hasItems = await this.getItems(); | ||||
| 					// } | ||||
|  | ||||
| 					return resolve(); | ||||
|  | ||||
| 				}catch(error){ | ||||
| 					reject(error); | ||||
| 				} | ||||
|  | ||||
| 			});			 | ||||
| 		}); | ||||
| 	} | ||||
|  | ||||
| 	unload(){ | ||||
| 		if(this.intervalStop){ | ||||
| 			clearInterval(this.intervalStop); | ||||
| 			this.intervalStop = undefined; | ||||
| 		} | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	async getItems(){ | ||||
| 		/*clear inventory*/ | ||||
| 		await this.bot.goTo({ | ||||
| 			where: this.bot.findChestBySign('bot dump'), | ||||
| 			range: 2, | ||||
| 		}) | ||||
| 		await this.bot.dumpToChest(this.bot.findChestBySign('bot dump')); | ||||
|  | ||||
|  | ||||
| 		/*  | ||||
| 		Bamboo | ||||
| 		*/ | ||||
| 		let packed_bambooChest = this.bot.findChestBySign('packed bamboo'); | ||||
| 		await this.bot.goTo({ | ||||
| 			where: packed_bambooChest.position, | ||||
| 			range: 2, | ||||
| 		}); | ||||
|  | ||||
|  | ||||
| 		await this.bot.getFullShulkersFromChest(packed_bambooChest, 'bamboo'); | ||||
|  | ||||
| 		return; | ||||
|  | ||||
|  | ||||
| 		let hasShard = await this.bot.checkItemsFromContainer( | ||||
| 			prismarine_shardChest, 'prismarine_shard', 64*4 | ||||
| 		); | ||||
|  | ||||
| 		/* | ||||
| 		crystals | ||||
| 		*/ | ||||
| 		let prismarine_crystalsChest = this.bot.findChestBySign('crystals'); | ||||
| 		await this.bot.goTo({ | ||||
| 			where: prismarine_crystalsChest.position, | ||||
| 			range: 2, | ||||
| 		}); | ||||
|  | ||||
| 		let hasCrystals = await this.bot.checkItemsFromContainer( | ||||
| 			prismarine_crystalsChest, 'prismarine_crystals', 64*5 | ||||
| 		); | ||||
|  | ||||
| 		if(!hasShard || !hasCrystals) return false; | ||||
|  | ||||
| 		/* | ||||
| 		get | ||||
| 		*/ | ||||
| 		await sleep(3000); | ||||
|  | ||||
| 		await this.bot.getItemsFromChest( | ||||
| 			prismarine_shardChest, 'prismarine_shard', 64*4 | ||||
| 		); | ||||
| 		await sleep(1000); | ||||
|  | ||||
| 		await this.bot.getItemsFromChest( | ||||
| 			prismarine_crystalsChest, 'prismarine_crystals', 64*5 | ||||
| 		); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	async craft(){ | ||||
|  | ||||
| 		// Ensure the bot has enough items (4 shards and 5 crystals for 1 lantern) | ||||
| 		let prismarineShardsCount = this.bot.bot.inventory.count(this.bot.mcData.itemsByName.prismarine_shard.id); | ||||
| 		let prismarineCrystalsCount = this.bot.bot.inventory.count(this.bot.mcData.itemsByName.prismarine_crystals.id); | ||||
|  | ||||
| 		if(prismarineShardsCount < 4 || prismarineCrystalsCount < 5){ | ||||
| 		  console.log("Not enough materials to craft 64 Sea Lanterns."); | ||||
| 		  return; | ||||
| 		}else{ | ||||
| 			console.log('good to make sea_lantern!'); | ||||
| 		} | ||||
|  | ||||
| 		// Hold onto the closest crafting table | ||||
| 		let craftingTable = this.bot.bot.findBlock({ | ||||
| 			matching: this.bot.mcData.blocksByName.crafting_table.id, | ||||
| 			maxDistance: 64 | ||||
| 		}); | ||||
|  | ||||
| 		await this.bot.goTo({ | ||||
| 			where: craftingTable.position, | ||||
| 			range: 1, | ||||
| 		}); | ||||
|  | ||||
| 		// Hold onto the recipe | ||||
| 		let recipe = this.bot.bot.recipesAll( | ||||
| 			this.bot.mcData.itemsByName.sea_lantern.id, | ||||
| 			null, | ||||
| 			craftingTable | ||||
| 		)[0]; | ||||
|  | ||||
| 		let window = await this.bot.openCraftingTable(craftingTable); | ||||
|  | ||||
| 		// Move these into openCrating function | ||||
| 		let windowOnce = (event)=> new Promise((resolve, reject)=> window.once(event, resolve)); | ||||
| 		let inventory = ()=> window.slots.slice(window.inventoryStart, window.inventoryEnd) | ||||
|  | ||||
| 		// Move the items into the crafting grid | ||||
| 		let slotCount = 1; | ||||
| 		for(let shapeRow of recipe.inShape){ | ||||
| 			for(let shape of shapeRow){ | ||||
| 				this.bot.bot.moveSlotItem( | ||||
| 					inventory().find((element)=> element && element.type === shape.id).slot, | ||||
| 					slotCount | ||||
| 				); | ||||
| 				await windowOnce(`updateSlot:${slotCount}`); | ||||
| 				slotCount++; | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		// Wait for the server to catch up. | ||||
| 		await sleep(500); | ||||
|  | ||||
| 		// Craft each item until all are gone. | ||||
| 		let craftedCount = 0; | ||||
| 		while(window.slots[0]){ | ||||
| 			await this.bot.bot.moveSlotItem( | ||||
| 				window.craftingResultSlot, | ||||
| 				38 // dont hard code this!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||||
| 			); | ||||
| 			craftedCount++; | ||||
| 			await windowOnce(`updateSlot:0`); | ||||
| 			await sleep(50); // wait for the client to catchup | ||||
| 		} | ||||
|  | ||||
| 		await window.close(); | ||||
|  | ||||
| 		/* | ||||
| 		Dump items to chest | ||||
| 		*/ | ||||
|  | ||||
| 		let seaLanternChest = this.bot.findChestBySign('sea_lantern'); | ||||
| 		await this.bot.goTo({ | ||||
| 			where: seaLanternChest.position, | ||||
| 			range: 4, | ||||
| 		}); | ||||
|  | ||||
| 		await this.bot.dumpToChest(seaLanternChest, 'sea_lantern') | ||||
| 	} | ||||
| } | ||||
|  | ||||
| module.exports = CraftChests; | ||||
							
								
								
									
										165
									
								
								nodejs/controller/goldFarm.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										165
									
								
								nodejs/controller/goldFarm.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,165 @@ | ||||
| 'use strict'; | ||||
|  | ||||
| const conf = require('../conf'); | ||||
| const {sleep} = require('../utils'); | ||||
|  | ||||
|  | ||||
| async function throwSnowballAtEntity(bot, entity) { | ||||
| 	const snowballItem = bot.bot.inventory.items().find(item => item.name === 'snowball'); | ||||
|  | ||||
| 	if (!snowballItem) { | ||||
| 		console.log("No snowballs in inventory."); | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	// Equip the snowball | ||||
| 	try{ | ||||
| 		await bot.bot.equip(snowballItem, 'hand') | ||||
|  | ||||
| 		let tossAt = bot.findBlockBySign('bot balls'); | ||||
| 		// Simulate throwing a snowball | ||||
| /*		const nearestHayBlock = bot.bot.findBlock({ | ||||
| 			useExtraInfo: true, | ||||
| 			maxDistance: 64, | ||||
| 			matching: (block)=>block.name.includes('hay'), | ||||
| 		}); | ||||
| 		if (nearestHayBlock){ | ||||
| 		}*/ | ||||
|  | ||||
| 		await bot.bot.lookAt(tossAt.position.offset(0, -2, 0)); | ||||
| 		await sleep(150); | ||||
| 		bot.bot.activateItem(); // This would simulate the throw of the snowball | ||||
| 		await sleep(200); | ||||
| 		bot.bot.activateItem(); // This would simulate the throw of the snowball | ||||
| 		await sleep(300); | ||||
| 		bot.bot.activateItem(); // This would simulate the throw of the snowball | ||||
|  | ||||
| 	}catch(error){ | ||||
| 		console.log('GoldFarm.throwSnowballAtEntity error', error); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function getNearestEntityInDirection(bot, direction, entityType) { | ||||
|     const entities = Object.values(bot.entities).filter(entity =>  | ||||
|         entity.position && entity !== bot.entity && entity.name === entityType | ||||
|     ); | ||||
|     let nearestEntity = null; | ||||
|     let minDistance = Infinity; | ||||
|      | ||||
|     for (const entity of entities) { | ||||
|         const relativePos = entity.position.minus(bot.entity.position); | ||||
|         const angle = Math.atan2(relativePos.x, relativePos.z); | ||||
|         const targetAngle = direction * (Math.PI / 180); | ||||
|         const angleDiff = Math.abs(angle - targetAngle); | ||||
|          | ||||
|         if (angleDiff < Math.PI / 8) {  | ||||
|             const distance = bot.entity.position.distanceTo(entity.position); | ||||
|             if (distance < minDistance) { | ||||
|                 minDistance = distance; | ||||
|                 nearestEntity = entity; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|     return nearestEntity; | ||||
| } | ||||
|  | ||||
| class GoldFarm{ | ||||
| 	location = {}; | ||||
|  | ||||
| 	constructor(args){ | ||||
| 		this.bot = args.bot; | ||||
| 		this.target = args.target; | ||||
| 		this.interval = args.interval; | ||||
| 		this.intervalStop; | ||||
| 	} | ||||
|  | ||||
| 	locationsSet(){ | ||||
| 		this.location.xpSpotAlone = this.bot.findBlockBySign('xpSpotAlone'); | ||||
| 		this.location.xpSpotSecond = this.bot.findBlockBySign('xpSpotSecond'); | ||||
| 		this.location.xp = this.location.xpSpotAlone; | ||||
| 		this.location.attack = this.bot.findBlockBySign('bot attack spot'); | ||||
| 	} | ||||
|  | ||||
| 	async init(){ | ||||
| 		this.onReadyListen = this.bot.on('onReady', async ()=>{ | ||||
| 			await sleep(1000); | ||||
| 			console.log('GoldFarm.init onReady called'); | ||||
| 			try{ | ||||
| 			this.locationsSet(); | ||||
|  | ||||
| 				await this.agroPigs(); | ||||
|  | ||||
| 			}catch(error){ | ||||
| 				console.error('Error in GoldFarm.init:', error); | ||||
| 			} | ||||
|  | ||||
|  | ||||
| 			await this.gotoXP(); | ||||
| 			 | ||||
| 			// let count = 1; | ||||
| 			// this.onPhysicTick = this.bot.on('physicsTick', async () => { | ||||
| 			// 	if(this.bot.bot.pathfinder.isMoving()) return; | ||||
| 			// 	if(count++ === 100){ | ||||
| 			// 		count = 1; | ||||
| 			// 		for(let playerName in this.bot.bot.players){ | ||||
| 			// 			if(this.bot.playerWithinBlock(playerName, this.location.xpSpotAlone, 1.5)){ | ||||
| 			// 				this.location.xp = this.location.xpSpotSecond; | ||||
| 			// 			}else{ | ||||
| 			// 				this.location.xp = this.location.xpSpotAlone; | ||||
| 			// 			} | ||||
| 			// 			await this.gotoXP(); | ||||
| 			// 		} | ||||
|  | ||||
| 			// 	} | ||||
| 			// }); | ||||
| 		}); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	unload(){ | ||||
| 		console.log('GoldFarm.unload'); | ||||
| 		clearInterval(this.intervalStop); | ||||
| 		this.intervalStop = null; | ||||
| 		this.onReadyListen(); | ||||
| 		if(this.onPhysicTick) this.onPhysicTick(); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
|  | ||||
| 	async agroPigs(){ | ||||
| 		await this.bot.goTo({ | ||||
| 			where: this.location.attack, | ||||
| 			range: 2, | ||||
| 		}); | ||||
|  | ||||
| 		await sleep(1000); | ||||
| 		// let entity = this.bot.bot.nearestEntity( | ||||
| 		// 	entity => entity.name.toLowerCase() === 'zombified_piglin' && this.bot.bot.entity.position.distanceTo(entity.position) >= 10 | ||||
| 		// ); | ||||
|  | ||||
| 		let entity = getNearestEntityInDirection(this.bot.bot, 270, 'zombified_piglin'); | ||||
|  | ||||
| 		console.log('entity', entity) | ||||
|  | ||||
| 		this.bot.bot.setControlState('jump', true); | ||||
| 		await sleep(100); | ||||
| 		await throwSnowballAtEntity(this.bot, entity); | ||||
|  | ||||
| 		await sleep(1200); | ||||
| 		this.bot.bot.setControlState('jump', false); | ||||
| 	} | ||||
|  | ||||
| 	async gotoXP(){ | ||||
| 		await this.bot.bot.equip(this.bot.bot.inventory.items().find( | ||||
| 			item => item.name === 'diamond_sword' | ||||
| 		), 'hand'); | ||||
|  | ||||
| 		await this.bot.goTo({ | ||||
| 			where: this.location.xp, | ||||
| 			range: 1, | ||||
| 		}); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| module.exports = GoldFarm; | ||||
| @ -3,18 +3,60 @@ | ||||
| const conf = require('../conf'); | ||||
| const {sleep, nextTick} = require('../utils'); | ||||
|  | ||||
| class GuardianFarm{ | ||||
| 	constructor(args){ | ||||
| 		this.bot = args.bot; | ||||
|  | ||||
| class Plugin{ | ||||
| 	plunginsLoaded = {}; | ||||
|  | ||||
| 	constructor(options){ | ||||
| 		this.bot = options.bot; | ||||
| 	} | ||||
|  | ||||
| 	async load(pluginName, options){ | ||||
| 		if(pluginName in this.plunginsLoaded) throw new Error(`Plugin ${pluginName} already loaded`); | ||||
| 		let plugin = new this.bot.constructor.plungins[pluginName]({...options, bot: this.bot}) | ||||
| 		this.plunginsLoaded[pluginName] = plugin; | ||||
|  | ||||
| 		return await plugin.init(); | ||||
| 	} | ||||
|  | ||||
| 	unload(pluginName){ | ||||
| 		console.log('Plugin.unload', pluginName); | ||||
| 		if(pluginName){ | ||||
| 			try{ | ||||
| 				return this.plunginsLoaded[pluginName].unload(); | ||||
| 				delete this.plunginsLoaded[pluginName];				 | ||||
| 			}catch(error){ | ||||
| 				console.error('Plugin.unload error', pluginName); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		for(pluginName in this.plunginsLoaded){ | ||||
| 			console.log('Plugin.unload load', pluginName) | ||||
| 			try{ | ||||
| 				this.plunginsLoaded[pluginName].unload(); | ||||
| 			}catch(error){ | ||||
| 				console.error(`Plugin.unload ${pluginName} Error`, error); | ||||
| 			} | ||||
| 			delete this.plunginsLoaded[pluginName]; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| class GuardianFarm extends Plugin{ | ||||
| 	constructor(options){ | ||||
| 		super(options); | ||||
| 		this.isDangerous = true; | ||||
| 		this.isAction = true; | ||||
| 		this.onTimeListen; | ||||
| 	} | ||||
|  | ||||
| 	async init(){ | ||||
| 		console.log('GuardianFarm started') | ||||
| 		console.log('GuardianFarm started'); | ||||
| 		this.onReadyListen = this.bot.on('onReady', async ()=>{ | ||||
| 			await sleep(3000); | ||||
| 			let lastTimeListen = this.bot.bot.time.timeOfDay; | ||||
| 			await this.load('Swing'); | ||||
|  | ||||
| 			this.onTimeListen = this.bot.bot.on('time', async ()=>{ | ||||
| 				let isDay = lastTimeListen < this.bot.bot.time.timeOfDay; | ||||
| 				lastTimeListen = this.bot.bot.time.timeOfDay; | ||||
| @ -23,7 +65,6 @@ class GuardianFarm{ | ||||
| 					await this.onNewDay(); | ||||
| 				} | ||||
| 			}); | ||||
| 			await this.bot.pluginLoad('Swing'); | ||||
|  | ||||
| 		}); | ||||
|  | ||||
| @ -31,8 +72,9 @@ class GuardianFarm{ | ||||
| 	} | ||||
|  | ||||
| 	unload(){ | ||||
| 		super.unload(); | ||||
| 		this.onReadyListen(); | ||||
| 		this.onTimeListen(); | ||||
| 		// this.onTimeListen(); | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
| @ -40,10 +82,10 @@ class GuardianFarm{ | ||||
| 	async onNewDay(){ | ||||
| 		try{ | ||||
| 			console.log('GuardianFarm.onNewDay new day!'); | ||||
| 			await this.bot.pluginUnload('Swing'); | ||||
| 			await this.bot.pluginLoad('Craft'); | ||||
| 			await this.bot.pluginUnload('Craft'); | ||||
| 			await this.bot.pluginLoad('Swing'); | ||||
| 			await this.unload('Swing'); | ||||
| 			await this.load('Craft'); | ||||
| 			await this.unload('Craft'); | ||||
| 			await this.load('Swing'); | ||||
| 		}catch(error){ | ||||
| 			console.error('Error in GuardianFarm.onNewDay:', error); | ||||
| 		} | ||||
|  | ||||
| @ -7,16 +7,14 @@ const inventoryViewer = require('mineflayer-web-inventory'); | ||||
|  | ||||
| const commands = require('./commands'); | ||||
| const {onJoin} = require('./player_list'); | ||||
| const {Ai} = require('./ai'); | ||||
| // const plugins = { | ||||
| // 	Swing: require('./swing'), | ||||
| // } | ||||
|  | ||||
| CJbot.pluginAdd(require('./swing')); | ||||
| CJbot.pluginAdd(require('./craft')); | ||||
| CJbot.pluginAdd(require('./tp')); | ||||
| CJbot.pluginAdd(require('./ai')); | ||||
| CJbot.pluginAdd(require('./guardianFarm')); | ||||
| CJbot.pluginAdd(require('./goldFarm')); | ||||
| CJbot.pluginAdd(require('./craft_chests')); | ||||
|  | ||||
| for(let name in conf.mc.bots){ | ||||
| 	if(CJbot.bots[name]) continue; | ||||
| @ -28,12 +26,6 @@ for(let name in conf.mc.bots){ | ||||
| 			bot.addCommand(name, toAdd) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	if(conf.mc.bots[name].plugins){ | ||||
| 		for(let pluginName in conf.mc.bots[name].plugins){ | ||||
| 			bot.pluginLoad(pluginName, conf.mc.bots[name].plugins[pluginName]); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
| (async ()=>{try{ | ||||
|  | ||||
| @ -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); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| @ -16,10 +16,14 @@ class Tp{ | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		await this.bot.goTo({ | ||||
| 			where: this.bot.findBlockBySign('bot TP spot'), | ||||
| 			range: 0, | ||||
| 		}); | ||||
| 		let spot = this.bot.findBlockBySign('bot TP spot'); | ||||
|  | ||||
| 		if(spot){ | ||||
| 			await this.bot.goTo({ | ||||
| 				where: spot, | ||||
| 				range: 1, | ||||
| 			}); | ||||
| 		} | ||||
|  | ||||
| 		this.cleatTimeout = setTimeout(()=>{ | ||||
| 			this.bot.pluginUnload(this.constructor.name) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user